type InsertAtCursor = (textArea: HTMLTextAreaElement, text: string) => void;
// toolbar handler
export const handleMetadataClick = (insertAtCursor: InsertAtCursor) => {
const textArea = document.querySelector("textarea");
if (textArea) {
const metadata = `---
title: Post Title
description: Your Post Description
date: ${new Date().toISOString().split("T")[0]}
image: example-img.png
---\n\n`;
insertAtCursor(textArea, metadata);
}
};
export const handleParagraphClick = (insertAtCursor: InsertAtCursor) => {
const textArea = document.querySelector("textarea");
if (textArea) {
insertAtCursor(textArea, "this is regular text, **bold text**, *italic text*\n");
}
};
export const handleHeading2Click = (insertAtCursor: InsertAtCursor) => {
const textArea = document.querySelector("textarea");
if (textArea) {
insertAtCursor(textArea, "## Heading 2\n");
}
};
export const handleHeading3Click = (insertAtCursor: InsertAtCursor) => {
const textArea = document.querySelector("textarea");
if (textArea) {
insertAtCursor(textArea, "### Heading 3\n");
}
};
export const handleBulletListClick = (insertAtCursor: InsertAtCursor) => {
const textArea = document.querySelector("textarea");
if (textArea) {
insertAtCursor(textArea, "- List One\n- List Two\n- Other List\n");
}
};
export const handleNumberedListClick = (insertAtCursor: InsertAtCursor) => {
const textArea = document.querySelector("textarea");
if (textArea) {
insertAtCursor(textArea, "1. Number One\n2. Number Two\n3. Number Three\n");
}
};
export const handleLinkClick = (insertAtCursor: InsertAtCursor) => {
const textArea = document.querySelector("textarea");
if (textArea) {
insertAtCursor(textArea, "[Visit OpenAI](https://www.openai.com)\n");
}
};
export const handleImageClick = (insertAtCursor: InsertAtCursor) => {
const textArea = document.querySelector("textarea");
if (textArea) {
insertAtCursor(textArea, "\n");
}
};
export const handleBlockquoteClick = (insertAtCursor: InsertAtCursor) => {
const textArea = document.querySelector("textarea");
if (textArea) {
insertAtCursor(textArea, "> The overriding design goal for Markdown's formatting syntax is to make it as readable as possible.\n");
}
};
export const handleCodeBlockClick = (insertAtCursor: InsertAtCursor) => {
const textArea = document.querySelector("textarea");
if (textArea) {
insertAtCursor(
textArea,
"```javascript:main.js showLineNumbers {3-4}\nfunction isRocketAboutToCrash() {\n // Check if the rocket is stable\n if (!isStable()) {\n NoCrash(); // Prevent the crash\n }\n}\n```\n"
);
}
};
export const handleTableClick = (insertAtCursor: InsertAtCursor) => {
const textArea = document.querySelector("textarea");
if (textArea) {
insertAtCursor(
textArea,
`| **Feature** | **Description** |
| ------------------------------- | ----------------------------------------------------- |
| MDX Support | Write interactive documentation with MDX. |
| Nested Pages | Organize content in a nested, hierarchical structure. |
| Blog Section | Include a dedicated blog section. |
| Pagination | Split content across multiple pages. |
`
);
}
};
export const handleNoteClick = (insertAtCursor: InsertAtCursor, type: string) => {
return () => {
const textArea = document.querySelector("textarea");
if (textArea) {
const noteTemplate = `\n This is a ${type} message.\n\n`;
insertAtCursor(textArea, noteTemplate);
}
};
};
export const handleComponentClick = (insertAtCursor: InsertAtCursor, component: string) => {
return () => {
const textArea = document.querySelector("textarea");
if (!textArea) return;
const templates: { [key: string]: string } = {
stepper: `
Content for step 1
Content for step 2
\n`,
card: `
This is how you use a card with an icon and a link. Clicking on this card brings you to the Card Group page.
\n`,
button: `\n`,
accordion: `
this is an example of plain text content from the accordion component and below is markdown ;
1. number one
2. number two
3. number three
\n`,
youtube: `\n`,
tooltip: `What do you know about ? Create interactive nested documentations using MDX.\n`,
tabs: `
Tab 1
Tab 2
Content for tab 1
Content for tab 2
\n`
};
insertAtCursor(textArea, templates[component]);
};
};
// slash command handler
export const MARK_COMPONENTS = [
{ label: "Metadata", value: `---
title: Post Title
description: Your Post Description
date: ${new Date().toISOString().split("T")[0]}
image: example-img.png
---\n\n` },
{ label: "Heading 2", value: "## Heading 2\n" },
{ label: "Heading 3", value: "### Heading 3\n" },
{ label: "Paragraph", value: "this is regular text, **bold text**, *italic text*\n" },
{ label: "Bullet List", value: "- List One\n- List Two\n- Other List\n" },
{ label: "Numbered List", value: "1. Number One\n2. Number Two\n3. Number Three\n" },
{ label: "Blockquote", value: "> The overriding design goal for Markdown's formatting syntax is to make it as readable as possible.\n" },
{ label: "Code Block", value: "```javascript:main.js showLineNumbers {3-4}\nfunction isRocketAboutToCrash() {\n // Check if the rocket is stable\n if (!isStable()) {\n NoCrash(); // Prevent the crash\n }\n}\n```\n" },
{ label: "Table", value: `| **Feature** | **Description** |
| ------------------------------- | ----------------------------------------------------- |
| MDX Support | Write interactive documentation with MDX. |
| Nested Pages | Organize content in a nested, hierarchical structure. |
| Blog Section | Include a dedicated blog section. |
| Pagination | Split content across multiple pages. |
` },
{ label: "Link", value: "[Visit OpenAI](https://www.openai.com)\n" },
{ label: "Image", value: "\n" },
// ⭐ Komponen Interaktif DocuBook ⭐
{ label: "Stepper", value: `
Content for step 1
Content for step 2
\n` },
{ label: "Button", value: `\n` },
{ label: "Accordion", value: `
This is an example of plain text content inside the accordion component.
1. Number One
2. Number Two
3. Number Three
\n` },
{ label: "Youtube", value: `\n` },
{ label: "Tooltip", value: `What do you know about ?\n` },
{ label: "Tabs", value: `
Tab 1
Tab 2
Content for tab 1
Content for tab 2
\n` },
{ label: "Note", value: `
This is a note message.
\n` },
{ label: "Danger", value: `
This is a danger message.
\n` },
{ label: "Warning", value: `
This is a warning message.
\n` },
{ label: "Success", value: `
This is a success message.
\n` }
];