Skip to content

Commit 0460787

Browse files
committed
feat: lint config & change event
1 parent 5f0e4d7 commit 0460787

5 files changed

Lines changed: 32 additions & 33 deletions

File tree

.eslintrc.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,11 @@ module.exports = {
2727
},
2828
ignorePatterns: ["node_modules", "build", "dist", "coverage", "public"],
2929
rules: {
30-
// 分号
3130
"semi": "error",
32-
// 对象键值引号样式保持一致
3331
"quote-props": ["error", "consistent-as-needed"],
34-
// 箭头函数允许单参数不带括号
3532
"arrow-parens": ["error", "as-needed"],
36-
// no var
3733
"no-var": "error",
38-
// const
3934
"prefer-const": "error",
40-
// 允许console
4135
"no-console": "off",
4236
"@typescript-eslint/consistent-type-imports": "error",
4337
"prefer-template": "error",

.prettierrc.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
module.exports = {
2-
"printWidth": 100, // 指定代码长度,超出换行
3-
"tabWidth": 2, // tab 键的宽度
4-
"useTabs": false, // 不使用tab
5-
"semi": true, // 结尾加上分号
6-
"singleQuote": false, // 使用单引号
7-
"quoteProps": "preserve", // 不要求对象字面量属性是否使用引号包裹
8-
"jsxSingleQuote": false, // jsx 语法中使用单引号
9-
"trailingComma": "es5", // 确保对象的最后一个属性后有逗号
10-
"bracketSpacing": true, // 大括号有空格 { name: 'rose' }
11-
"arrowParens": "avoid", // 箭头函数,单个参数不强制添加括号
12-
"requirePragma": false, // 是否严格按照文件顶部的特殊注释格式化代码
13-
"insertPragma": false, // 是否在格式化的文件顶部插入Pragma标记,以表明该文件被prettier格式化过了
14-
"proseWrap": "preserve", // 按照文件原样折行
15-
"htmlWhitespaceSensitivity": "ignore", // html文件的空格敏感度,控制空格是否影响布局
16-
"endOfLine": "lf" // 结尾是 \n \r \n\r auto
17-
}
2+
"printWidth": 100,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"semi": true,
6+
"singleQuote": false,
7+
"quoteProps": "preserve",
8+
"jsxSingleQuote": false,
9+
"trailingComma": "es5",
10+
"bracketSpacing": true,
11+
"arrowParens": "avoid",
12+
"requirePragma": false,
13+
"insertPragma": false,
14+
"proseWrap": "preserve",
15+
"htmlWhitespaceSensitivity": "ignore",
16+
"endOfLine": "lf",
17+
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"lint:es": "eslint --fix --ext .js,.jsx,.ts,.tsx --ignore-path .gitignore .",
2323
"lint:style": "stylelint \"**/*.{css,scss,sass}\" --fix --ignore-path .gitignore",
2424
"lint": "npm run lint-es && npm run lint-style",
25-
"lint:circular": "madge --circular ./src"
25+
"lint:circular": "madge --extensions js,jsx --circular ./dist"
2626
},
2727
"dependencies": {
2828
"laser-utils": "0.0.5-alpha.10",

src/core/editor.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Editor, EditorUi, Graph } from "../editor";
44
import { mxEvent, mxResources } from "./mxgraph";
55
import type { Language } from "../editor/i18n";
66
import { getLanguage } from "../editor/i18n";
7-
import type { Func } from "laser-utils";
7+
import type { A, O, F } from "laser-utils/dist/es/types";
88

99
const themes: Record<string, Node> = {};
1010
themes[Graph.prototype.defaultThemeName] = (
@@ -26,7 +26,7 @@ export class DiagramEditor {
2626
public start = (
2727
lang: Language,
2828
init?: XMLDocument | null,
29-
onXMLChange?: (xml: Element) => void
29+
onXMLChange?: (xml: Element, changes: A.Any) => void
3030
): void => {
3131
this.container.appendChild(this.diagramContainer);
3232
this.container.style.overflow = "hidden";
@@ -36,8 +36,14 @@ export class DiagramEditor {
3636
if (init) {
3737
this.editorUi.editor.setGraphXml(init.documentElement);
3838
}
39-
this.editor.graph.getModel().addListener(mxEvent.CHANGE, () => {
40-
onXMLChange && onXMLChange(this.editorUi && this.editorUi.editor.getGraphXml());
39+
this.editor.graph.getModel().addListener(mxEvent.CHANGE, (_: O.Any, event: O.Any) => {
40+
if (onXMLChange) {
41+
let changes: A.Any = [];
42+
if (event && event.properties && event.properties.changes) {
43+
changes = event.properties.changes;
44+
}
45+
onXMLChange(this.editorUi && this.editorUi.editor.getGraphXml(), changes);
46+
}
4147
});
4248
};
4349

@@ -54,7 +60,7 @@ export class DiagramEditor {
5460
this.container.removeChild(this.diagramContainer);
5561
};
5662

57-
public static getLang = (lang: Func.Args<typeof getLanguage>["0"]) => {
63+
public static getLang = (lang: F.Args<typeof getLanguage>["0"]) => {
5864
return getLanguage(lang);
5965
};
6066
}

src/core/mxgraph.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ mxCodec.prototype.decode = function (node, into) {
117117
if (node && node.nodeType == mxConstants.NODETYPE_ELEMENT) {
118118
let ctor: unknown = null;
119119
try {
120-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
121-
// @ts-ignore // 因为需要处理的`XML Node`可能不在`Window`上
120+
// @ts-expect-error 需要处理的 XML Node 可能不在 Window 上
122121
ctor = mx[node.nodeName] || window[node.nodeName];
123122
} catch (error) {
124123
console.log(`NODE ${node.nodeName} IS NOT FOUND`, error);
@@ -172,11 +171,11 @@ mxSvgCanvas2D.prototype.createClip = function (x2, y2, w3, h3) {
172171
y2 = Math.round(y2);
173172
w3 = Math.round(w3);
174173
h3 = Math.round(h3);
175-
const id = "mx-clip-" + x2 + "-" + y2 + "-" + w3 + "-" + h3;
174+
const id = `mx-clip-${x2}-${y2}-${w3}-${h3}`;
176175
let counter = 0;
177-
let tmp = id + "-" + counter;
176+
let tmp = `${id}-${counter}`;
178177
while (document.getElementById(tmp) != null) {
179-
tmp = id + "-" + ++counter;
178+
tmp = `${id}-${++counter}`;
180179
}
181180
const clip = this.createElement("clipPath");
182181
clip.setAttribute("id", tmp);

0 commit comments

Comments
 (0)