Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,23 +334,23 @@ The stats bar automatically adapts to your theme colors using CSS variables.
function MarkdownEditor({ value, onChange }) {
const ref = useRef();
const editorRef = useRef();

useEffect(() => {
const [instance] = OverType.init(ref.current, {
value,
onChange
});
editorRef.current = instance;

return () => editorRef.current?.destroy();
}, []);

useEffect(() => {
if (editorRef.current && value !== editorRef.current.getValue()) {
editorRef.current.setValue(value);
}
}, [value]);

return <div ref={ref} style={{ height: '400px' }} />;
}
```
Expand Down Expand Up @@ -417,42 +417,42 @@ new OverType(target, options)
lineHeight: 1.6,
fontFamily: 'monospace',
padding: '16px',

// Theme - 'solar', 'cave', or custom theme object
theme: 'solar',

// Custom colors (override theme colors)
colors: {
h1: '#e63946',
h2: '#457b9d',
// ... any color variable
},

// Mobile styles (applied at <= 640px)
mobile: {
fontSize: '16px',
padding: '12px',
lineHeight: 1.5
},

// Behavior
autofocus: false,
placeholder: 'Start typing...',
value: '',

// Auto-resize
autoResize: false, // Auto-expand height with content
minHeight: '100px', // Minimum height when autoResize is enabled
maxHeight: null, // Maximum height (null = unlimited)

// Native textarea properties
textareaProps: {
required: true,
maxLength: 500,
name: 'content',
// Any HTML textarea attribute
},

// Toolbar
toolbar: false, // Enable/disable toolbar
toolbarButtons: [], // Custom button array (v2.0)
Expand All @@ -464,13 +464,13 @@ new OverType(target, options)

// Smart lists
smartLists: true, // Enable GitHub-style list continuation on Enter

// Stats bar
showStats: false, // Enable/disable stats bar
statsFormatter: (stats) => { // Custom stats format
return `${stats.chars} chars | ${stats.words} words`;
},

// Callbacks
onChange: (value, instance) => {},
onKeydown: (event, instance) => {}
Expand Down Expand Up @@ -511,6 +511,9 @@ editor.showPreviewMode() // Switch to preview mode
editor.focus()
editor.blur()

// Perform actions. Equivalent to clicking on the corresponding toolbar button.
editor.performAction('toggleBold')

// Show or hide stats bar
editor.showStats(true) // Show stats
editor.showStats(false) // Hide stats
Expand Down Expand Up @@ -809,7 +812,7 @@ Contributions are welcome! Please feel free to submit a Pull Request.

Built with the radical idea that sometimes dumb ideas work.

**Ready for another radical idea?**
**Ready for another radical idea?**
Let's remove every layer of the web application stack.

### Hyperclay
Expand Down
1 change: 1 addition & 0 deletions dist/overtype.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export interface OverTypeInstance {
setTheme(theme: string | Theme): this;
setCodeHighlighter(highlighter: ((code: string, language: string) => string) | null): void;
updatePreview(): void;
performAction(actionId: string, event?: Event | null): Promise<boolean>;

// HTML output methods
getRenderedHTML(options?: RenderOptions): string;
Expand Down
1 change: 1 addition & 0 deletions scripts/generate-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ export interface OverTypeInstance {
setTheme(theme: string | Theme): this;
setCodeHighlighter(highlighter: ((code: string, language: string) => string) | null): void;
updatePreview(): void;
performAction(actionId: string, event?: Event | null): Promise<boolean>;

// HTML output methods
getRenderedHTML(options?: RenderOptions): string;
Expand Down
1 change: 1 addition & 0 deletions src/overtype.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export interface OverTypeInstance {
setTheme(theme: string | Theme): this;
setCodeHighlighter(highlighter: ((code: string, language: string) => string) | null): void;
updatePreview(): void;
performAction(actionId: string, event?: Event | null): Promise<boolean>;

// HTML output methods
getRenderedHTML(options?: RenderOptions): string;
Expand Down
2 changes: 2 additions & 0 deletions test/test-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ if (editorsWithOptions.length > 0) {
instance.focus();
instance.blur();
instance.updatePreview();
const actionResult: Promise<boolean> = instance.performAction('toggleBold');
console.log(actionResult);
instance.showStats(true);
instance.setTheme('cave');
instance.reinit({ fontSize: '18px' });
Expand Down