|
14 | 14 | 流程图编辑器,支持独立的流程图编辑器包以及`DrawIO`嵌入通信方案。 |
15 | 15 |
|
16 | 16 | ```bash |
| 17 | +# Install |
17 | 18 | $ npm i embed-drawio |
| 19 | + |
| 20 | +# Development |
| 21 | +$ npm run build:dist |
| 22 | +$ npm run dev |
18 | 23 | ``` |
19 | 24 | ## 独立编辑器 |
20 | | -支持独立的流程图编辑器编辑与展示功能。 |
| 25 | +支持独立的流程图编辑器编辑与渲染。 |
21 | 26 |
|
22 | | -使用方法可参考`example/app.tsx`,由于包体积原因,强烈建议以懒加载方式引入。 |
| 27 | +使用方法可参考`example/index.tsx`,由于包体积原因,强烈建议以懒加载方式引入。 |
23 | 28 |
|
24 | 29 | ```js |
25 | | -import type * as DiagramEditor from "embed-drawio/dist/es/core/editor"; |
26 | | -import type * as DiagramViewer from "embed-drawio/dist/es/core/viewer"; |
| 30 | +import type { DiagramEditor } from "embed-drawio/dist/es/core/editor"; |
| 31 | +import type { DiagramViewer } from "embed-drawio/dist/es/core/viewer"; |
27 | 32 |
|
28 | 33 | let editor: typeof DiagramEditor | null = null; |
29 | | -export const diagramEditorLoader = (): Promise<typeof DiagramEditor> => { |
| 34 | +export const loadEditor = async (): Promise<typeof DiagramEditor> => { |
30 | 35 | if (editor) return Promise.resolve(editor); |
31 | | - return Promise.all([ |
32 | | - import( |
33 | | - /* webpackChunkName: "embed-drawio-editor" */ "embed-drawio/dist/es/core/editor" |
34 | | - ), |
35 | | - // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
36 | | - // @ts-ignore |
| 36 | + const res = await Promise.all([ |
| 37 | + import(/* webpackChunkName: "embed-drawio-editor" */ "embed-drawio/dist/es/core/editor"), |
| 38 | + // @ts-expect-error css declaration |
37 | 39 | import(/* webpackChunkName: "embed-drawio-css" */ "embed-drawio/dist/es/index.css"), |
38 | | - ]).then(res => (editor = res[0])); |
| 40 | + ]); |
| 41 | + editor = res[0].DiagramEditor; |
| 42 | + return editor; |
39 | 43 | }; |
40 | 44 |
|
41 | 45 | let viewer: typeof DiagramViewer | null = null; |
42 | | -export const diagramViewerLoader = (): Promise<typeof DiagramViewer> => { |
| 46 | +export const loadViewer = async (): Promise<typeof DiagramViewer> => { |
43 | 47 | if (viewer) return Promise.resolve(viewer); |
44 | | - return Promise.all([ |
45 | | - import( |
46 | | - /* webpackChunkName: "embed-drawio-viewer" */ "embed-drawio/dist/es/core/viewer" |
47 | | - ), |
48 | | - ]).then(res => (viewer = res[0])); |
| 48 | + const res = await Promise.all([ |
| 49 | + import(/* webpackChunkName: "embed-drawio-viewer" */ "embed-drawio/dist/es/core/viewer"), |
| 50 | + ]); |
| 51 | + viewer = res[0].DiagramViewer; |
| 52 | + return viewer; |
49 | 53 | }; |
50 | 54 | ``` |
51 | 55 |
|
52 | 56 | ## 嵌入DrawIO |
53 | 57 | 支持`DrawIO`的嵌入通信方案。 |
54 | 58 |
|
55 | | -使用方法可参考`example/app.tsx`,由于`sideEffects`原因,强烈建议以路径方式引入。 |
| 59 | +使用方法可参考`example/index.tsx`,由于`sideEffects`原因,强烈建议以路径方式引入。 |
56 | 60 |
|
57 | 61 |
|
58 | 62 | ```js |
|
0 commit comments