Skip to content

Commit 7d5e8db

Browse files
committed
fix: css & static method
1 parent 4d84318 commit 7d5e8db

10 files changed

Lines changed: 246 additions & 193 deletions

File tree

README.md

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,45 +14,49 @@
1414
流程图编辑器,支持独立的流程图编辑器包以及`DrawIO`嵌入通信方案。
1515

1616
```bash
17+
# Install
1718
$ npm i embed-drawio
19+
20+
# Development
21+
$ npm run build:dist
22+
$ npm run dev
1823
```
1924
## 独立编辑器
20-
支持独立的流程图编辑器编辑与展示功能
25+
支持独立的流程图编辑器编辑与渲染
2126

22-
使用方法可参考`example/app.tsx`,由于包体积原因,强烈建议以懒加载方式引入。
27+
使用方法可参考`example/index.tsx`,由于包体积原因,强烈建议以懒加载方式引入。
2328

2429
```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";
2732

2833
let editor: typeof DiagramEditor | null = null;
29-
export const diagramEditorLoader = (): Promise<typeof DiagramEditor> => {
34+
export const loadEditor = async (): Promise<typeof DiagramEditor> => {
3035
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
3739
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;
3943
};
4044

4145
let viewer: typeof DiagramViewer | null = null;
42-
export const diagramViewerLoader = (): Promise<typeof DiagramViewer> => {
46+
export const loadViewer = async (): Promise<typeof DiagramViewer> => {
4347
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;
4953
};
5054
```
5155

5256
## 嵌入DrawIO
5357
支持`DrawIO`的嵌入通信方案。
5458

55-
使用方法可参考`example/app.tsx`,由于`sideEffects`原因,强烈建议以路径方式引入。
59+
使用方法可参考`example/index.tsx`,由于`sideEffects`原因,强烈建议以路径方式引入。
5660

5761

5862
```js

example/index.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import "./index.css";
2+
import "../dist/es/index.css";
23
import ReactDOM from "react-dom";
34
import type { FC } from "react";
45
import { useEffect, useRef, useState } from "react";
56
import { SVG_DATA, XML_DATA } from "./constant";
67
import { clearElement } from "./utils";
78
import { loadEditor, loadViewer } from "./loader";
8-
import { stringToXml, xmlToString } from "../src/utils/xml";
9-
import { base64ToSvgString, stringToSvg } from "../src/utils/svg";
10-
import { getLanguage } from "../src/editor/i18n";
11-
import { EditorBus } from "../src/event";
9+
import { stringToXml, xmlToString } from "../dist/es/utils/xml";
10+
import { base64ToSvgString, stringToSvg } from "../dist/es/utils/svg";
11+
import { getLanguage } from "../dist/es/editor/i18n";
12+
import { EditorBus } from "../dist/es/event";
1213

1314
const DiagramExample: FC = () => {
1415
const [loading, setLoading] = useState(true);

example/loader.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import type { DiagramEditor } from "../src/core/editor";
2-
import type { DiagramViewer } from "../src/core/viewer";
1+
import type { DiagramEditor } from "../dist/es/core/editor";
2+
import type { DiagramViewer } from "../dist/es/core/viewer";
33

44
let editor: typeof DiagramEditor | null = null;
55
let viewer: typeof DiagramViewer | null = null;
66

77
export const loadEditor = (): Promise<typeof DiagramEditor> => {
88
if (editor) return Promise.resolve(editor);
9-
return import("../src/core/editor").then(res => {
9+
return import("../dist/es/core/editor").then(res => {
1010
editor = res.DiagramEditor;
1111
return editor;
1212
});
1313
};
1414

1515
export const loadViewer = (): Promise<typeof DiagramViewer> => {
1616
if (viewer) return Promise.resolve(viewer);
17-
return import("../src/core/viewer").then(res => {
17+
return import("../dist/es/core/viewer").then(res => {
1818
viewer = res.DiagramViewer;
1919
return viewer;
2020
});

example/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { xmlToString } from "../src/utils/xml";
1+
import { xmlToString } from "../dist/es/utils/xml";
22

33
export const clearElement = (element: HTMLElement | null): void => {
44
element && element.childNodes.forEach(node => element.removeChild(node));

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "embed-drawio",
3-
"version": "0.1.0",
3+
"version": "0.1.2",
44
"files": [
55
"dist",
66
"pnpm-lock.yaml"
@@ -14,7 +14,7 @@
1414
},
1515
"scripts": {
1616
"dev": "react-app-rewired start",
17-
"build": "react-app-rewired build",
17+
"build": "npm run build:dist && react-app-rewired build",
1818
"build:es": "tsc -p tsconfig.build.json",
1919
"build:lib": "tsc -p tsconfig.lib.json",
2020
"build:css": "gulp -f gulpfile.js",
@@ -24,7 +24,7 @@
2424
"lint": "npm run lint-es && npm run lint-style"
2525
},
2626
"dependencies": {
27-
"laser-utils": "0.0.2-alpha.13",
27+
"laser-utils": "0.0.5-alpha.10",
2828
"mxgraph": "4.2.2",
2929
"pako": "1.0.6",
3030
"sanitize-html": "2.7.3",
@@ -35,8 +35,8 @@
3535
"@types/node": "12.0.0",
3636
"@types/react": "17.0.2",
3737
"@types/react-dom": "17.0.2",
38-
"@typescript-eslint/eslint-plugin": "5.4.0",
39-
"@typescript-eslint/parser": "5.4.0",
38+
"@typescript-eslint/eslint-plugin": "6.12.0",
39+
"@typescript-eslint/parser": "6.12.0",
4040
"customize-cra": "1.0.0",
4141
"eslint": "7.11.0",
4242
"eslint-config-prettier": "8.3.0",
@@ -53,7 +53,7 @@
5353
"react-dom": "17.0.2",
5454
"stylelint": "14.8.5",
5555
"stylelint-config-standard": "25.0.0",
56-
"typescript": "4.1.2"
56+
"typescript": "5.3.2"
5757
},
5858
"lint-staged": {
5959
"*.{js,ts,jsx,tsx}": [

0 commit comments

Comments
 (0)