import { storiesOf } from "@storybook/react"; import { IMakeRteApiProps, makeRteApi, OnDebouncedContentChangeFn, Rte } from "@vivid-planet/comet-admin-rte"; import { ContentState, convertFromHTML } from "draft-js"; import { stateToHTML } from "draft-js-export-html"; import * as React from "react"; import { PrintAnything, RteLayout } from "./helper"; type Html = string; const defaultValue: Html = "
save-format is HTML
"; const makeRteApiProps: IMakeRteApiProps = { parse: (v) => { const blocksFromHTML = convertFromHTML(v); return ContentState.createFromBlockArray(blocksFromHTML.contentBlocks, blocksFromHTML.entityMap); }, format: (v) => { return stateToHTML(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 ( <>