开源白板工具(SaaS),一体化白板,包含思维导图、流程图、自由画等。All in one open-source whiteboard tool with mind, flowchart, freehand and etc.
feat: support local storage
pubuzhixing89c0e6526dcd0
diff --git a/apps/web/src/app/app.tsx b/apps/web/src/app/app.tsxindex a80348d..7cd6ccb 100644--- a/apps/web/src/app/app.tsx+++ b/apps/web/src/app/app.tsx@@ -1,8 +1,32 @@-import { mockData } from './mock-data';+import { useState } from 'react';+import { initializeData } from './initialize-data';import { Drawnix } from '@drawnix/core';+import { PlaitElement, PlaitTheme, Viewport } from '@plait/core';++const DRAWNIX_LOCAL_DATA_KEY = 'drawnix-local-data';export function App() {- return <Drawnix value={mockData}></Drawnix>;+ const [value] = useState<{+ children: PlaitElement[];+ viewport?: Viewport;+ theme?: PlaitTheme;+ }>(() => {+ const localData = localStorage.getItem(DRAWNIX_LOCAL_DATA_KEY);+ if (localData) {+ return JSON.parse(localData);+ }+ 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));+ }}+ ></Drawnix>+ );}export default App;diff --git a/apps/web/src/app/initialize-data.ts b/apps/web/src/app/initialize-data.tsnew file mode 100644index 0000000..fd90d36--- /dev/null+++ b/apps/web/src/app/initialize-data.ts@@ -0,0 +1,463 @@+import type { PlaitElement } from '@plait/core';++export const initializeData: PlaitElement[] = [+ {+ id: 'Sfftf',+ type: 'geometry',+ shape: 'terminal',+ angle: 0,+ opacity: 1,+ textHeight: 20,+ text: {+ children: [+ {+ text: '结束',+ },+ ],+ align: 'center',+ },+ points: [+ [-124.8046875, 612.1328125],+ [-4.8046875, 672.1328125],+ ],+ strokeWidth: 2,+ strokeColor: '#333333',+ },+ {+ id: 'aMJWD',+ type: 'geometry',+ shape: 'process',+ angle: 0,+ opacity: 1,+ textHeight: 20,+ text: {+ children: [+ {+ text: '过程',+ },+ ],+ align: 'center',+ },+ points: [+ [80.1953125, 452.1328125],+ [200.1953125, 512.1328125],+ ],+ strokeWidth: 2,+ strokeColor: '#333333',+ },+ {+ id: 'FHSxH',+ type: 'geometry',+ shape: 'decision',+ angle: 0,+ opacity: 1,+ textHeight: 20,+ text: {+ children: [+ {+ text: '判断',+ },+ ],+ align: 'center',+ },+ points: [+ [-134.8046875, 447.1328125],+ [5.1953125, 517.1328125],+ ],+ strokeWidth: 2,+ strokeColor: '#333333',+ },+ {+ id: 'xnnhM',+ type: 'geometry',+ shape: 'process',+ angle: 0,+ opacity: 1,+ textHeight: 20,+ text: {+ children: [+ {+ text: '过程',+ },+ ],+ align: 'center',+ },+ points: [+ [-124.8046875, 332.1328125],+ [-4.8046875, 392.1328125],+ ],+ strokeWidth: 2,+ strokeColor: '#333333',+ },+ {+ id: 'FAkXk',+ type: 'geometry',+ shape: 'terminal',+ angle: 0,+ opacity: 1,+ textHeight: 20,+ text: {+ children: [+ {+ text: '开始',+ },+ ],+ align: 'center',+ },+ points: [+ [-124.8046875, 217.1328125],+ [-4.8046875, 277.1328125],+ ],+ strokeWidth: 2,+ strokeColor: '#333333',+ },+ {+ id: 'mrdfi',+ type: 'line',+ shape: 'elbow',+ source: {+ marker: 'none',+ connection: [0.5, 1],+ boundId: 'aMJWD',+ },+ texts: [],+ target: {+ marker: 'arrow',+ connection: [1, 0.5],+ boundId: 'Sfftf',+ },+ opacity: 1,+ points: [+ [140.1953125, 512.1328125],+ [-4.8046875, 642.1328125],+ ],+ strokeWidth: 2,+ strokeColor: '#333333',+ },+ {+ id: 'bjjcw',+ type: 'line',+ shape: 'elbow',+ source: {+ marker: 'none',+ connection: [1, 0.5],+ boundId: 'FHSxH',+ },+ texts: [+ {+ text: {+ children: [+ {+ text: '否',+ },+ ],+ },+ position: 0.5,+ width: 14,+ height: 20,+ },+ ],+ target: {+ marker: 'arrow',+ connection: [0, 0.5],+ boundId: 'aMJWD',+ },+ opacity: 1,+ points: [+ [5.1953125, 482.1328125],+ [80.1953125, 482.1328125],+ ],+ strokeWidth: 2,+ strokeColor: '#333333',+ },+ {+ id: 'mnzKm',+ type: 'line',+ shape: 'elbow',+ source: {+ marker: 'none',+ connection: [0.5, 1],+ boundId: 'FHSxH',+ },+ texts: [+ {+ text: {+ children: [+ {+ text: '是',+ },+ ],+ },+ position: 0.5,+ width: 14,+ height: 20,+ },+ ],+ target: {+ marker: 'arrow',+ connection: [0.5, 0],+ boundId: 'Sfftf',+ },+ opacity: 1,+ points: [+ [-64.8046875, 517.1328125],+ [-64.8046875, 612.1328125],+ ],+ strokeWidth: 2,+ strokeColor: '#333333',+ },+ {+ id: 'bJmWK',+ type: 'line',+ shape: 'elbow',+ source: {+ marker: 'none',+ connection: [0.5, 1],+ boundId: 'xnnhM',+ },+ texts: [],+ target: {+ marker: 'arrow',+ connection: [0.5, 0],+ boundId: 'FHSxH',+ },+ opacity: 1,+ points: [+ [-64.8046875, 392.1328125],+ [-64.8046875, 447.1328125],+ ],+ strokeWidth: 2,+ strokeColor: '#333333',+ },+ {+ id: 'zZtTs',+ type: 'line',+ shape: 'elbow',+ source: {+ marker: 'none',+ connection: [0.5, 1],+ boundId: 'FAkXk',+ },+ texts: [],+ target: {+ marker: 'arrow',+ connection: [0.5, 0],+ boundId: 'xnnhM',+ },+ opacity: 1,+ points: [+ [-64.8046875, 277.1328125],+ [-64.8046875, 332.1328125],+ ],+ strokeWidth: 2,+ strokeColor: '#333333',+ },+ {+ type: 'mindmap',+ id: 'rzdDJ',+ rightNodeCount: 4,+ data: {+ topic: {+ children: [+ {+ text: '思维导图',+ },+ ],+ },+ },+ children: [+ {+ id: 'WKQyj',+ data: {+ topic: {+ children: [+ {+ text: '观点一',+ },+ ],+ },+ },+ children: [+ {+ id: 'RYSRd',+ data: {+ topic: {+ children: [+ {+ text: '',+ },+ ],+ },+ },+ children: [+ {+ id: 'nDBRj',+ data: {+ topic: {+ children: [+ {+ text: '',+ },+ ],+ },+ },+ children: [],+ width: 14,+ height: 20,+ },+ ],+ width: 14,+ height: 20,+ },+ ],+ width: 42,+ height: 20,+ },+ {+ id: 'PWzAD',+ data: {+ topic: {+ children: [+ {+ text: '观点二',+ },+ ],+ },+ },+ children: [+ {+ id: 'bTRmh',+ data: {+ topic: {+ children: [+ {+ text: '',+ },+ ],+ },+ },+ children: [+ {+ id: 'bnZEJ',+ data: {+ topic: {+ children: [+ {+ text: '',+ },+ ],+ },+ },+ children: [],+ width: 14,+ height: 20,+ },+ ],+ width: 14,+ height: 20,+ },+ ],+ width: 42,+ height: 20,+ },+ {+ id: 'nJTYp',+ data: {+ topic: {+ children: [+ {+ text: '观点三',+ },+ ],+ },+ },+ children: [+ {+ id: 'GtyaH',+ data: {+ topic: {+ children: [+ {+ text: '',+ },+ ],+ },+ },+ children: [+ {+ id: 'JsPEN',+ data: {+ topic: {+ children: [+ {+ text: '',+ },+ ],+ },+ },+ children: [],+ width: 14,+ height: 20,+ },+ ],+ width: 14,+ height: 20,+ },+ ],+ width: 42,+ height: 20,+ },+ {+ id: 'aCpyY',+ data: {+ topic: {+ children: [+ {+ text: '观点四',+ },+ ],+ },+ },+ children: [+ {+ id: 'iHynm',+ data: {+ topic: {+ children: [+ {+ text: '',+ },+ ],+ },+ },+ children: [+ {+ id: 'TiZGR',+ data: {+ topic: {+ children: [+ {+ text: '',+ },+ ],+ },+ },+ children: [],+ width: 14,+ height: 20,+ },+ ],+ width: 14,+ height: 20,+ },+ ],+ width: 42,+ height: 20,+ },+ ],+ width: 72,+ height: 25,+ isRoot: true,+ points: [[403.06494140625, 437.6953125]],+ },+];diff --git a/apps/web/src/app/mock-data.ts b/apps/web/src/app/mock-data.tsdeleted file mode 100644index d8cbabf..0000000--- a/apps/web/src/app/mock-data.ts+++ /dev/null@@ -1,439 +0,0 @@-import type { PlaitElement } from '@plait/core';--export const mockData: PlaitElement[] = [- {- id: 'Sfftf',- type: 'geometry',- shape: 'terminal',- angle: 0,- opacity: 1,- textHeight: 20,- text: {- children: [- {- text: '结束'- }- ],- align: 'center'- },- points: [- [-418, 584],- [-298, 644]- ],- strokeWidth: 2- },- {- id: 'aMJWD',- type: 'geometry',- shape: 'process',- angle: 0,- opacity: 1,- textHeight: 20,- text: {- children: [- {- text: '过程'- }- ],- align: 'center'- },- points: [- [-213, 424],- [-93, 484]- ],- strokeWidth: 2- },- {- id: 'FHSxH',- type: 'geometry',- shape: 'decision',- angle: 0,- opacity: 1,- textHeight: 20,- text: {- children: [- {- text: '判断'- }- ],- align: 'center'- },- points: [- [-428, 419],- [-288, 489]- ],- strokeWidth: 2- },- {- id: 'xnnhM',- type: 'geometry',- shape: 'process',- angle: 0,- opacity: 1,- textHeight: 20,- text: {- children: [- {- text: '过程'- }- ],- align: 'center'- },- points: [- [-418, 304],- [-298, 364]- ],- strokeWidth: 2- },- {- id: 'FAkXk',- type: 'geometry',- shape: 'terminal',- angle: 0,- opacity: 1,- textHeight: 20,- text: {- children: [- {- text: '开始'- }- ],- align: 'center'- },- points: [- [-418, 189],- [-298, 249]- ],- strokeWidth: 2- },- {- id: 'mrdfi',- type: 'line',- shape: 'elbow',- source: {- marker: 'none',- connection: [0.5, 1],- boundId: 'aMJWD'- },- texts: [],- target: {- marker: 'arrow',- connection: [1, 0.5],- boundId: 'Sfftf'- },- opacity: 1,- points: [- [-153, 484],- [-298, 614]- ],- strokeWidth: 2- },- {- id: 'bjjcw',- type: 'line',- shape: 'elbow',- source: {- marker: 'none',- connection: [1, 0.5],- boundId: 'FHSxH'- },- texts: [- {- text: {- children: [- {- text: '否'- }- ]- },- position: 0.5,- width: 14,- height: 20- }- ],- target: {- marker: 'arrow',- connection: [0, 0.5],- boundId: 'aMJWD'- },- opacity: 1,- points: [- [-288, 454],- [-213, 454]- ],- strokeWidth: 2- },- {- id: 'mnzKm',- type: 'line',- shape: 'elbow',- source: {- marker: 'none',- connection: [0.5, 1],- boundId: 'FHSxH'- },- texts: [- {- text: {- children: [- {- text: '是'- }- ]- },- position: 0.5,- width: 14,- height: 20- }- ],- target: {- marker: 'arrow',- connection: [0.5, 0],- boundId: 'Sfftf'- },- opacity: 1,- points: [- [-358, 489],- [-358, 584]- ],- strokeWidth: 2- },- {- id: 'bJmWK',- type: 'line',- shape: 'elbow',- source: {- marker: 'none',- connection: [0.5, 1],- boundId: 'xnnhM'- },- texts: [],- target: {- marker: 'arrow',- connection: [0.5, 0],- boundId: 'FHSxH'- },- opacity: 1,- points: [- [-358, 364],- [-358, 419]- ],- strokeWidth: 2- },- {- id: 'zZtTs',- type: 'line',- shape: 'elbow',- source: {- marker: 'none',- connection: [0.5, 1],- boundId: 'FAkXk'- },- texts: [],- target: {- marker: 'arrow',- connection: [0.5, 0],- boundId: 'xnnhM'- },- opacity: 1,- points: [- [-358, 249],- [-358, 304]- ],- strokeWidth: 2- },- {- type: 'mindmap',- id: 'rzdDJ',- rightNodeCount: 3,- data: {- topic: {- children: [- {- text: '脑图调研'- }- ]- },- emojis: [- {- name: '🏀'- },- {- name: '🌈'- }- ]- },- children: [- {- id: 'WKQyj',- data: {- topic: {- children: [- {- text: '富文本'- }- ]- },- emojis: [- {- name: '🤩'- },- {- name: '🤘'- }- ],- image: {- url: 'https://atlas-rc.pingcode.com/files/public/5ffa68d453ffebf847cf49b9/origin-url',- width: 364,- height: 160- }- },- children: [],- width: 42,- height: 20- },- {- id: 'PWzAD',- data: {- topic: {- children: [- {- text: '知名脑图产品'- }- ]- }- },- children: [- {- id: 'CEWYY',- data: {- topic: {- children: [- {- text: '布局算法'- }- ]- }- },- children: [],- width: 56,- height: 20- },- {- id: 'QGfhQ',- data: {- topic: {- children: [- {- text: 'non-layered-tidy-trees'- }- ]- }- },- children: [- {- id: 'AdXeW',- data: {- topic: {- children: [- {- text: '鱼骨图哦'- }- ]- }- },- children: [],- width: 56,- height: 20- },- {- id: 'bdasn',- data: {- topic: {- children: [- {- text: '缩进布局'- }- ]- }- },- children: [],- width: 56,- height: 20- }- ],- width: 144.8046875,- height: 20- },- {- id: 'SJrGb',- data: {- topic: {- children: [- {- text: '知名脑图产品'- }- ]- }- },- children: [],- width: 84,- height: 20- }- ],- width: 84,- height: 20- },- {- id: 'mGzXi',- data: {- topic: {- children: [- {- text: 'xxxxxxx'- }- ]- }- },- children: [- {- id: 'WFsbH',- data: {- topic: {- children: [- {- text: '鱼骨图哦'- }- ]- }- },- children: [],- width: 56,- height: 20- },- {- id: 'hYPGM',- data: {- topic: {- children: [- {- text: '缩进布局'- }- ]- }- },- children: [],- width: 56,- height: 20- }- ],- width: 48,- height: 20- }- ],- width: 72,- height: 25,- isRoot: true,- points: [[69.43603515625, 383.30859375]]- }-];diff --git a/packages/drawnix/src/drawnix.tsx b/packages/drawnix/src/drawnix.tsxindex 7309199..6ffc609 100644--- a/packages/drawnix/src/drawnix.tsx+++ b/packages/drawnix/src/drawnix.tsx@@ -4,6 +4,7 @@ import {PlaitElement,PlaitPlugin,PlaitPointerType,+ PlaitTheme,Selection,ThemeColorMode,Viewport,@@ -23,7 +24,9 @@ import { PopupToolbar } from './components/popup-toolbar/popup-toolbar';export type DrawnixProps = {value: PlaitElement[];- onChange?: (value: PlaitElement[]) => void;+ viewport?: Viewport;+ theme?: PlaitTheme;+ onChange?: (value: BoardChangeData) => void;onSelectionChange?: (selection: Selection) => void;onValueChange?: (value: PlaitElement[]) => void;onViewportChange?: (value: Viewport) => void;@@ -39,7 +42,12 @@ export type DrawnixState = {pointer: DrawnixPointerType;};-export const Drawnix: React.FC<DrawnixProps> = ({ value, onChange }) => {+export const Drawnix: React.FC<DrawnixProps> = ({+ value,+ viewport,+ theme,+ onChange,+}) => {const plugins: PlaitPlugin[] = [withDraw,withGroup,@@ -48,7 +56,6 @@ export const Drawnix: React.FC<DrawnixProps> = ({ value, onChange }) => {withCommonPlugin,];const options: PlaitBoardOptions = {};-const [appState, setAppState] = useState<DrawnixState>(() => {// TODO: need to consider how to maintenance the pointer state in futurereturn { pointer: PlaitPointerType.hand };@@ -58,10 +65,12 @@ export const Drawnix: React.FC<DrawnixProps> = ({ value, onChange }) => {<div className="drawnix"><Wrappervalue={value}+ viewport={viewport}+ theme={theme}options={options}plugins={plugins}onChange={(data: BoardChangeData) => {- // console.log(JSON.stringify(data));+ onChange && onChange(data);}}><Board></Board>