forms-wysiwyg
v0.1.0
Published
Standalone React + TypeScript WYSIWYG editor package.
Maintainers
Readme
forms-wysiwyg
Standalone React WYSIWYG editor package extracted from the Forms workspace and prepared for npm-style distribution.
It ships:
- a reusable React editor component
- generated TypeScript declarations for TS consumers
- CommonJS and ESM builds
- a hidden form field option via the
nameprop for traditional form posts - image, table, emoji, source-code, fullscreen, and PDF export support
Package location
This standalone package lives at /Users/muhammadfirdaus/Sites/wysiwyg.
It is intentionally outside the Laravel app so it can be built and published independently.
Install
From the package folder:
npm install
npm run typecheck
npm run build
npm run pack:previewUsage in TypeScript
import { WysiwygEditor, type WysiwygEditorProps } from 'forms-wysiwyg';
export function ArticleEditor() {
const [content, setContent] = React.useState('<p>Hello world</p>');
return (
<WysiwygEditor
value={content}
onChange={setContent}
placeholder="Write something lovely..."
minHeight="320px"
/>
);
}Usage in JavaScript
import { WysiwygEditor } from 'forms-wysiwyg';
export function ArticleEditor() {
const [content, setContent] = React.useState('<p>Hello world</p>');
return (
<WysiwygEditor
value={content}
onChange={setContent}
placeholder="Write something lovely..."
/>
);
}Controlled and uncontrolled usage
- Use
value+onChangefor a controlled editor. - Use
defaultValueorinitialContentfor uncontrolled usage. - Use
nameif you want the current HTML mirrored into a hidden<textarea>for form submission.
Image uploads
Pass an async imagesUploadHandler(file) prop to upload images to your own API/storage service. If you do not provide one, pasted or dropped images fall back to data URLs.
Exports
The package exports:
WysiwygEditorWysiwygEditorFielddefaultImageProperties- all public TypeScript types used by the editor
Release checks
npm run typecheck
npm run build
npm run pack:preview
npm run publish:dry-runPublish checklist
- Pick a unique npm package name or scope in
package.json. - Update
versionandlicenseinpackage.jsonas needed. - Run
npm login. - Run
npm run check. - For an unscoped package, publish with
npm publish. - For a scoped public package, publish with
npm publish --access public. - Verify the release with
npm view <your-package-name> version.
If your npm account uses 2FA, npm will prompt for the OTP directly in the terminal during publish.
Notes
- React and ReactDOM are peer dependencies.
- The editor relies on the browser
contenteditableAPI anddocument.execCommand, so it should be rendered on the client in SSR apps. html2canvasandjspdfare runtime dependencies used only when exporting to PDF.- The component styles are self-contained via inline styles and an internal
<style>block, so there is no separate CSS file to import.
