Skip to content

Commit 0a85dea

Browse files
committed
fix: sidebar circular dependency
1 parent 7d5e8db commit 0a85dea

9 files changed

Lines changed: 92 additions & 32 deletions

File tree

.eslintrc.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ module.exports = {
3939
"prefer-const": "error",
4040
// 允许console
4141
"no-console": "off",
42-
// 关闭每个函数都要显式声明返回值
43-
// "@typescript-eslint/explicit-module-boundary-types": "off",
4442
"@typescript-eslint/consistent-type-imports": "error",
43+
"prefer-template": "error",
4544
},
4645
};

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "embed-drawio",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"files": [
55
"dist",
66
"pnpm-lock.yaml"
@@ -21,14 +21,14 @@
2121
"build:dist": "rm -rf ./dist && npm run build:es && npm run build:lib && npm run build:css",
2222
"lint:es": "eslint --fix --ext .js,.jsx,.ts,.tsx --ignore-path .gitignore .",
2323
"lint:style": "stylelint \"**/*.{css,scss,sass}\" --fix --ignore-path .gitignore",
24-
"lint": "npm run lint-es && npm run lint-style"
24+
"lint": "npm run lint-es && npm run lint-style",
25+
"lint:circular": "madge --circular ./src"
2526
},
2627
"dependencies": {
2728
"laser-utils": "0.0.5-alpha.10",
2829
"mxgraph": "4.2.2",
2930
"pako": "1.0.6",
30-
"sanitize-html": "2.7.3",
31-
"sanitizer": "0.1.3"
31+
"sanitize-html": "2.7.3"
3232
},
3333
"devDependencies": {
3434
"@typed-mxgraph/typed-mxgraph": "1.0.7",
@@ -44,9 +44,9 @@
4444
"eslint-plugin-prettier": "3.3.1",
4545
"eslint-plugin-react": "7.27.0",
4646
"eslint-plugin-react-hooks": "4.3.0",
47-
"gulp": "^5.0.0",
48-
"gulp-clean-css": "^4.3.0",
49-
"gulp-concat": "^2.6.1",
47+
"gulp": "5.0.0",
48+
"gulp-clean-css": "4.3.0",
49+
"gulp-concat": "2.6.1",
5050
"prettier": "2.4.1",
5151
"react": "17.0.2",
5252
"react-app-rewired": "2.1.8",

pnpm-lock.yaml

Lines changed: 3 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/editor/js/Dialogs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
import { Editor, Dialog, FilenameDialog } from "./Editor";
1818
import { mxJSColor, mxColor } from "../jscolor/jscolor";
1919
import { EditorUi } from "./EditorUi";
20-
import { PRESENT_COLORS, DEFAULT_COLORS } from "../constant";
20+
import { PRESENT_COLORS, DEFAULT_COLORS } from "../utils/constant";
2121

2222
export { ColorDialog, OutlineWindow, LayersWindow };
2323

src/editor/js/Graph.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ import {
6161
mxGeometry,
6262
} from "../../core/mxgraph";
6363
import { Editor } from "./Editor";
64-
import { Sidebar } from "./Sidebar";
6564
import { getStencil } from "../stencils";
6665

6766
import pako from "pako";
@@ -9723,13 +9722,6 @@ if (typeof mxVertexHandler != "undefined") {
97239722
mxEdgeHandler.prototype.labelHandleImage = HoverIcons.prototype.secondaryHandle;
97249723
mxOutline.prototype.sizerImage = HoverIcons.prototype.mainHandle;
97259724

9726-
Sidebar.prototype.triangleUp = HoverIcons.prototype.triangleUp;
9727-
Sidebar.prototype.triangleRight = HoverIcons.prototype.triangleRight;
9728-
Sidebar.prototype.triangleDown = HoverIcons.prototype.triangleDown;
9729-
Sidebar.prototype.triangleLeft = HoverIcons.prototype.triangleLeft;
9730-
Sidebar.prototype.refreshTarget = HoverIcons.prototype.refreshTarget;
9731-
Sidebar.prototype.roundDrop = HoverIcons.prototype.roundDrop;
9732-
97339725
// Pre-fetches images (only needed for non data-uris)
97349726
new Image().src = HoverIcons.prototype.mainHandle.src;
97359727
new Image().src = HoverIcons.prototype.fixedHandle.src;

src/editor/js/Sidebar.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,20 @@ import {
2020
mxCodec,
2121
mxGraphModel,
2222
} from "../../core/mxgraph";
23-
import { Graph, HoverIcons } from "./Graph";
23+
import { Graph } from "./Graph";
2424
import { Editor, Dialog } from "./Editor";
2525
import { getStencil } from "../stencils";
2626
import Gear_128x128 from "../stencils/clipart/Gear_128x128";
2727
import { collapsedImage, expandedImage, searchImage } from "../images/base64";
28+
import {
29+
REFRESH_TARGET_IMAGE,
30+
ROUND_DROP_IMAGE,
31+
TRIANGLE_DOWN_IMAGE,
32+
TRIANGLE_LEFT_IMAGE,
33+
TRIANGLE_RIGHT_IMAGE,
34+
TRIANGLE_UP_IMAGE,
35+
} from "../utils/graph";
36+
import { GRAPH } from "../utils/constant";
2837

2938
export { Sidebar };
3039

@@ -115,6 +124,13 @@ function Sidebar(editorUi, container) {
115124
this.init();
116125
}
117126

127+
Sidebar.prototype.triangleUp = TRIANGLE_UP_IMAGE;
128+
Sidebar.prototype.triangleRight = TRIANGLE_RIGHT_IMAGE;
129+
Sidebar.prototype.triangleDown = TRIANGLE_DOWN_IMAGE;
130+
Sidebar.prototype.triangleLeft = TRIANGLE_LEFT_IMAGE;
131+
Sidebar.prototype.refreshTarget = REFRESH_TARGET_IMAGE;
132+
Sidebar.prototype.roundDrop = ROUND_DROP_IMAGE;
133+
118134
/**
119135
* Adds all palettes to the sidebar.
120136
*/
@@ -4386,7 +4402,7 @@ Sidebar.prototype.createDragSource = function (elt, dropHandler, preview, cells,
43864402
arrow.setAttribute("title", tooltip);
43874403
}
43884404

4389-
mxUtils.setOpacity(arrow, img == HoverIcons.prototype.refreshTarget ? 30 : 20);
4405+
mxUtils.setOpacity(arrow, img == REFRESH_TARGET_IMAGE ? 30 : 20);
43904406
arrow.style.position = "absolute";
43914407
arrow.style.cursor = "crosshair";
43924408

@@ -4724,7 +4740,7 @@ Sidebar.prototype.createDragSource = function (elt, dropHandler, preview, cells,
47244740
}
47254741

47264742
bds.grow(this.graph.tolerance);
4727-
bds.grow(HoverIcons.prototype.arrowSpacing);
4743+
bds.grow(GRAPH.ARROW_SPACING);
47284744

47294745
var handler = this.graph.selectionCellsHandler.getHandler(currentTargetState.cell);
47304746

@@ -4878,7 +4894,7 @@ Sidebar.prototype.createDragSource = function (elt, dropHandler, preview, cells,
48784894
}
48794895

48804896
bds.grow(this.graph.tolerance);
4881-
bds.grow(HoverIcons.prototype.arrowSpacing);
4897+
bds.grow(GRAPH.ARROW_SPACING);
48824898

48834899
var handler = this.graph.selectionCellsHandler.getHandler(state.cell);
48844900

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
export const GRAPH = {
2+
ARROW_FILL: "#29b6f2",
3+
ARROW_SPACING: 2,
4+
};
5+
16
export const PRESENT_COLORS = [
27
"E6D0DE",
38
"CDA2BE",

src/editor/utils/graph.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { mxImage } from "../../core/mxgraph";
2+
import { refreshTarget } from "../images/base64";
3+
import { GRAPH } from "./constant";
4+
5+
export const createSvgImage = (
6+
w: number,
7+
h: number,
8+
data: string,
9+
coordWidth?: string,
10+
coordHeight?: string
11+
) => {
12+
const viewBox = coordWidth && coordHeight ? `viewBox="0 0 ${coordWidth} ${coordHeight}"` : "";
13+
const tmp = unescape(
14+
encodeURIComponent(
15+
`${
16+
'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">' +
17+
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="'
18+
}${w}px" height="${h}px" ${viewBox} version="1.1">${data}</svg>`
19+
)
20+
);
21+
return new mxImage(`data:image/svg+xml;base64,${btoa(tmp)}`, w, h);
22+
};
23+
24+
export const TRIANGLE_UP_IMAGE = createSvgImage(
25+
18,
26+
28,
27+
`<path d="m 6 26 L 12 26 L 12 12 L 18 12 L 9 1 L 1 12 L 6 12 z" stroke="#fff" fill="${GRAPH.ARROW_FILL}"/>`
28+
);
29+
30+
export const TRIANGLE_RIGHT_IMAGE = createSvgImage(
31+
26,
32+
18,
33+
`<path d="m 1 6 L 14 6 L 14 1 L 26 9 L 14 18 L 14 12 L 1 12 z" stroke="#fff" fill="${GRAPH.ARROW_FILL}"/>`
34+
);
35+
36+
export const TRIANGLE_DOWN_IMAGE = createSvgImage(
37+
18,
38+
26,
39+
`<path d="m 6 1 L 6 14 L 1 14 L 9 26 L 18 14 L 12 14 L 12 1 z" stroke="#fff" fill="${GRAPH.ARROW_FILL}"/>`
40+
);
41+
42+
export const TRIANGLE_LEFT_IMAGE = createSvgImage(
43+
28,
44+
18,
45+
`<path d="m 1 9 L 12 1 L 12 6 L 26 6 L 26 12 L 12 12 L 12 18 z" stroke="#fff" fill="${GRAPH.ARROW_FILL}"/>`
46+
);
47+
48+
export const REFRESH_TARGET_IMAGE = new mxImage(refreshTarget, 38, 38);
49+
50+
export const ROUND_DROP_IMAGE = createSvgImage(
51+
26,
52+
26,
53+
`<circle cx="13" cy="13" r="12" stroke="#fff" fill="${GRAPH.ARROW_FILL}"/>`
54+
);

tsconfig.lib.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
4+
"module": "commonjs",
45
"outDir": "dist/lib",
56
"declarationDir": "dist/lib"
67
},

0 commit comments

Comments
 (0)