Skip to content

Commit

Permalink
chore: added Experiments / StoreRawMarkup story
Browse files Browse the repository at this point in the history
  • Loading branch information
makhnatkin committed Jan 16, 2025
1 parent bd34bef commit 7fe8a3e
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 1 deletion.
2 changes: 1 addition & 1 deletion demo/stories/experiments/empty-row/EmptyRow.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ export const Story: StoryObj<typeof component> = {
Story.storyName = 'Preserve Empty Rows';

export default {
title: 'Experiments',
title: 'Experiments / Preserve Empty Rows',
component,
};
13 changes: 13 additions & 0 deletions demo/stories/experiments/store-raw/StoreRawMarkup.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type {StoryObj} from '@storybook/react';

import {StoreRawMarkupDemo as component} from './StoreRawMarkup';

export const Story: StoryObj<typeof component> = {
args: {},
};
Story.storyName = 'Store Raw Markup';

export default {
title: 'Experiments',
component,
};
103 changes: 103 additions & 0 deletions demo/stories/experiments/store-raw/StoreRawMarkup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import React, {useCallback, useLayoutEffect, useState} from 'react';

import {toaster} from '@gravity-ui/uikit/toaster-singleton-react-18';

import {MarkdownEditorView, type RenderPreview, useMarkdownEditor} from '../../../../src';
import {PlaygroundLayout} from '../../../components/PlaygroundLayout';
import {SplitModePreview} from '../../../components/SplitModePreview';
import {plugins} from '../../../defaults/md-plugins';
import {useMarkdownEditorValue} from '../../../hooks/useMarkdownEditorValue';

const initialMarkup = `
## YFM Table
### Simple table
#|
|| **Header1** | **Header2** ||
|| Text | Text ||
|#
### Multiline content
#|
||
Text
on two lines
|
- Potatoes
- Carrot
- Onion
- Cucumber
||
|#
### Nested tables
#|
|| 1 | Text before other table
#|
|| 5 | 6 ||
|| 7 | 8 ||
|#
Text after other table
||
|| 3 | 4 ||
|#
`;

type StoreRawMarkupDemoProps = {};

export const StoreRawMarkupDemo = React.memo<StoreRawMarkupDemoProps>(() => {
const [mdMarkup, setMdMarkup] = useState(initialMarkup);

const renderPreview = useCallback<RenderPreview>(
({getValue, md}) => (
<SplitModePreview
getValue={getValue}
allowHTML={md.html}
linkify={md.linkify}
linkifyTlds={md.linkifyTlds}
breaks={md.breaks}
needToSanitizeHtml
plugins={plugins}
/>
),
[],
);

const editor = useMarkdownEditor(
{
initial: {markup: mdMarkup},
markupConfig: {renderPreview},
},
[],
);

// for preserve edited content
const value = useMarkdownEditorValue(editor);
useLayoutEffect(() => {
setMdMarkup(value);
}, [value]);

return (
<PlaygroundLayout
editor={editor}
view={({className}) => (
<MarkdownEditorView
autofocus
stickyToolbar
settingsVisible
editor={editor}
toaster={toaster}
className={className}
/>
)}
/>
);
});

StoreRawMarkupDemo.displayName = 'Experiments / StoreRawMarkup';

0 comments on commit 7fe8a3e

Please sign in to comment.