@finos/legend-vscode-extension-dependencies 2.1.15 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. package/lib/bundles/bundle.cjs.js +110 -102
  2. package/lib/bundles/style/bundle.css +1 -1
  3. package/lib/components/Diagram/DiagramEditor.d.ts +9 -0
  4. package/lib/components/Diagram/DiagramEditor.d.ts.map +1 -0
  5. package/lib/components/Diagram/DiagramEditor.js +61 -0
  6. package/lib/components/Diagram/DiagramEditor.js.map +1 -0
  7. package/lib/components/Diagram/DiagramEditorDiagramCanvas.d.ts +5 -0
  8. package/lib/components/Diagram/DiagramEditorDiagramCanvas.d.ts.map +1 -0
  9. package/lib/components/Diagram/DiagramEditorDiagramCanvas.js +92 -0
  10. package/lib/components/Diagram/DiagramEditorDiagramCanvas.js.map +1 -0
  11. package/lib/components/Diagram/DiagramEditorToolPanel.d.ts +7 -0
  12. package/lib/components/Diagram/DiagramEditorToolPanel.d.ts.map +1 -0
  13. package/lib/components/Diagram/DiagramEditorToolPanel.js +37 -0
  14. package/lib/components/Diagram/DiagramEditorToolPanel.js.map +1 -0
  15. package/lib/components/Diagram/DiagramHeader.d.ts +7 -0
  16. package/lib/components/Diagram/DiagramHeader.d.ts.map +1 -0
  17. package/lib/components/Diagram/DiagramHeader.js +39 -0
  18. package/lib/components/Diagram/DiagramHeader.js.map +1 -0
  19. package/lib/index.d.ts +2 -1
  20. package/lib/index.d.ts.map +1 -1
  21. package/lib/index.js +2 -1
  22. package/lib/index.js.map +1 -1
  23. package/lib/stores/DiagramEditorState.d.ts +35 -0
  24. package/lib/stores/DiagramEditorState.d.ts.map +1 -0
  25. package/lib/stores/DiagramEditorState.js +102 -0
  26. package/lib/stores/DiagramEditorState.js.map +1 -0
  27. package/lib/utils/Const.d.ts +2 -0
  28. package/lib/utils/Const.d.ts.map +1 -1
  29. package/lib/utils/Const.js +2 -0
  30. package/lib/utils/Const.js.map +1 -1
  31. package/lib/utils/VsCodeUtils.d.ts +2 -1
  32. package/lib/utils/VsCodeUtils.d.ts.map +1 -1
  33. package/lib/utils/VsCodeUtils.js.map +1 -1
  34. package/package.json +11 -7
  35. package/src/components/Diagram/DiagramEditor.tsx +113 -0
  36. package/src/components/Diagram/DiagramEditorDiagramCanvas.tsx +150 -0
  37. package/src/components/Diagram/DiagramEditorToolPanel.tsx +105 -0
  38. package/src/components/Diagram/DiagramHeader.tsx +230 -0
  39. package/src/index.ts +2 -1
  40. package/src/stores/DiagramEditorState.ts +121 -0
  41. package/src/utils/Const.ts +2 -0
  42. package/src/utils/VsCodeUtils.ts +4 -2
  43. package/tsconfig.json +5 -1
  44. package/lib/components/DiagramRenderer.d.ts +0 -22
  45. package/lib/components/DiagramRenderer.d.ts.map +0 -1
  46. package/lib/components/DiagramRenderer.js +0 -61
  47. package/lib/components/DiagramRenderer.js.map +0 -1
  48. package/src/components/DiagramRenderer.tsx +0 -98
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Copyright (c) 2020-present, Goldman Sachs
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import {
17
+ type Diagram,
18
+ type Point,
19
+ } from '@finos/legend-extension-dsl-diagram/graph';
20
+ import { type PureModel } from '@finos/legend-graph';
21
+ import { type GeneratorFn, guaranteeNonNullable } from '@finos/legend-shared';
22
+ import { action, computed, flow, makeObservable, observable } from 'mobx';
23
+ import {
24
+ DIAGRAM_INTERACTION_MODE,
25
+ type DiagramRenderer,
26
+ } from '@finos/legend-extension-dsl-diagram/application';
27
+
28
+ export class DiagramEditorState {
29
+ _renderer?: DiagramRenderer | undefined;
30
+ diagramId: string;
31
+ diagram?: Diagram;
32
+ graph?: PureModel;
33
+
34
+ constructor(diagramId: string) {
35
+ makeObservable(this, {
36
+ _renderer: observable,
37
+ diagram: observable,
38
+ diagramCursorClass: computed,
39
+ addClassView: flow,
40
+ setRenderer: action,
41
+ });
42
+
43
+ this.diagramId = diagramId;
44
+ }
45
+
46
+ get renderer(): DiagramRenderer {
47
+ return guaranteeNonNullable(
48
+ this._renderer,
49
+ `Diagram renderer must be initialized (this is likely caused by calling this method at the wrong place)`,
50
+ );
51
+ }
52
+
53
+ get isDiagramRendererInitialized(): boolean {
54
+ return Boolean(this._renderer);
55
+ }
56
+
57
+ // NOTE: we have tried to use React to control the cursor and
58
+ // could not overcome the jank/lag problem, so we settle with CSS-based approach
59
+ // See https://css-tricks.com/using-css-cursors/
60
+ // See https://developer.mozilla.org/en-US/docs/Web/CSS/cursor
61
+ get diagramCursorClass(): string {
62
+ if (!this.isDiagramRendererInitialized) {
63
+ return '';
64
+ }
65
+ if (this.renderer.middleClick || this.renderer.rightClick) {
66
+ return 'diagram-editor__cursor--grabbing';
67
+ }
68
+ switch (this.renderer.interactionMode) {
69
+ case DIAGRAM_INTERACTION_MODE.PAN: {
70
+ return this.renderer.leftClick
71
+ ? 'diagram-editor__cursor--grabbing'
72
+ : 'diagram-editor__cursor--grab';
73
+ }
74
+ case DIAGRAM_INTERACTION_MODE.ZOOM_IN: {
75
+ return 'diagram-editor__cursor--zoom-in';
76
+ }
77
+ case DIAGRAM_INTERACTION_MODE.ZOOM_OUT: {
78
+ return 'diagram-editor__cursor--zoom-out';
79
+ }
80
+ case DIAGRAM_INTERACTION_MODE.LAYOUT: {
81
+ if (this.renderer.selectionStart) {
82
+ return 'diagram-editor__cursor--crosshair';
83
+ } else if (
84
+ this.renderer.mouseOverClassCorner ||
85
+ this.renderer.selectedClassCorner
86
+ ) {
87
+ return 'diagram-editor__cursor--resize';
88
+ } else if (this.renderer.mouseOverClassView) {
89
+ return 'diagram-editor__cursor--pointer';
90
+ }
91
+ return '';
92
+ }
93
+ default:
94
+ return '';
95
+ }
96
+ }
97
+
98
+ setupRenderer(): void {
99
+ this.renderer.setIsReadOnly(false);
100
+ }
101
+
102
+ setRenderer(val: DiagramRenderer): void {
103
+ this._renderer = val;
104
+ }
105
+
106
+ setDiagram(val: Diagram): void {
107
+ this.diagram = val;
108
+ }
109
+
110
+ setGraph(val: PureModel): void {
111
+ this.graph = val;
112
+ }
113
+
114
+ *addClassView(path: string, position: Point | undefined): GeneratorFn<void> {
115
+ if (!this.graph || !this.diagram) {
116
+ return;
117
+ }
118
+ const _class = this.graph.getClass(path);
119
+ this.renderer.addClassView(_class, position);
120
+ }
121
+ }
@@ -17,3 +17,5 @@
17
17
  // Event Types
