Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SVGMetadata API #239

Merged
merged 6 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/workflow-glsp/src/di.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
SLabel,
SLabelView,
StructureCompartmentView,
svgMetadataModule,
TYPES
} from '@eclipse-glsp/client';
import { bindOrRebind, ContainerConfiguration, DefaultTypes } from '@eclipse-glsp/protocol';
Expand Down Expand Up @@ -89,5 +90,8 @@ export function initializeWorkflowDiagramContainer(
baseDiv: widgetId,
hiddenDiv: widgetId + '_hidden'
});

container.load(svgMetadataModule);
haydar-metin marked this conversation as resolved.
Show resolved Hide resolved

return container;
}
26 changes: 26 additions & 0 deletions packages/client/src/features/svg-metadata/di.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/********************************************************************************
* Copyright (c) 2020-2022 EclipseSource and others.
haydar-metin marked this conversation as resolved.
Show resolved Hide resolved
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { ContainerModule } from 'inversify';
import '../../../css/decoration.css';
haydar-metin marked this conversation as resolved.
Show resolved Hide resolved
import { TYPES } from '../../base/types';
import { MetadataPlacer } from './metadata-placer';

const svgMetadataModule = new ContainerModule((bind, _unbind, isBound) => {
haydar-metin marked this conversation as resolved.
Show resolved Hide resolved
bind(MetadataPlacer).toSelf().inSingletonScope();
bind(TYPES.IVNodePostprocessor).toService(MetadataPlacer);
});

export default svgMetadataModule;
50 changes: 50 additions & 0 deletions packages/client/src/features/svg-metadata/metadata-placer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/********************************************************************************
* Copyright (c) 2020-2022 EclipseSource and others.
haydar-metin marked this conversation as resolved.
Show resolved Hide resolved
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { injectable, inject } from 'inversify';
import { VNode } from 'snabbdom';
import { IVNodePostprocessor, SChildElement, SEdge, setAttr, SModelElement, SModelRoot } from 'sprotty';
import { DOMHelper } from 'sprotty/lib/base/views/dom-helper';
import { TYPES } from '../../base/types';

@injectable()
export class MetadataPlacer implements IVNodePostprocessor {
@inject(TYPES.DOMHelper) protected domHelper: DOMHelper;

decorate(vnode: VNode, element: SModelElement): VNode {
if (element instanceof SModelRoot) {
setAttr(vnode, 'data-svg-metadata-api', true);
}

setAttr(vnode, 'data-svg-metadata-type', element.type);

if (element instanceof SChildElement) {
setAttr(vnode, 'data-svg-metadata-parent-id', this.domHelper.createUniqueDOMElementId(element.parent));
}
if (element instanceof SEdge) {
if (element.source !== undefined) {
setAttr(vnode, 'data-svg-metadata-edge-source-id', this.domHelper.createUniqueDOMElementId(element.source));
}
if (element.target !== undefined) {
setAttr(vnode, 'data-svg-metadata-edge-target-id', this.domHelper.createUniqueDOMElementId(element.target));
}
}
return vnode;
}

postUpdate(): void {
// empty
}
}
5 changes: 4 additions & 1 deletion packages/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import glspCommandPaletteModule from './features/command-palette/di.config';
import glspContextMenuModule from './features/context-menu/di.config';
import { copyPasteContextMenuModule, glspServerCopyPasteModule } from './features/copy-paste/di.config';
import glspDecorationModule from './features/decoration/di.config';
import svgMetadataModule from './features/svg-metadata/di.config';
import glspEditLabelModule from './features/edit-label/di.config';
import modelHintsModule from './features/hints/di.config';
import glspHoverModule from './features/hover/di.config';
Expand Down Expand Up @@ -73,6 +74,7 @@ export * from './features/context-menu/server-context-menu-provider';
export * from './features/copy-paste/copy-paste-context-menu';
export * from './features/copy-paste/copy-paste-handler';
export * from './features/decoration/decoration-placer';
export * from './features/svg-metadata/metadata-placer';
export * from './features/edit-label/edit-label-tool';
export * from './features/edit-label/edit-label-validator';
export * from './features/export/glsp-svg-exporter';
Expand Down Expand Up @@ -151,5 +153,6 @@ export {
glspDecorationModule,
sourceModelWatcherModule,
markerNavigatorContextMenuModule,
glspViewportModule
glspViewportModule,
svgMetadataModule
};