Tinacms + Plate
The Plate structure in TinaCMS is a bit overwhelming, given the number of files and folders. This document provides an overview of its organization, highlights key files and functionalities, and notes essential practices to avoid common pitfalls.
Root File Location
The root entry point for the Plate Editor integration can be found at:
/packages/tinacms/src/toolkit/fields/plugins/mdx-field-plugin/plate/index.tsx
Plate Folder Structure
Below is the folder structure of the toolkit Plate integration:
Note
The above folder list is interactable
Key Highlights and Notes
1. Migration from plate-headless to plate-common (As of version 36 of Plate)
Most of the recent updates to Plate reside under components/plate-ui. These include elements and utilities added during the migration process.
info
If adding new features be it a new toolbar button, component, etc - you will more than likely add it to this folder.
2. Rich Text Toolbar Components
-
components/fixed-toolbar-buttons.tsx- This is the primary component for managing the RichText toolbar.
- Key functionality:
- Controls the toolbar buttons.
- Filters overrides, ensuring they are applied correctly.
-
components/floating-toolbar-buttons.tsx- This is very similar to the
fixed-toolbar-buttonscomponent but is used when a word/node is selected. - Key functionality:
- Controls what is shown (Currently only the
TurnIntocomponent)
- Controls what is shown (Currently only the
- This is very similar to the
-
toolbar/toolbar-overrides.tsx- Contains constants and logic used for managing toolbar overrides.
- Important: Overrides must match the
ToolbarOverrideTypefound in the schema-tools package:schema-tools/types/index.ts- This is critical for maintaining feature compatibility. A mismatch can lead to issues. If adding to one, add to the other.
-
toolbar/toolbar-provider.tsx- Facilitates sharing toolbar state across components.
- Use this to add stateful dependencies required in individual
plate-uicomponents.
3. Link URL Handling
The file transforms/is-url.ts is used to override the orginal isUrl logic written by Plate. (this is copied into our project than alternated to allow relative paths).
If we ever need to update this, ensure that we either add back the localUrlMatch or add something equivalent.
const localUrlMatch = string.match(localUrlRE) // Check for local URL match
const match = generalMatch || emailLinkMatch || localUrlMatchThe local regex check that we added to allow relative paths.
createLinkPlugin({
options: {
//? NOTE: This is a custom validation function that allows for relative links i.e. /about
isUrl: (url: string) => isUrl(url),
},
renderAfterEditable: LinkFloatingToolbar,
}),Then to override the default url validation, we invoke our custom isUrl function on the plugin.
This ensures local paths like /about are treated correctly while retaining original isUrl functionality.
Plate + RichText Field
So above we have covered some of the main internal components that make up the rich text editor. But what is actually being passed and used. Well we have a component called MdxFieldPluginExtendible.
This can be found packages/tinacms/src/toolkit/fields/plugins/mdx-field-plugin/index.tsx
This is the rich-text field that is being used by all users and internally.