This guide will walk you through the process of creating your own document model library using the Document Model Editor in the Connect app.
-
Access the Document Model Editor in the Connect app using one of the following methods:
- Visit the web deployment at https://document-model-electron.vercel.app/.
- Clone the repository from GitHub and run it locally: https://github.com/powerhouse-inc/document-model-electron.
-
In the Document Model Editor, create a new document model by defining its properties, state schema, initial state, and operations schema.
-
Once you have configured your document model, press the
Save
button in the Sidebar. -
The document model will be exported as a ZIP file with the extension ".phdm.zip."
Use Yarn to create a new document model library project. Replace "PROJECT_NAME"
with your desired project name:
yarn create document-model-lib "PROJECT_NAME"
cd "PROJECT_NAME"
After running the command, you'll have a new project directory created.
git clone https://github.com/powerhouse-inc/document-model-libs.git
cd document-model-libs
yarn install
Generate the document model using the following command, replacing "DOCUMENT_MODEL"
with the the path to the ZIP file saved previously:
yarn generate ./"DOCUMENT_MODEL".phdm.zip
This command will create a directory for the under the /document-models
directory within your project which contains:
- JSON file with the document model specification.
- GraphQL file with the state and operation schemas.
gen
folder with autogenerated code.src
folder with custom code to be completed.
Inside the directory document-models/"DOCUMENT_MODEL"/src/reducers
there will be a file for each module of the document model with the reducer functions to be implemented for each operation.
Write your custom reducer logic to handle the document model operations and state changes as needed for your application.
You can also export custom utility functions on the document-models/"DOCUMENT_MODEL"/src/utils.ts
file.
yarn build
yarn publish
If the Connect App is set up to bundle this library then the newly created document model will be accessible in the UI.
generate
: Updates the generated code according to the JSON spec and GraphQL schema.lint
: Checks for errors with ESLint and TypeScript checking.format
: Formats the code using Prettier.build
: Builds the library project using Vite.storybook
: Starts Storybook in development mode.build-storybook
: Builds Storybook.test
: Runs Jest for testing.