-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathinitializer.ts
More file actions
85 lines (75 loc) · 2.66 KB
/
initializer.ts
File metadata and controls
85 lines (75 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
Copyright 2021 Bonitasoft S.A.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import factory, { type mxGraph as mxGraphClass, type mxGraphExportObject } from 'mxgraph';
/**
* The `mxgraph` context that allows access to the mxGraph objects.
*
* **WARNING**: this is for advanced users.
*
* Here are some examples where calling the mxGraph API directly can be useful:
* ```javascript
* // Get the mxGraph version
* const mxGraphVersion = mxgraph.mxClient.VERSION;
* // Call mxUtils in custom BPMN Shapes
* c.setFillColor(mxgraph.mxUtils.getValue(this.style, BpmnStyleIdentifier.EDGE_START_FILL_COLOR, this.stroke));
* ```
*
* @since 0.30.0
*/
export const mxgraph = initialize();
// Destructured exports for convenient access to mxGraph objects.
// mxGraph is exported separately to preserve their constructor types in the api-extractor generated .d.ts (destructuring loses `typeof` during rollup).
export const {
mxCellOverlay,
mxCellRenderer,
mxClient,
mxConnector,
mxConstants,
mxDictionary,
mxEllipse,
mxEvent,
mxGeometry, // at least used in tests
mxGraphView,
mxImageExport,
mxImageShape,
mxMarker,
mxPerimeter,
mxPoint,
mxRectangle,
mxRectangleShape,
mxRhombus,
mxSvgCanvas2D,
mxText,
mxUtils,
} = mxgraph;
export const mxGraph: typeof mxGraphClass = mxgraph.mxGraph;
/** @internal */
declare global {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- Since we are overriding an existing interface in the global scope, it is not possible to convert it to a type.
interface Window {
mxForceIncludes: boolean;
mxLoadResources: boolean;
mxLoadStylesheets: boolean;
mxResourceExtension: string;
}
}
function initialize(): mxGraphExportObject {
// set options globally, as it is not working when passing options to the factory (https://github.com/jgraph/mxgraph/issues/479)
// Required otherwise 'Uncaught ReferenceError: assignment to undeclared variable mx...'
window.mxForceIncludes = false;
window.mxLoadResources = false;
// Required otherwise we got 'Uncaught ReferenceError: assignment to undeclared variable mx...'
window.mxLoadStylesheets = false;
window.mxResourceExtension = '.txt';
return factory({});
}