18
18
  export const GET_PROJECT_ENTITIES = 'getProjectEntities';
19
19
  export const GET_PROJECT_ENTITIES_RESPONSE = 'getProjectEntitiesResponse';
20
+ export const DIAGRAM_DROP_CLASS_ERROR = 'diagramDropClassError';
21
+ export const WRITE_ENTITY = 'writeEntity';
@@ -14,12 +14,14 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
+ import type { PlainObject } from '@finos/legend-shared';
18
+
17
19
  interface Vscode {
18
- postMessage(message: unknown): void;
20
+ postMessage(message: PlainObject): void;
19
21
  }
20
22
 
21
23
  declare const vscode: Vscode;
22
24
 
23
- export const postMessage = (message: unknown): void => {
25
+ export const postMessage = (message: PlainObject): void => {
24
26
  vscode.postMessage(message);
25
27
  };
package/tsconfig.json CHANGED
@@ -51,9 +51,13 @@
51
51
  "./src/index.ts",
52
52
  "./src/graph-manager/index.ts",
53
53
  "./src/graph-manager/helpers/VSCODE_Extension_GraphManagerHelper.ts",
54
+ "./src/stores/DiagramEditorState.ts",
54
55
  "./src/utils/Const.ts",
55
56
  "./src/utils/VsCodeUtils.ts",
56
- "./src/components/DiagramRenderer.tsx"
57
+ "./src/components/Diagram/DiagramEditor.tsx",
58
+ "./src/components/Diagram/DiagramEditorDiagramCanvas.tsx",
59
+ "./src/components/Diagram/DiagramEditorToolPanel.tsx",
60
+ "./src/components/Diagram/DiagramHeader.tsx"
57
61
  ],
