Clientor is a versatile React package that provides a robust text editor component. It supports both MDX and Rich Text editing styles, making it ideal for developers who need a flexible and powerful text input solution. Key features include local and remote image insertion with validation, link management, formatting tools, and customizable content length constraints.
To get started with development on Clientor, follow these steps:
- Node.js (v18 or higher recommended)
- npm or yarn
- Clone the repository:
git clone <repository-url> cd clientor
- Install dependencies:
npm install
Start the Vite development server to see the project in action:
npm run devTo create a production-ready build:
npm run buildTo check the code for linting errors:
npm run lintTo integrate Clientor into your React application, follow these steps:
Clientor requires two main providers to function correctly: ClientorUserProvider (for user-specific configurations and handlers) and ClientorContextProvider (for internal editor state).
import { ClientorContextProvider } from "./lib/contexts/clientorContext";
import ClientorUserProvider from "./lib/contexts/clientorUserContext";
import ClientorBox from "./ui/ClientorBox";
function App() {
return (
<ClientorUserProvider
handleSubmit={(data) => {
console.log("Submitted data:", data);
return data.raw !== "";
}}
// Optional: Add other configurations like min/max content length, sounds, etc.
>
<ClientorContextProvider>
<ClientorBox />
</ClientorContextProvider>
</ClientorUserProvider>
);
}The ClientorUserProvider accepts several props to customize the editor's behavior:
handleSubmit: A function called when the user submits the content.maxContentLength: Define a maximum character limit and a handler for when it's exceeded.minContentLength: Define a minimum character limit and a handler.playSounds: Enable/disable sounds for sending or errors.imagesValidate: Configure validation rules for local and remote images (origins, sizes, etc.).
The project is organized into several key directories within src/:
-
Contains all stylesheets.
clientor.cssis the core component styling, whileapp.cssis for the development environment. -
The "factory" of the project. Contains non-JSX logic:
contexts/: React contexts for state management.storage/: Helpers for IndexedDB (idb.ts) and Session Storage (ss.ts).hooks.ts&useFunctionalities.ts: Custom hooks for editor logic.helpers.ts,utils.ts,types.ts: Utility functions and type definitions.
-
Contains all React components. The main entry point is
ClientorBox.tsx.components/: Sub-components for different parts of the editor (top toolbar, textarea, bottom bar, preview).
-
Defines the default configuration values for the component.
To maintain consistency, all components in Clientor follow a specific internal structure:
- STATES: Context consumers and local states.
- RH: Standard React hooks (e.g.,
useTransition). - CH: Custom hooks.
- REFS: Component refs.
- FEH: Functions and Event Handlers.
- EFFECTS:
useEffecthooks. - IVS: Intermediary Variables for render logic.
- TSX | JSX: The returned UI.
Example pattern:
const MyComponent = () => {
// 1. STATES
// 2. RH
// ...
// 8. TSX
return <div>...</div>;
};Clientor is open-source, and we welcome contributions!
- Join our Telegram group to discuss features.
- Create a feature branch off of the
developbranch:feature/your-feature-name. - Regularly commit with clear messages (max 128 characters).
- Submit a Pull Request with a clear explanation of your changes.
- Follow the component structure described above.
- Ensure all parts of your components are properly labeled.
- Do not edit the README directly in your PR unless instructed.
Clientor leverages the following libraries:
- lucide-react: Providing a clean and consistent icon set.
- marked: Used for parsing Markdown text into HTML.
- nanoid: For generating unique resource identifiers (e.g., image IDs).
- react & react-dom: The core framework.