@finos/legend-extension-dsl-diagram
Version:
Legend extension for Diagram DSL
216 lines • 9.06 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
/**
* Copyright (c) 2020-present, Goldman Sachs
*
* 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 packageJson from '../../../package.json' with { type: 'json' };
import { LegendStudioApplicationPlugin, PACKAGEABLE_ELEMENT_GROUP_BY_CATEGORY, } from '@finos/legend-application-studio';
import { ShapesIcon } from '@finos/legend-art';
import { Diagram } from '../../graph/metamodel/pure/packageableElements/diagram/DSL_Diagram_Diagram.js';
import { DiagramEditorState } from '../../stores/studio/DiagramEditorState.js';
import { DiagramEditor } from './DiagramEditor.js';
import { ClassDiagramPreview } from './ClassDiagramPreview.js';
import { DSL_DIAGRAM_LEGEND_STUDIO_DOCUMENTATION_KEY } from '../../__lib__/studio/DSL_Diagram_LegendStudioDocumentation.js';
import { EMPTY_DIAGRAM_SNIPPET, getDiagramSnippetWithGeneralizationView, getDiagramSnippetWithOneClassView, getDiagramSnippetWithPropertyView, } from '../../__lib__/studio/DSL_Diagram_LegendStudioCodeSnippet.js';
import { collectKeyedCommandConfigEntriesFromConfig, } from '@finos/legend-application';
import { DSL_DIAGRAM_LEGEND_STUDIO_APPLICATION_NAVIGATION_CONTEXT_KEY } from '../../__lib__/studio/DSL_Diagram_LegendStudioApplicationNavigationContext.js';
import { DSL_DIAGRAM_LEGEND_STUDIO_COMMAND_CONFIG } from '../../__lib__/studio/DSL_Diagram_LegendStudioCommand.js';
const DIAGRAM_ELEMENT_TYPE = 'DIAGRAM';
const DIAGRAM_ELEMENT_PROJECT_EXPLORER_DND_TYPE = 'PROJECT_EXPLORER_DIAGRAM';
const PURE_GRAMMAR_DIAGRAM_PARSER_NAME = 'Diagram';
const PURE_GRAMMAR_DIAGRAM_ELEMENT_TYPE_LABEL = 'Diagram';
export class DSL_Diagram_LegendStudioApplicationPlugin extends LegendStudioApplicationPlugin {
constructor() {
super(packageJson.extensions.applicationStudioPlugin, packageJson.version);
}
getExtraKeyedCommandConfigEntries() {
return collectKeyedCommandConfigEntriesFromConfig(DSL_DIAGRAM_LEGEND_STUDIO_COMMAND_CONFIG);
}
getExtraRequiredDocumentationKeys() {
return [
DSL_DIAGRAM_LEGEND_STUDIO_DOCUMENTATION_KEY.CONCEPT_ELEMENT_DIAGRAM,
DSL_DIAGRAM_LEGEND_STUDIO_DOCUMENTATION_KEY.GRAMMAR_PARSER,
];
}
getExtraClassPreviewRenderers() {
return [
(_class) => (_jsx(ClassDiagramPreview, { _class: _class })),
];
}
getExtraAccessEventLoggingApplicationContextKeys() {
return [
DSL_DIAGRAM_LEGEND_STUDIO_APPLICATION_NAVIGATION_CONTEXT_KEY.DIAGRAM_EDITOR,
];
}
getExtraPureGrammarKeywords() {
return [PURE_GRAMMAR_DIAGRAM_ELEMENT_TYPE_LABEL];
}
getExtraSupportedElementTypes() {
return [DIAGRAM_ELEMENT_TYPE];
}
getExtraSupportedElementTypesWithCategory() {
const elementTypesWithCategoryMap = new Map();
elementTypesWithCategoryMap.set(PACKAGEABLE_ELEMENT_GROUP_BY_CATEGORY.MODEL, [DIAGRAM_ELEMENT_TYPE]);
return elementTypesWithCategoryMap;
}
getExtraElementClassifiers() {
return [
(element) => {
if (element instanceof Diagram) {
return DIAGRAM_ELEMENT_TYPE;
}
return undefined;
},
];
}
getExtraElementIconGetters() {
return [
(type) => {
if (type === DIAGRAM_ELEMENT_TYPE) {
return (_jsx("div", { className: "icon color--diagram", children: _jsx(ShapesIcon, {}) }));
}
return undefined;
},
];
}
getExtraElementEditorRenderers() {
return [
(elementEditorState) => {
if (elementEditorState instanceof DiagramEditorState) {
return _jsx(DiagramEditor, {}, elementEditorState.uuid);
}
return undefined;
},
];
}
getExtraNewElementFromStateCreators() {
return [
(type, name, state) => {
if (type === DIAGRAM_ELEMENT_TYPE) {
return new Diagram(name);
}
return undefined;
},
];
}
getExtraElementEditorStateCreators() {
return [
(editorStore, element) => {
if (element instanceof Diagram) {
return new DiagramEditorState(editorStore, element);
}
return undefined;
},
];
}
getExtraDragElementClassifiers() {
return [
(element) => {
if (element instanceof Diagram) {
return DIAGRAM_ELEMENT_PROJECT_EXPLORER_DND_TYPE;
}
return undefined;
},
];
}
getExtraPureGrammarTextEditorDragElementTypes() {
return [DIAGRAM_ELEMENT_PROJECT_EXPLORER_DND_TYPE];
}
getExtraElementEditorPostRenameActions() {
return [
(editorStore, element) => {
// rerender currently opened diagram
if (editorStore.tabManagerState.currentTab instanceof DiagramEditorState) {
editorStore.tabManagerState.currentTab.renderer.render();
}
},
];
}
getExtraElementEditorPostDeleteActions() {
return [
(editorStore, element) => {
// rerender currently opened diagram
if (editorStore.tabManagerState.currentTab instanceof DiagramEditorState) {
editorStore.tabManagerState.currentTab.renderer.render();
}
},
];
}
getExtraPureGrammarParserElementDocumentationGetters() {
return [
(editorStore, parserKeyword, elementKeyword) => {
if (parserKeyword === PURE_GRAMMAR_DIAGRAM_PARSER_NAME) {
if (elementKeyword === PURE_GRAMMAR_DIAGRAM_ELEMENT_TYPE_LABEL) {
return editorStore.applicationStore.documentationService.getDocEntry(DSL_DIAGRAM_LEGEND_STUDIO_DOCUMENTATION_KEY.CONCEPT_ELEMENT_DIAGRAM);
}
}
return undefined;
},
];
}
getExtraPureGrammarParserDocumentationGetters() {
return [
(editorStore, parserKeyword) => {
if (parserKeyword === PURE_GRAMMAR_DIAGRAM_PARSER_NAME) {
return editorStore.applicationStore.documentationService.getDocEntry(DSL_DIAGRAM_LEGEND_STUDIO_DOCUMENTATION_KEY.GRAMMAR_PARSER);
}
return undefined;
},
];
}
getExtraPureGrammarParserKeywordSuggestionGetters() {
return [
(editorStore) => [
{
text: PURE_GRAMMAR_DIAGRAM_PARSER_NAME,
description: `(dsl)`,
documentation: editorStore.applicationStore.documentationService.getDocEntry(DSL_DIAGRAM_LEGEND_STUDIO_DOCUMENTATION_KEY.GRAMMAR_PARSER),
insertText: PURE_GRAMMAR_DIAGRAM_PARSER_NAME,
},
],
];
}
getExtraPureGrammarParserElementSnippetSuggestionsGetters() {
return [
(editorStore, parserKeyword) => parserKeyword === PURE_GRAMMAR_DIAGRAM_PARSER_NAME
? [
{
text: PURE_GRAMMAR_DIAGRAM_ELEMENT_TYPE_LABEL,
description: '(blank)',
insertText: EMPTY_DIAGRAM_SNIPPET,
},
{
text: PURE_GRAMMAR_DIAGRAM_ELEMENT_TYPE_LABEL,
description: 'with class',
insertText: getDiagramSnippetWithOneClassView(),
},
{
text: PURE_GRAMMAR_DIAGRAM_ELEMENT_TYPE_LABEL,
description: 'with inheritance',
insertText: getDiagramSnippetWithGeneralizationView(),
},
{
text: PURE_GRAMMAR_DIAGRAM_ELEMENT_TYPE_LABEL,
description: 'with composition',
insertText: getDiagramSnippetWithPropertyView(),
},
]
: undefined,
];
}
getExtraGrammarTextEditorAutoFoldingElementCreatorKeywords() {
return [PURE_GRAMMAR_DIAGRAM_PARSER_NAME];
}
}
//# sourceMappingURL=DSL_Diagram_LegendStudioApplicationPlugin.js.map