Template editor for MTRGen as a React component.
- ๐ Table of Contents
- ๐ง About
- ๐ Getting Started
- ๐ Usage
- โ๏ธ Built Using
- โ๏ธ Authors
- ๐ง Dev Soundtrack
React component for editing JSON templates to be used by MTRGen.
You need to have NodeJS installed and use React in your project.
npm install mtrgen-template-editor
pnpm install mtrgen-template-editor
yarn add mtrgen-template-editor
bun add mtrgen-template-editor
// Import the component
import { MTRGenTemplateEditor, Template } from "mtrgen-template-editor";
function App() {
// Create a template object
const [template, setTemplate] = useState<Template>({
name: "Template",
path: "path",
filename: "template",
file: {}
});
return (
<div className="App">
{/* Use it */}
<MTRGenTemplateEditor setTemplate={setTemplate} template={template} onTemplateChange={(temp) => setTemplate(temp) } />
</div>
);
}
interface EditorProps {
template: Template; // The template object
onTemplateChange: (template: Template) => void; // Callback for when the template changes
setTemplate: Dispatch<SetStateAction<Template>>; // React hook for setting the template
}
interface Template {
autoImport?: boolean;
file: File;
filename: string;
name: string;
path: string;
}
interface File {
class?: Class;
interface?: Interface;
namespace?: Namespace;
strict?: boolean;
trait?: Trait;
use?: IndexedString[];
}
interface Class {
comments?: IndexedString[];
constants?: Constant[];
extends?: string;
implements?: IndexedString[];
methods?: Method[];
modifier?: Modifier;
name: string;
props?: Prop[];
traits?: IndexedString[];
}
interface Constant {
id: number|string;
comments?: IndexedString[];
name: string;
value: Value;
visibility?: Visibility;
}
type Value = any[] | boolean | number | number | { [key: string]: any } | null | string;
interface Method {
id: number|string;
body?: IndexedString[];
comments?: IndexedString[];
modifier?: Modifier;
name: string;
nullable?: boolean;
params?: Param[];
ref?: boolean;
return?: string;
static?: boolean;
visibility?: Visibility;
}
enum Modifier {
Abstract = "abstract",
Final = "final",
}
interface Param {
id: number|string;
name: string;
nullable?: boolean;
promoted?: boolean;
ref?: boolean;
type?: string;
value?: Value;
}
enum Visibility {
Private = "private",
Protected = "protected",
Public = "public",
}
interface Prop {
id: number|string;
comments?: IndexedString[];
getter?: boolean;
init?: boolean;
name: string;
nullable?: boolean;
setter?: boolean;
static?: boolean;
type?: string;
value?: Value;
visibility?: Visibility;
}
interface Interface {
comments?: IndexedString[];
constants?: Constant[];
extends?: string;
methods?: Method[];
name: string;
}
interface Namespace {
class?: Class;
interface?: Interface;
name: string;
trait?: Trait;
use?: IndexedString[];
}
interface Trait {
comments?: IndexedString[];
methods?: Method[];
name: string;
props?: Prop[];
}
interface IndexedString {
id: number|string;
value: string;
}
- pnpm - pnpm
- TypeScript - TypeScript
- React - React
- Bootstrap - Bootstrap
- React Bootstrap - React Bootstrap
- @matronator - Everything
Package was built while listening to: