I’m trying to build a simple component to allow for code display and syntax highlighting. Its my first time dabbling in modules, so hoping someone can help me with whatever I am obviously missing here… I started off with the Image component in the SDK example, module builds and worked ok until I tried to edit this file.
When building my module I am getting
TypeScript emitted no output for C:\Code\IgnitionModules\perspective-code-viewer\web\packages\client\typescript\components\CodeViewer.tsx.
Here is the tsx
/**
* Example of a component which displays an image, given a URL.
*/
import * as React from 'react';
import {
Component,
ComponentMeta,
ComponentProps,
PComponent,
PropertyTree,
SizeObject
} from '@inductiveautomation/perspective-client';
// The 'key' or 'id' for this component type. Component must be registered with this EXACT key in the Java side as well
// as on the client side. In the client, this is done in the index file where we import and register through the
// ComponentRegistry provided by the perspective-client API.
export const COMPONENT_TYPE = "codeviewer";
// This is the shape of the properties we get from the perspective 'props' property tree.
export interface CodeViewerProps {
code: string; // the code this component should display
codeType: string; // the style class to be applied
}
export class CodeViewer extends Component<ComponentProps<CodeViewerProps>, any> {
render() {
// The props we're interested in.
const { props, emit } = this.props;
// Read the 'code' property provided by the perspective gateway via the component 'props'.
// Note that the topmost piece of dom requires the application of an element reference, events, style and
// className as shown below otherwise the layout won't work, or any events configured will fail. See render
// of MessengerComponent in Messenger.tsx for more details.
return (
<pre {...emit()}>
<code class={props.codeType}>
{props.code}
</code>
</pre>
);
}
}
// This is the actual thing that gets registered with the component registry.
export class CodeViewerMeta implements ComponentMeta {
getComponentType(): string {
return COMPONENT_TYPE;
}
// the class or React Type that this component provides
getViewComponent(): PComponent {
return CodeViewer;
}
getDefaultSize(): SizeObject {
return ({
width: 360,
height: 360
});
}
// Invoked when an update to the PropertyTree has occurred,
// effectively mapping the state of the tree to component props.
getPropsReducer(tree: PropertyTree): CodeViewerProps {
return {
code: tree.readString("code", "")
code_type: tree.readString("codeType", "")
};
}
}