Skip to content

Commit db7439e

Browse files
Copilottbouffard
andcommitted
Remove initializer.ts and use direct maxGraph imports everywhere
Co-authored-by: tbouffard <27200110+tbouffard@users.noreply.github.com>
1 parent d611961 commit db7439e

24 files changed

+172
-225
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
"utils:test:model": "node ./scripts/utils/dist/utils.mjs test/fixtures/bpmn/simple-start-task-end.bpmn --output model"
105105
},
106106
"dependencies": {
107-
"@maxgraph/core": "0.20.0",
107+
"@maxgraph/core": "^0.20.0",
108108
"es-toolkit": "~1.39.10",
109109
"fast-xml-parser": "5.2.5"
110110
},

src/bpmn-visualization.ts

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
// Use maxGraph types
18-
// The `preserve="true"` directive is required to retain types in the output starting from TypeScript 5.5.
19-
// See https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html#preservetrue for details.
20-
// It is sufficient to add the `preserve` attribute once across all triple-slash directives, as the API Extractor will merge them when generating the final single definition file.
21-
/// <reference types="@maxgraph/core" preserve="true"/>
22-
2317
// Public API
2418
export * from './component/options';
2519
export { BpmnVisualization } from './component/BpmnVisualization';
@@ -33,5 +27,37 @@ export { StyleConfigurator } from './component/mxgraph/config/StyleConfigurator'
3327
export * from './component/mxgraph/style';
3428
export * from './component/mxgraph/shape/render';
3529

36-
// the mxGraph context
37-
export { mxgraph } from './component/mxgraph/initializer';
30+
// the mxGraph context - for backward compatibility
31+
// @deprecated Use direct imports from '@maxgraph/core' instead
32+
import {
33+
CellRenderer,
34+
Client,
35+
constants,
36+
Dictionary,
37+
EdgeStyle,
38+
ImageShape,
39+
InternalEvent,
40+
Perimeter,
41+
Point,
42+
Rectangle,
43+
RectangleShape,
44+
SvgCanvas2D,
45+
styleUtils,
46+
} from '@maxgraph/core';
47+
48+
export const mxgraph = {
49+
CellRenderer: CellRenderer,
50+
mxCellRenderer: CellRenderer,
51+
mxClient: Client,
52+
mxConstants: constants,
53+
mxDictionary: Dictionary,
54+
mxEvent: InternalEvent,
55+
mxPerimeter: Perimeter,
56+
mxPoint: Point,
57+
mxRectangle: Rectangle,
58+
mxRectangleShape: RectangleShape,
59+
mxSvgCanvas2D: SvgCanvas2D,
60+
mxUtils: styleUtils,
61+
ImageShape,
62+
EdgeStyle,
63+
};

src/component/mxgraph/BpmnCellRenderer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ limitations under the License.
1717
import type { IconPainter } from './shape/render';
1818
import type { CellState, ImageShape, Shape } from '@maxgraph/core';
1919

20-
import { mxgraph, Rectangle } from './initializer';
20+
import { CellRenderer, Dictionary, Rectangle } from '@maxgraph/core';
2121
import { CustomCellOverlay } from './overlay/custom-overlay';
2222
import { OverlayBadgeShape } from './overlay/shapes';
2323
import { overrideCreateSvgCanvas } from './shape/utils';
2424

