Getting started
This page explains how to quickly embed the DGM.js editor into the web.
Create React project
First, create a React with TypeScript project. Here, Vite is used.
npm create vite@latest my-project -- --template react-tscd my-projectInstall TailwindCSS
Here, TailwindCSS is used for styling. However, you can use any other styling method you prefer, such as CSS or Styled Components.
npm install -D tailwindcss postcss autoprefixernpx tailwindcss init -pexport default { content: ['./index.html', './src/**/*.{js,ts,jsx,tsx}'], theme: { extend: {}, }, plugins: [],};@tailwind base;@tailwind components;@tailwind utilities;Install packages
To use DGM.js, you need to install two packages as below.
npm i @dgmjs/core @dgmjs/reactInsert Editor component
Before inserting the actual component, first update the index.html. Here, apply simple styles to the area where the editor will be inserted and load the fonts to be used.
<!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8" /> <link rel="preconnect" href="https://fonts.googleapis.com" /> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /> <link href="https://fonts.googleapis.com/css2?family=Gloria+Hallelujah&family=IBM+Plex+Mono:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;1,100;1,200;1,300;1,400;1,500;1,600;1,700&family=Inter:[email protected]&display=swap" rel="stylesheet" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>DGM.js example</title> </head> <body> <div class="text-4xl p-2 text-center"> <a href="https://dgmjs.dev" class="underline" target="_blank">DGM.js</a> example </div> <div id="root" class="absolute top-16 left-8 right-8 h-96"></div> <script type="module" src="/src/main.tsx"></script> </body></html>