import { storiesOf } from "@storybook/react"; import { IMakeRteApiProps, makeRteApi, OnDebouncedContentChangeFn, Rte } from "@vivid-planet/comet-admin-rte"; import { stateToMarkdown } from "draft-js-export-markdown"; import { stateFromMarkdown } from "draft-js-import-markdown"; import * as React from "react"; import { PrintAnything, RteLayout } from "./helper"; type Markdown = string; const defaultValue: Markdown = ` # Headline 1 This is markdown `; const makeRteApiProps: IMakeRteApiProps = { parse: (v) => { return stateFromMarkdown(v); }, format: (v) => { return stateToMarkdown(v); }, }; const [useRteApi] = makeRteApi(makeRteApiProps); function Story() { const [saveableContent, setSaveableContent] = React.useState(defaultValue); const handleDebouncedContentChange: OnDebouncedContentChangeFn = (innerEditorState, convertStateToRawContent) => { setSaveableContent(convertStateToRawContent(innerEditorState)); }; const { editorState, setEditorState } = useRteApi({ defaultValue, onDebouncedContentChange: handleDebouncedContentChange }); return ( <> {saveableContent} ); } storiesOf("comet-admin-rte/save-as", module).add("Save as MD", () => );