UNPKG

@finos/legend-studio

Version:
289 lines 13 kB
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'; import { BufferIcon, SitemapIcon } from '@finos/legend-art'; import { SchemaSetEditor } from './editor/edit-panel/external-format-editor/SchemaSetElementEditor.js'; import { PackageableElementExplicitReference, SchemaSet, Binding, ModelUnit, ExternalFormatConnection, UrlStream, PURE_GRAMMAR_BINDING_ELEMENT_TYPE_LABEL, PURE_GRAMMAR_EXTERNAL_FORMAT_PARSER_NAME, PURE_GRAMMAR_SCHEMA_SET_ELEMENT_TYPE_LABEL, } from '@finos/legend-graph'; import { ExternalFormatConnectionEditor, ExternalFormatConnectionValueState, NewExternalFormatConnectionDriver, } from './editor/edit-panel/external-format-editor/ExternalFormatConnectionEditor.js'; import { BindingEditor } from './editor/edit-panel/external-format-editor/BindingElementEditor.js'; import { guaranteeNonNullable } from '@finos/legend-shared'; import { LegendStudioApplicationPlugin, } from '../stores/LegendStudioApplicationPlugin.js'; import { SchemaSetEditorState } from '../stores/editor-state/element-editor-state/external-format/SchemaSetEditorState.js'; import { BindingEditorState } from '../stores/editor-state/element-editor-state/external-format/BindingEditorState.js'; import { externalFormat_Binding_setContentType, externalFormat_urlStream_setUrl, } from '../stores/graphModifier/DSLExternalFormat_GraphModifierHelper.js'; import { DSL_EXTERNAL_FORMAT_LEGEND_STUDIO_DOCUMENTATION_KEY } from './DSLExternalFormat_LegendStudioDocumentation.js'; import { BASIC_BINDING_SNIPPET, BASIC_SCHEMASET_SNIPPET, SCHEMASET_WITH_JSON_SCHEMA_SNIPPET, SCHEMASET_WITH_XML_SCHEMA_SNIPPET, SCHEMASET_WITH_FLAT_DATA_SCHEMA_SNIPPET, } from './DSLExternalFormat_CodeSnippets.js'; import { NewSchemaSetDriver, NewSchemaSetDriverEditor, } from './editor/edit-panel/external-format-editor/NewSchemaSetDriver.js'; const SCHEMA_SET_ELEMENT_TYPE = 'SCHEMASET'; const SCHEMA_SET_ELEMENT_PROJECT_EXPLORER_DND_TYPE = 'PROJECT_EXPLORER_SCHEMA_SET'; const BINDING_ELEMENT_TYPE = 'BINDING'; const BINDING_ELEMENT_PROJECT_EXPLORER_DND_TYPE = 'PROJECT_EXPLORER_BINDING'; export class DSLExternalFormat_LegendStudioApplicationPlugin extends LegendStudioApplicationPlugin { constructor() { super(packageJson.extensions.dsl_external_format_studioPlugin, packageJson.version); } getExtraRequiredDocumentationKeys() { return [ DSL_EXTERNAL_FORMAT_LEGEND_STUDIO_DOCUMENTATION_KEY.GRAMMAR_ELEMENT_BINDING, DSL_EXTERNAL_FORMAT_LEGEND_STUDIO_DOCUMENTATION_KEY.GRAMMAR_ELEMENT_SCHEMASET, DSL_EXTERNAL_FORMAT_LEGEND_STUDIO_DOCUMENTATION_KEY.GRAMMAR_PARSER, ]; } getExtraSupportedElementTypes() { return [SCHEMA_SET_ELEMENT_TYPE, BINDING_ELEMENT_TYPE]; } getExtraElementTypeGetters() { return [ (element) => { if (element instanceof SchemaSet) { return SCHEMA_SET_ELEMENT_TYPE; } else if (element instanceof Binding) { return BINDING_ELEMENT_TYPE; } return undefined; }, ]; } getExtraElementIconGetters() { return [ (type) => { if (type === SCHEMA_SET_ELEMENT_TYPE) { return (_jsx("div", { className: "icon icon--schema-set", children: _jsx(SitemapIcon, {}) })); } else if (type === BINDING_ELEMENT_TYPE) { return (_jsx("div", { className: "icon icon--binding", children: _jsx(BufferIcon, {}) })); } return undefined; }, ]; } getExtraElementEditorRenderers() { return [ (elementEditorState) => { if (elementEditorState instanceof SchemaSetEditorState) { return _jsx(SchemaSetEditor, {}, elementEditorState.uuid); } else if (elementEditorState instanceof BindingEditorState) { return _jsx(BindingEditor, {}, elementEditorState.uuid); } return undefined; }, ]; } getExtraNewElementFromStateCreators() { return [ (type, name, state) => { const externalFormatState = state.editorStore.graphState.graphGenerationState.externalFormatState; if (type === SCHEMA_SET_ELEMENT_TYPE) { const schemaSet = state .getNewElementDriver(NewSchemaSetDriver) .createElement(name); return schemaSet; } else if (type === BINDING_ELEMENT_TYPE) { const binding = new Binding(name); externalFormat_Binding_setContentType(binding, guaranteeNonNullable(externalFormatState.formatContentTypes[0])); binding.schemaSet = undefined; const modelUnit = new ModelUnit(); binding.modelUnit = modelUnit; return binding; } return undefined; }, ]; } getExtraElementEditorStateCreators() { return [ (editorStore, element) => { if (element instanceof SchemaSet) { return new SchemaSetEditorState(editorStore, element); } else if (element instanceof Binding) { return new BindingEditorState(editorStore, element); } return undefined; }, ]; } getExtraNewElementDriverCreators() { return [ (editorStore, type) => { if (type === SCHEMA_SET_ELEMENT_TYPE) { return new NewSchemaSetDriver(editorStore); } return undefined; }, ]; } getExtraNewElementDriverEditorRenderers() { return [ (type) => { if (type === SCHEMA_SET_ELEMENT_TYPE) { return _jsx(NewSchemaSetDriverEditor, {}); } return undefined; }, ]; } getExtraElementProjectExplorerDnDTypeGetters() { return [ (element) => { if (element instanceof SchemaSet) { return SCHEMA_SET_ELEMENT_PROJECT_EXPLORER_DND_TYPE; } else if (element instanceof Binding) { return BINDING_ELEMENT_PROJECT_EXPLORER_DND_TYPE; } return undefined; }, ]; } getExtraPureGrammarTextEditorDnDTypes() { return [ SCHEMA_SET_ELEMENT_PROJECT_EXPLORER_DND_TYPE, BINDING_ELEMENT_PROJECT_EXPLORER_DND_TYPE, ]; } getExtraRuntimeConnectionTooltipTextBuilders() { return [ (connection) => { if (connection instanceof ExternalFormatConnection) { return `External format connection \u2022 store ${connection.store.value.path}`; } return undefined; }, ]; } getExtraDefaultConnectionValueBuilders() { return [ (store) => { if (store instanceof Binding) { const externalFormatConnection = new ExternalFormatConnection(PackageableElementExplicitReference.create(store)); const urlStream = new UrlStream(); externalFormat_urlStream_setUrl(urlStream, ''); externalFormatConnection.externalSource = urlStream; return externalFormatConnection; } return undefined; }, ]; } getExtraConnectionValueEditorStateBuilders() { return [ (editorStore, connection) => { if (connection instanceof ExternalFormatConnection) { return new ExternalFormatConnectionValueState(editorStore, connection); } return undefined; }, ]; } getExtraConnectionEditorRenderers() { return [ (connectionValueState, isReadOnly) => { if (connectionValueState instanceof ExternalFormatConnectionValueState) { return (_jsx(ExternalFormatConnectionEditor, { connectionValueState: connectionValueState, isReadOnly: isReadOnly })); } return undefined; }, ]; } getExtraNewConnectionDriverCreators() { return [ (editorStore, store) => { if (store instanceof Binding) { return new NewExternalFormatConnectionDriver(editorStore); } return undefined; }, ]; } getExtraPureGrammarParserElementDocumentationGetters() { return [ (editorStore, parserKeyword, elementKeyword) => { if (parserKeyword === PURE_GRAMMAR_EXTERNAL_FORMAT_PARSER_NAME) { if (elementKeyword === PURE_GRAMMAR_BINDING_ELEMENT_TYPE_LABEL) { return editorStore.applicationStore.documentationService.getDocEntry(DSL_EXTERNAL_FORMAT_LEGEND_STUDIO_DOCUMENTATION_KEY.GRAMMAR_ELEMENT_BINDING); } else if (elementKeyword === PURE_GRAMMAR_SCHEMA_SET_ELEMENT_TYPE_LABEL) { return editorStore.applicationStore.documentationService.getDocEntry(DSL_EXTERNAL_FORMAT_LEGEND_STUDIO_DOCUMENTATION_KEY.GRAMMAR_ELEMENT_SCHEMASET); } } return undefined; }, ]; } getExtraPureGrammarParserDocumentationGetters() { return [ (editorStore, parserKeyword) => { if (parserKeyword === PURE_GRAMMAR_EXTERNAL_FORMAT_PARSER_NAME) { return editorStore.applicationStore.documentationService.getDocEntry(DSL_EXTERNAL_FORMAT_LEGEND_STUDIO_DOCUMENTATION_KEY.GRAMMAR_PARSER); } return undefined; }, ]; } getExtraPureGrammarParserKeywordSuggestionGetters() { return [ (editorStore) => [ { text: PURE_GRAMMAR_EXTERNAL_FORMAT_PARSER_NAME, description: `(dsl)`, documentation: editorStore.applicationStore.documentationService.getDocEntry(DSL_EXTERNAL_FORMAT_LEGEND_STUDIO_DOCUMENTATION_KEY.GRAMMAR_PARSER), insertText: PURE_GRAMMAR_EXTERNAL_FORMAT_PARSER_NAME, }, ], ]; } getExtraPureGrammarParserElementSnippetSuggestionsGetters() { return [ (editorStore, parserKeyword) => parserKeyword === PURE_GRAMMAR_EXTERNAL_FORMAT_PARSER_NAME ? [ // binding { text: PURE_GRAMMAR_BINDING_ELEMENT_TYPE_LABEL, description: '(blank)', insertText: BASIC_BINDING_SNIPPET, }, // schema set { text: PURE_GRAMMAR_SCHEMA_SET_ELEMENT_TYPE_LABEL, description: '(blank)', insertText: BASIC_SCHEMASET_SNIPPET, }, { text: PURE_GRAMMAR_SCHEMA_SET_ELEMENT_TYPE_LABEL, description: 'with flat-data', insertText: SCHEMASET_WITH_FLAT_DATA_SCHEMA_SNIPPET, }, { text: PURE_GRAMMAR_SCHEMA_SET_ELEMENT_TYPE_LABEL, description: 'with JSON shema', insertText: SCHEMASET_WITH_JSON_SCHEMA_SNIPPET, }, { text: PURE_GRAMMAR_SCHEMA_SET_ELEMENT_TYPE_LABEL, description: 'with XML shema', insertText: SCHEMASET_WITH_XML_SCHEMA_SNIPPET, }, ] : undefined, ]; } } //# sourceMappingURL=DSLExternalFormat_LegendStudioApplicationPlugin.js.map