25-
export class BpmnCellRenderer extends mxgraph.CellRenderer {
25+
export class BpmnCellRenderer extends CellRenderer {
2626
constructor(private readonly iconPainter: IconPainter) {
2727
super();
2828
}
@@ -33,7 +33,7 @@ export class BpmnCellRenderer extends mxgraph.CellRenderer {
3333
let dict = null;
3434

3535
if (overlays != null) {
36-
dict = new mxgraph.mxDictionary<Shape>();
36+
dict = new Dictionary<Shape>();
3737

3838
for (const currentOverlay of overlays) {
3939
const shape = state.overlays == null ? null : state.overlays.remove(currentOverlay);
@@ -48,7 +48,7 @@ export class BpmnCellRenderer extends mxgraph.CellRenderer {
4848
if (currentOverlay instanceof CustomCellOverlay) {
4949
overlayShape = new OverlayBadgeShape(currentOverlay.label, new Rectangle(0, 0, 0, 0), currentOverlay.style);
5050
} else {
51-
overlayShape = new mxgraph.ImageShape(new Rectangle(0, 0, 0, 0), currentOverlay.image.src);
51+
overlayShape = new ImageShape(new Rectangle(0, 0, 0, 0), currentOverlay.image.src);
5252
(overlayShape as ImageShape).preserveImageAspect = false;
5353
}
5454
// END bpmn-visualization CUSTOMIZATION

src/component/mxgraph/BpmnRenderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import type { Cell } from '@maxgraph/core';
2626
import { MessageVisibleKind, ShapeUtil } from '../../model/bpmn/internal';
2727
import { MessageFlow } from '../../model/bpmn/internal/edge/flows';
2828

29-
import { Point } from './initializer';
29+
import { Point } from '@maxgraph/core';
3030
import CoordinatesTranslator from './renderer/CoordinatesTranslator';
3131
import StyleComputer from './renderer/StyleComputer';
3232

src/component/mxgraph/config/StyleConfigurator.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import type { BpmnGraph } from '../BpmnGraph';
1818
import type { Stylesheet, CellStateStyle } from '@maxgraph/core';
1919

2020
import { AssociationDirectionKind, FlowKind, SequenceFlowKind, ShapeBpmnElementKind, ShapeUtil } from '../../../model/bpmn/internal';
21-
import { mxConstants, mxPerimeter } from '../initializer';
21+
import { constants, Perimeter } from '@maxgraph/core';
2222
import { BpmnStyleIdentifier, MarkerIdentifier, StyleDefault } from '../style';
2323

2424
const arrowDefaultSize = 12;
@@ -171,7 +171,7 @@ export class StyleConfigurator {
171171
// label style
172172
style.verticalAlign = 'middle';
173173
style.align = 'center';
174-
style[mxConstants.STYLE_SWIMLANE_LINE] = 0; // hide the line between the title region and the content area
174+
style[constants.STYLE_SWIMLANE_LINE] = 0; // hide the line between the title region and the content area
175175
style.startSize = StyleDefault.LANE_LABEL_SIZE;
176176
style.fillColor = StyleDefault.LANE_LABEL_FILL_COLOR;
177177

@@ -182,9 +182,9 @@ export class StyleConfigurator {
182182
for (const kind of ShapeUtil.eventKinds()) {
183183
const style: CellStateStyle = {};
184184
style.shape = kind;
185-
style[mxConstants.STYLE_PERIMETER] = mxPerimeter.EllipsePerimeter;
186-
style[mxConstants.STYLE_STROKEWIDTH] = kind == ShapeBpmnElementKind.EVENT_END ? StyleDefault.STROKE_WIDTH_THICK : StyleDefault.STROKE_WIDTH_THIN;
187-
style[mxConstants.STYLE_VERTICAL_LABEL_POSITION] = mxConstants.ALIGN_BOTTOM;
185+
style[constants.STYLE_PERIMETER] = Perimeter.EllipsePerimeter;
186+
style[constants.STYLE_STROKEWIDTH] = kind == ShapeBpmnElementKind.EVENT_END ? StyleDefault.STROKE_WIDTH_THICK : StyleDefault.STROKE_WIDTH_THIN;
187+
style[constants.STYLE_VERTICAL_LABEL_POSITION] = constants.ALIGN_BOTTOM;
188188
this.putCellStyle(kind, style);
189189
}
190190
}
@@ -193,23 +193,23 @@ export class StyleConfigurator {
193193
const style: CellStateStyle = {};
194194
style.shape = ShapeBpmnElementKind.TEXT_ANNOTATION;
195195
style.verticalAlign = 'middle';
196-
style.align = mxConstants.ALIGN_LEFT;
197-
style[mxConstants.STYLE_SPACING_LEFT] = 5;
196+
style.align = constants.ALIGN_LEFT;
197+
style[constants.STYLE_SPACING_LEFT] = 5;
198198
style.fillColor = StyleDefault.TEXT_ANNOTATION_FILL_COLOR;
199-
style[mxConstants.STYLE_STROKEWIDTH] = StyleDefault.STROKE_WIDTH_THIN;
199+
style[constants.STYLE_STROKEWIDTH] = StyleDefault.STROKE_WIDTH_THIN;
200200
this.putCellStyle(ShapeBpmnElementKind.TEXT_ANNOTATION, style);
201201
}
202202

203203
private configureGroupStyle(): void {
204204
const style: CellStateStyle = {};
205-
style[mxConstants.STYLE_ROUNDED] = true;
205+
style[constants.STYLE_ROUNDED] = true;
206206
style.dashed = true;
207207
style.dashPattern = '7 4 1 4';
208-
style[mxConstants.STYLE_STROKEWIDTH] = StyleDefault.STROKE_WIDTH_THIN;
208+
style[constants.STYLE_STROKEWIDTH] = StyleDefault.STROKE_WIDTH_THIN;
209209
style.fillColor = StyleDefault.GROUP_FILL_COLOR;
210210
// Default label positioning
211211
style.align = 'center';
212-
style.verticalAlign = mxConstants.ALIGN_TOP;
212+
style.verticalAlign = constants.ALIGN_TOP;
213213

214214
this.putCellStyle(ShapeBpmnElementKind.GROUP, style);
215215
}
@@ -218,9 +218,9 @@ export class StyleConfigurator {
218218
for (const kind of ShapeUtil.activityKinds()) {
219219
const style: CellStateStyle = {};
220220
style.shape = kind;
221-
style[mxConstants.STYLE_ROUNDED] = true; // required by the BPMN specification
221+
style[constants.STYLE_ROUNDED] = true; // required by the BPMN specification
222222
style.verticalAlign = 'middle';
223-
style[mxConstants.STYLE_STROKEWIDTH] = kind == ShapeBpmnElementKind.CALL_ACTIVITY ? StyleDefault.STROKE_WIDTH_THICK : StyleDefault.STROKE_WIDTH_THIN;
223+
style[constants.STYLE_STROKEWIDTH] = kind == ShapeBpmnElementKind.CALL_ACTIVITY ? StyleDefault.STROKE_WIDTH_THICK : StyleDefault.STROKE_WIDTH_THIN;
224224
this.putCellStyle(kind, style);
225225
}
226226
}
@@ -229,13 +229,13 @@ export class StyleConfigurator {
229229
for (const kind of ShapeUtil.gatewayKinds()) {
230230
const style: CellStateStyle = {};
231231
style.shape = kind;
232-
style[mxConstants.STYLE_PERIMETER] = mxPerimeter.RhombusPerimeter;
233-
style[mxConstants.STYLE_STROKEWIDTH] = StyleDefault.STROKE_WIDTH_THIN;
234-
style.verticalAlign = mxConstants.ALIGN_TOP;
232+
style[constants.STYLE_PERIMETER] = Perimeter.RhombusPerimeter;
233+
style[constants.STYLE_STROKEWIDTH] = StyleDefault.STROKE_WIDTH_THIN;
234+
style.verticalAlign = constants.ALIGN_TOP;
235235

236236
// Default label positioning
237-
style[mxConstants.STYLE_LABEL_POSITION] = mxConstants.ALIGN_LEFT;
238-
style[mxConstants.STYLE_VERTICAL_LABEL_POSITION] = mxConstants.ALIGN_TOP;
237+
style[constants.STYLE_LABEL_POSITION] = constants.ALIGN_LEFT;
238+
style[constants.STYLE_VERTICAL_LABEL_POSITION] = constants.ALIGN_TOP;
239239

240240
this.putCellStyle(kind, style);
241241
}
@@ -247,10 +247,10 @@ export class StyleConfigurator {
247247

248248
style.shape = BpmnStyleIdentifier.EDGE;
249249
style.endSize = arrowDefaultSize;
250-
style[mxConstants.STYLE_STROKEWIDTH] = 1.5;
251-
style[mxConstants.STYLE_ROUNDED] = true;
250+
style[constants.STYLE_STROKEWIDTH] = 1.5;
251+
style[constants.STYLE_ROUNDED] = true;
252252
style.arcSize = 5;
253-
style.verticalAlign = mxConstants.ALIGN_BOTTOM;
253+
style.verticalAlign = constants.ALIGN_BOTTOM;
254254

255255
// The end arrow must be redefined in specific style
256256
delete style.endArrow;
@@ -272,13 +272,13 @@ export class StyleConfigurator {
272272
}
273273

274274
function configureCommonDefaultStyle(style: CellStateStyle): void {
275-
style[mxConstants.STYLE_FONTFAMILY] = StyleDefault.DEFAULT_FONT_FAMILY;
276-
style[mxConstants.STYLE_FONTSIZE] = StyleDefault.DEFAULT_FONT_SIZE;
277-
style[mxConstants.STYLE_FONTCOLOR] = StyleDefault.DEFAULT_FONT_COLOR;
275+
style[constants.STYLE_FONTFAMILY] = StyleDefault.DEFAULT_FONT_FAMILY;
276+
style[constants.STYLE_FONTSIZE] = StyleDefault.DEFAULT_FONT_SIZE;
277+
style[constants.STYLE_FONTCOLOR] = StyleDefault.DEFAULT_FONT_COLOR;
278278
style.fillColor = StyleDefault.DEFAULT_FILL_COLOR;
279-
style[mxConstants.STYLE_STROKECOLOR] = StyleDefault.DEFAULT_STROKE_COLOR;
280-
style[mxConstants.STYLE_LABEL_BACKGROUNDCOLOR] = mxConstants.NONE;
279+
style[constants.STYLE_STROKECOLOR] = StyleDefault.DEFAULT_STROKE_COLOR;
280+
style[constants.STYLE_LABEL_BACKGROUNDCOLOR] = constants.NONE;
281281

282282
// only works with html labels (enabled by GraphConfigurator)
283-
style[mxConstants.STYLE_WHITE_SPACE] = 'wrap';
283+
style[constants.STYLE_WHITE_SPACE] = 'wrap';
284284
}

src/component/mxgraph/config/register-style-definitions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
import type { AbstractCanvas2D, Cell, Point, Shape } from '@maxgraph/core';
1818

1919
import { ShapeBpmnElementKind } from '../../../model/bpmn/internal';
20-
import { CellRenderer, mxgraph } from '../initializer';
20+
import { CellRenderer, MarkerShape } from '@maxgraph/core';
2121
import {
2222
BusinessRuleTaskShape,
2323
CallActivityShape,
@@ -102,5 +102,5 @@ const dashMarkerFactory = (
102102
};
103103

104104
export const registerEdgeMarkers = (): void => {
105-
mxgraph.mxMarker.addMarker(MarkerIdentifier.ARROW_DASH, dashMarkerFactory);
105+
MarkerShape.addMarker(MarkerIdentifier.ARROW_DASH, dashMarkerFactory);
106106
};

src/component/mxgraph/initializer.ts

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)