58
62
  "include": [
59
63
  "src/**/*.ts",
@@ -1,22 +0,0 @@
1
- /**
2
- * Copyright (c) 2020-present, Goldman Sachs
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import '../../style/index.scss';
17
- import type { AbstractPreset } from '@finos/legend-shared';
18
- export declare const DiagramRendererComponent: React.FC<{
19
- diagramId: string;
20
- presets: AbstractPreset[];
21
- }>;
22
- //# sourceMappingURL=DiagramRenderer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DiagramRenderer.d.ts","sourceRoot":"","sources":["../../src/components/DiagramRenderer.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AASH,OAAO,wBAAwB,CAAC;AAOhC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,eAAO,MAAM,wBAAwB,EAAE,KAAK,CAAC,EAAE,CAAC;IAC9C,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,cAAc,EAAE,CAAC;CAC3B,CA8DA,CAAC"}
@@ -1,61 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- /**
3
- * Copyright (c) 2020-present, Goldman Sachs
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- import { getDiagram, DiagramRenderer, } from '@finos/legend-extension-dsl-diagram';
18
- import { createRef, useEffect, useState } from 'react';
19
- import '../../style/index.scss';
20
- import { postMessage } from '../utils/VsCodeUtils.js';
21
- import { GET_PROJECT_ENTITIES, GET_PROJECT_ENTITIES_RESPONSE, } from '../utils/Const.js';
22
- import { getPureGraph } from '../graph-manager/index.js';
23
- export const DiagramRendererComponent = ({ diagramId, presets }) => {
24
- const ref = createRef();
25
- const [diagram, setDiagram] = useState(null);
26
- const [entities, setEntities] = useState([]);
27
- const [error, setError] = useState();
28
- useEffect(() => {
29
- postMessage({
30
- command: GET_PROJECT_ENTITIES,
31
- });
32
- }, [diagramId]);
33
- window.addEventListener('message', (event) => {
34
- const message = event.data;
35
- if (message.command === GET_PROJECT_ENTITIES_RESPONSE) {
36
- const es = message.result;
37
- setEntities(es);
38
- }
39
- });
40
- useEffect(() => {
41
- if (entities.length && diagramId) {
42
- getPureGraph(entities, presets)
43
- .then((pureModel) => {
44
- setDiagram(getDiagram(diagramId, pureModel));
45
- setError(null);
46
- })
47
- .catch((e) => {
48
- setError(e.message);
49
- setDiagram(null);
50
- });
51
- }
52
- }, [entities, diagramId, presets]);
53
- useEffect(() => {
54
- if (diagram) {
55
- const diagramRenderer = new DiagramRenderer(ref.current, diagram);
56
- diagramRenderer.render({ initial: true });
57
- }
58
- }, [ref, diagram]);
59
- return (_jsx("div", { className: "diagram__renderer", ref: ref, children: error ? (_jsxs("div", { className: "diagram__renderer__error", children: [_jsx("span", { children: "Something went wrong. Diagram cannot be created." }), _jsx("span", { className: "diagram__renderer__error__details", title: `${error}`, children: "Error Details." })] })) : null }));
60
- };
61
- //# sourceMappingURL=DiagramRenderer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DiagramRenderer.js","sourceRo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AAE;QACb,IAAI,QAAQ,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;YACjC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC;iBAC5B,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE;gBAClB,UAAU,CAAC,UAAU,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;gBAC7C,QAAQ,CAAC,IAAI,CAAC,CAAC;YACjB,CAAC,CAAC;iBACD,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;gBACX,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;gBACpB,UAAU,CAAC,IAAI,CAAC,CAAC;YACnB,CAAC,CAAC,CAAC;QACP,CAAC;IACH,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;IAEnC,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,eAAe,GAAG,IAAI,eAAe,CACzC,GAAG,CAAC,OAAyB,EAC7B,OAAO,CACR,CAAC;YACF,eAAe,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;IAEnB,OAAO,CACL,cAAK,SAAS,EAAC,mBAAmB,EAAC,GAAG,EAAE,GAAG,YACxC,KAAK,CAAC,CAAC,CAAC,CACP,eAAK,SAAS,EAAC,0BAA0B,aACvC,8EAA6D,EAC7D,eACE,SAAS,EAAC,mCAAmC,EAC7C,KAAK,EAAE,GAAG,KAAK,EAAE,+BAGZ,IACH,CACP,CAAC,CAAC,CAAC,IAAI,GACJ,CACP,CAAC;AACJ,CAAC,CAAC"}
@@ -1,98 +0,0 @@
1
- /**
2
- * Copyright (c) 2020-present, Goldman Sachs
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
- import {
18
- type Diagram,
19
- getDiagram,
20
- DiagramRenderer,
21
- } from '@finos/legend-extension-dsl-diagram';
22
- import type { Entity } from '@finos/legend-storage';
23
- import { createRef, useEffect, useState } from 'react';
24
- import '../../style/index.scss';
25
- import { postMessage } from '../utils/VsCodeUtils.js';
26
- import {
27
- GET_PROJECT_ENTITIES,
28
- GET_PROJECT_ENTITIES_RESPONSE,
29
- } from '../utils/Const.js';
30
- import { getPureGraph } from '../graph-manager/index.js';
31
- import type { AbstractPreset } from '@finos/legend-shared';
32
-
33
- export const DiagramRendererComponent: React.FC<{
34
- diagramId: string;
35
- presets: AbstractPreset[];
36
- }> = ({ diagramId, presets }) => {
37
- const ref = createRef<HTMLDivElement>();
38
- const [diagram, setDiagram] = useState<Diagram | null>(null);
39
- const [entities, setEntities] = useState<Entity[]>([]);
40
- const [error, setError] = useState<string | null>();
41
-
42
- useEffect(() => {
43
- postMessage({
44
- command: GET_PROJECT_ENTITIES,
45
- });
46
- }, [diagramId]);
47
-
48
- window.addEventListener(
49
- 'message',
50
- (event: MessageEvent<{ result: Entity[]; command: string }>) => {
51
- const message = event.data;
52
- if (message.command === GET_PROJECT_ENTITIES_RESPONSE) {
53
- const es: Entity[] = message.result;
54
- setEntities(es);
55
- }
56
- },
57
- );
58
-
59
- useEffect(() => {
60
- if (entities.length && diagramId) {
61
- getPureGraph(entities, presets)
62
- .then((pureModel) => {
63
- setDiagram(getDiagram(diagramId, pureModel));
64
- setError(null);
65
- })
66
- .catch((e) => {
67
- setError(e.message);
68
- setDiagram(null);
69
- });
70
- }
71
- }, [entities, diagramId, presets]);
72
-
73
- useEffect(() => {
74
- if (diagram) {
75
- const diagramRenderer = new DiagramRenderer(
76
- ref.current as HTMLDivElement,
77
- diagram,
78
- );
79
- diagramRenderer.render({ initial: true });
80
- }
81
- }, [ref, diagram]);
82
-
83
- return (
84
- <div className="diagram__renderer" ref={ref}>
85
- {error ? (
86
- <div className="diagram__renderer__error">
87
- <span>Something went wrong. Diagram cannot be created.</span>
88
- <span
89
- className="diagram__renderer__error__details"
90
- title={`${error}`}
91
- >
92
- Error Details.
93
- </span>
94
- </div>
95
- ) : null}
96
- </div>
97
- );
98
- };