Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: markdown-editor@15 #554

Merged
merged 23 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
09c1a7b
feat(deps)!: move lodash from peerDependencies to dependencies
d3m1d0v Jan 17, 2025
9877744
feat(deps): upd gravity-ui/icons to v2.12.0
d3m1d0v Jan 17, 2025
ab8b4ad
feat(deps): upd gravity-ui/i18n to v1.7.0
d3m1d0v Jan 17, 2025
6497fc4
test(deps): update jest to v29.7.0
d3m1d0v Jan 20, 2025
4c911ff
feat: update typescript to v5.7.3
d3m1d0v Jan 21, 2025
06121f3
feat!: removed deprecated properties from MarkdownEditorOptions type …
makhnatkin Feb 4, 2025
85d7688
feat!: removed deprecated properties (#583)
makhnatkin Feb 5, 2025
8ecdb51
feat(package)!: drop typesVersions and improve exports (#585)
d3m1d0v Feb 5, 2025
24ed8c6
feat(build)!: use new jsx transform (#586)
d3m1d0v Feb 5, 2025
0f0e2cf
feat(deps): update ProseMirror and CodeMirror packages (#589)
makhnatkin Feb 6, 2025
7f29908
feat(deps): update lezer packages (#590)
d3m1d0v Feb 6, 2025
a1e6e13
feat(deps): updated @diplodoc/transform and related packages (#591)
makhnatkin Feb 7, 2025
405808b
feat!: update esm and cjs build (#592)
d3m1d0v Feb 7, 2025
2baa8fe
build: bump gulp-utils to v1.0.1
d3m1d0v Feb 10, 2025
4e44d37
Merge branch 'main' into v15next
d3m1d0v Feb 10, 2025
764f539
feat(types)!: updated MarkdownSerializer types (#596)
makhnatkin Feb 10, 2025
ef40d8f
feat(presets): fixed commonmark-specs preset
d3m1d0v Feb 10, 2025
411ea8b
feat!: change re-exports from `src/plugins`
d3m1d0v Feb 10, 2025
752e4a3
Merge branch 'main' into v15next
d3m1d0v Feb 10, 2025
3c7f0bc
feat!: update uikit to v7
d3m1d0v Jan 29, 2025
b6b8277
feat(bundle)!: remove toaster from MarkdownEditorView props
d3m1d0v Feb 10, 2025
551eb6e
Merge branch 'main' into v15next
d3m1d0v Feb 11, 2025
26ecd42
fix(core): fixed circularr dependencies
d3m1d0v Feb 11, 2025
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
4 changes: 3 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
}
],
"@babel/preset-typescript",
"@babel/preset-react"
["@babel/preset-react", {
"runtime": "automatic"
}]
],
"plugins": []
}
3 changes: 2 additions & 1 deletion .storybook/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import type {Preview} from '@storybook/react';
import {MINIMAL_VIEWPORTS} from '@storybook/addon-viewport';
import {withThemeProvider} from '../demo/hocs/withThemeProvider';
import {withLang} from '../demo/hocs/withLang';
import {withToaster} from '../demo/hocs/withToaster';

const preview: Preview = {
decorators: [withThemeProvider, withLang],
decorators: [withThemeProvider, withLang, withToaster],
parameters: {
jsx: {showFunctions: true}, // To show functions in sources
viewport: {
Expand Down
3 changes: 1 addition & 2 deletions README-ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ npm install @gravity-ui/markdown-editor
```tsx
import React from 'react';
import {useMarkdownEditor, MarkdownEditorView} from '@gravity-ui/markdown-editor';
import {toaster} from '@gravity-ui/uikit/toaster-singleton-react-18';

function Editor({onSubmit}) {
const editor = useMarkdownEditor({allowHTML: false});
Expand All @@ -48,7 +47,7 @@ function Editor({onSubmit}) {
};
}, [onSubmit]);

return <MarkdownEditorView stickyToolbar autofocus toaster={toaster} editor={editor} />;
return <MarkdownEditorView stickyToolbar autofocus editor={editor} />;
}
```

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ To set up styling and theme see [UIKit docs](https://github.com/gravity-ui/uikit
```tsx
import React from 'react';
import {useMarkdownEditor, MarkdownEditorView} from '@gravity-ui/markdown-editor';
import {toaster} from '@gravity-ui/uikit/toaster-singleton-react-18';

function Editor({onSubmit}) {
const editor = useMarkdownEditor({allowHTML: false});
Expand All @@ -48,7 +47,7 @@ function Editor({onSubmit}) {
};
}, [onSubmit]);

return <MarkdownEditorView stickyToolbar autofocus toaster={toaster} editor={editor} />;
return <MarkdownEditorView stickyToolbar autofocus editor={editor} />;
}
```
Read more:
Expand Down
2 changes: 1 addition & 1 deletion demo/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "@gravity-ui/eslint-config/client"
"extends": ["@gravity-ui/eslint-config/client", "plugin:react/jsx-runtime"]
}
4 changes: 2 additions & 2 deletions demo/components/PMSelection.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import {useLayoutEffect} from 'react';

import {EditorView} from 'prosemirror-view';
import {useEffectOnce, useUpdate} from 'react-use';
Expand All @@ -23,7 +23,7 @@ export function WysiwygSelection({editor, className}: WysiwygSelectionProps) {

const view = editor?.currentMode === 'wysiwyg' && editor._wysiwygView;

React.useLayoutEffect(() => {
useLayoutEffect(() => {
if (!editor) return undefined;
editor.on(
// @ts-expect-error TODO: add public event for selection change
Expand Down
83 changes: 37 additions & 46 deletions demo/components/Playground.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React, {CSSProperties, useCallback, useEffect, useState} from 'react';
import {CSSProperties, memo, useCallback, useEffect, useState} from 'react';

import {defaultOptions} from '@diplodoc/transform/lib/sanitize';
import {Button, DropdownMenu} from '@gravity-ui/uikit';
import {toaster} from '@gravity-ui/uikit/toaster-singleton-react-18';

import {
type DirectiveSyntaxValue,
Expand Down Expand Up @@ -39,7 +38,7 @@
import {SplitModePreview} from './SplitModePreview';

const fileUploadHandler: FileUploadHandler = async (file) => {
console.info('[Playground] Uploading file: ' + file.name);

Check warning on line 41 in demo/components/Playground.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected console statement

Check warning on line 41 in demo/components/Playground.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected console statement
await randomDelay(1000, 3000);
return {url: URL.createObjectURL(file)};
};
Expand Down Expand Up @@ -75,14 +74,7 @@
onChangeEditorType?: (mode: MarkdownEditorMode) => void;
onChangeSplitModeEnabled?: (splitModeEnabled: boolean) => void;
directiveSyntax?: DirectiveSyntaxValue;
} & Pick<
UseMarkdownEditorProps,
| 'needToSetDimensionsForUploadedImages'
| 'extraExtensions'
| 'renderPreview'
| 'extensionOptions'
| 'experimental'
> &
} & Pick<UseMarkdownEditorProps, 'experimental' | 'wysiwygConfig'> &
Pick<
MarkdownEditorViewProps,
| 'markupHiddenActionsConfig'
Expand All @@ -94,12 +86,12 @@
>;

logger.setLogger({
metrics: console.info,

Check warning on line 89 in demo/components/Playground.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected console statement

Check warning on line 89 in demo/components/Playground.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected console statement
action: (data) => console.info(`Action: ${data.action}`, data),

Check warning on line 90 in demo/components/Playground.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected console statement

Check warning on line 90 in demo/components/Playground.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected console statement
...console,
});

export const Playground = React.memo<PlaygroundProps>((props) => {
export const Playground = memo<PlaygroundProps>((props) => {
const {
initial,
initialEditor,
Expand All @@ -116,8 +108,7 @@
stickyToolbar,
renderPreviewDefined,
height,
extraExtensions,
extensionOptions,
wysiwygConfig,
toolbarsPreset,
wysiwygToolbarConfig,
wysiwygCommandMenuConfig,
Expand All @@ -126,21 +117,18 @@
placeholderOptions,
enableSubmitInPreview,
hidePreviewAfterSubmit,
needToSetDimensionsForUploadedImages,
experimental,
directiveSyntax,
} = props;
const [editorMode, setEditorMode] = React.useState<MarkdownEditorMode>(
initialEditor ?? 'wysiwyg',
);
const [mdRaw, setMdRaw] = React.useState<MarkupString>(initial || '');
const [editorMode, setEditorMode] = useState<MarkdownEditorMode>(initialEditor ?? 'wysiwyg');
const [mdRaw, setMdRaw] = useState<MarkupString>(initial || '');

React.useEffect(() => {
useEffect(() => {
updateLocation(mdRaw);
}, [mdRaw]);

const renderPreview = useCallback<RenderPreview>(
({getValue, md, directiveSyntax}) => (

Check warning on line 131 in demo/components/Playground.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

'directiveSyntax' is already declared in the upper scope on line 121 column 9

Check warning on line 131 in demo/components/Playground.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

'directiveSyntax' is already declared in the upper scope on line 121 column 9
<SplitModePreview
getValue={getValue}
allowHTML={md.html}
Expand Down Expand Up @@ -193,39 +181,44 @@
</style
`,
});
if (extraExtensions) builder.use(extraExtensions);
if (wysiwygConfig?.extensions) builder.use(wysiwygConfig.extensions);
},
extensionOptions: {
commandMenu: {actions: wysiwygCommandMenuConfig ?? wCommandMenuConfig},
imgSize: {
parseInsertedUrlAsImage,
},
...wysiwygConfig?.extensionOptions,
},
},
allowHTML,
linkify,
linkifyTlds,
initialMarkup: mdRaw,
breaks: breaks ?? true,
initialEditorMode: editorMode,
initialSplitModeEnabled: initialSplitModeEnabled,
initialToolbarVisible: true,
splitMode: splitModeOrientation,
needToSetDimensionsForUploadedImages,
renderPreview: renderPreviewDefined ? renderPreview : undefined,
fileUploadHandler,
md: {
html: allowHTML,
linkify,
linkifyTlds,
breaks: breaks ?? true,
},
initial: {
markup: mdRaw,
mode: editorMode,
toolbarVisible: true,
splitModeEnabled: initialSplitModeEnabled,
},
handlers: {
uploadFile: fileUploadHandler,
},
experimental: {
...experimental,
directiveSyntax,
preserveEmptyRows: preserveEmptyRows,
},
prepareRawMarkup: prepareRawMarkup
? (value) => '**prepare raw markup**\n\n' + value
: undefined,
extensionOptions: {
commandMenu: {actions: wysiwygCommandMenuConfig ?? wCommandMenuConfig},
imgSize: {
parseInsertedUrlAsImage,
},
...extensionOptions,
preserveEmptyRows,
prepareRawMarkup: prepareRawMarkup
? (value) => '**prepare raw markup**\n\n' + value
: undefined,
},
markupConfig: {
extensions: markupConfigExtensions,
parseInsertedUrlAsImage,
renderPreview,
splitMode: splitModeOrientation,
},
},
[
Expand All @@ -236,8 +229,7 @@
splitModeOrientation,
renderPreviewDefined,
renderPreview,
extraExtensions,
needToSetDimensionsForUploadedImages,
experimental?.needToSetDimensionsForUploadedImages,
initial,
experimental?.enableNewImageSizeCalculation,
experimental?.needToSetDimensionsForUploadedImages,
Expand All @@ -264,14 +256,14 @@
setEditorMode(mode);
}
const onToolbarAction = ({id, editorMode: type}: ToolbarActionData) => {
console.info(`The '${id}' action is performed in the ${type}-editor.`);

Check warning on line 259 in demo/components/Playground.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected console statement

Check warning on line 259 in demo/components/Playground.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected console statement
};
function onChangeSplitModeEnabled({splitModeEnabled}: {splitModeEnabled: boolean}) {
props.onChangeSplitModeEnabled?.(splitModeEnabled);
console.info(`Split mode enabled: ${splitModeEnabled}`);

Check warning on line 263 in demo/components/Playground.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected console statement

Check warning on line 263 in demo/components/Playground.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected console statement
}
function onChangeToolbarVisibility({visible}: {visible: boolean}) {
console.info('Toolbar visible: ' + visible);

Check warning on line 266 in demo/components/Playground.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected console statement

Check warning on line 266 in demo/components/Playground.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected console statement
}

mdEditor.on('cancel', onCancel);
Expand All @@ -291,7 +283,7 @@
mdEditor.off('change-split-mode-enabled', onChangeSplitModeEnabled);
mdEditor.off('change-toolbar-visibility', onChangeToolbarVisibility);
};
}, [mdEditor]);

Check warning on line 286 in demo/components/Playground.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

React Hook useEffect has a missing dependency: 'props'. Either include it or remove the dependency array. However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the useEffect call and refer to those specific props inside useEffect

Check warning on line 286 in demo/components/Playground.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

React Hook useEffect has a missing dependency: 'props'. Either include it or remove the dependency array. However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the useEffect call and refer to those specific props inside useEffect

return (
<PlaygroundLayout
Expand All @@ -300,7 +292,6 @@
view={({className}) => (
<MarkdownEditorView
autofocus
toaster={toaster}
className={className}
stickyToolbar={Boolean(stickyToolbar)}
toolbarsPreset={toolbarsPreset}
Expand Down
6 changes: 3 additions & 3 deletions demo/components/PlaygroundLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useEffect} from 'react';
import {StrictMode, useEffect} from 'react';

import {useUpdate} from 'react-use';

Expand Down Expand Up @@ -49,14 +49,14 @@ export const PlaygroundLayout: React.FC<PlaygroundLayoutProps> = function Playgr

<hr />

<React.StrictMode>
<StrictMode>
<div className={b('editor')} style={{height: props.viewHeight ?? 'initial'}}>
{props.view({className: b('editor-view')})}

<WysiwygDevTools editor={editor} />
<WysiwygSelection editor={editor} className={b('pm-selection')} />
</div>
</React.StrictMode>
</StrictMode>

<hr />

Expand Down
4 changes: 2 additions & 2 deletions demo/components/PlaygroundMini.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import {memo} from 'react';

import {getInitialMd} from '../utils/getInitialMd';

Expand All @@ -25,7 +25,7 @@ export type PlaygroundMiniProps = Pick<
| 'directiveSyntax'
> & {withDefaultInitialContent?: boolean};

export const PlaygroundMini = React.memo<PlaygroundMiniProps>(
export const PlaygroundMini = memo<PlaygroundMiniProps>(
({withDefaultInitialContent, initial, ...props}) => (
<Playground
{...props}
Expand Down
6 changes: 3 additions & 3 deletions demo/components/ProseMirrorDevTools.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import {useEffect, useLayoutEffect} from 'react';

import {applyDevTools, removeDevTools} from 'prosemirror-dev-toolkit';
import {EditorView} from 'prosemirror-view';
Expand All @@ -18,7 +18,7 @@ export function WysiwygDevTools({editor}: WysiwygDevToolsProps) {

const view = editor?.currentMode === 'wysiwyg' && editor._wysiwygView;

React.useLayoutEffect(() => {
useLayoutEffect(() => {
if (!editor) return undefined;
editor.on('change-editor-mode', rerender);
return () => {
Expand All @@ -36,7 +36,7 @@ type ProseMirrorDevToolsProps = {
};

function ProseMirrorDevTools({view}: ProseMirrorDevToolsProps) {
React.useEffect(() => {
useEffect(() => {
applyDevTools(view);
return () => {
removeDevTools();
Expand Down
2 changes: 1 addition & 1 deletion demo/components/SplitModePreview.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useEffect, useMemo, useRef, useState} from 'react';
import {useEffect, useMemo, useRef, useState} from 'react';

import transform from '@diplodoc/transform';
import {useThemeValue} from '@gravity-ui/uikit';
Expand Down Expand Up @@ -55,7 +55,7 @@
setHtml(res.html);
setMeta(res.meta);
}, 200),
[getValue, allowHTML, breaks, plugins, linkify, linkifyTlds, needToSanitizeHtml, theme],

Check warning on line 58 in demo/components/SplitModePreview.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

React Hook useMemo has an unnecessary dependency: 'theme'. Either exclude it or remove the dependency array

Check warning on line 58 in demo/components/SplitModePreview.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

React Hook useMemo has an unnecessary dependency: 'theme'. Either exclude it or remove the dependency array
);

useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions demo/defaults/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Easily connect to your React app with a hook:
\`\`\`plaintext
import React from 'react';
import { useMarkdownEditor, MarkdownEditorView } from '@gravity-ui/markdown-editor';
import { toaster } from '@gravity-ui/uikit/toaster-singleton-react-18';
import { toaster } from '@gravity-ui/uikit/toaster-singleton';

function Editor({ onSubmit }) {
const editor = useMarkdownEditor({ allowHTML: false });
Expand All @@ -65,7 +65,7 @@ function Editor({ onSubmit }) {
};
}, [onSubmit]);

return <MarkdownEditorView stickyToolbar autofocus toaster={toaster} editor={editor} />;
return <MarkdownEditorView stickyToolbar autofocus editor={editor} />;
}
\`\`\`

Expand Down
2 changes: 0 additions & 2 deletions demo/hocs/withLang.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import React from 'react';

import {configure} from '@gravity-ui/uikit';
import type {Decorator} from '@storybook/react';

Expand Down
2 changes: 0 additions & 2 deletions demo/hocs/withThemeProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import React from 'react';

import {ThemeProvider} from '@gravity-ui/uikit';
import type {Decorator} from '@storybook/react';

Expand Down
13 changes: 13 additions & 0 deletions demo/hocs/withToaster.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {ToasterProvider} from '@gravity-ui/uikit';
import {toaster} from '@gravity-ui/uikit/toaster-singleton';
import type {Decorator} from '@storybook/react';

import '@gravity-ui/uikit/styles/styles.scss';

export const withToaster: Decorator = (StoryItem, context) => {
return (
<ToasterProvider toaster={toaster}>
<StoryItem {...context} />
</ToasterProvider>
);
};
7 changes: 2 additions & 5 deletions demo/stories/css-variables/CSSVariables.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import React from 'react';

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

import {MarkdownEditorView, useMarkdownEditor} from '../../../src';
import {PlaygroundLayout} from '../../components/PlaygroundLayout';
import {markup} from '../../defaults/content';

export const CustomCSSVariablesDemo = React.memo((styles) => {
export const CustomCSSVariablesDemo = memo((styles) => {
const editor = useMarkdownEditor({initial: {markup}});

return (
Expand All @@ -19,7 +17,6 @@ export const CustomCSSVariablesDemo = React.memo((styles) => {
stickyToolbar
settingsVisible
editor={editor}
toaster={toaster}
className={className}
/>
)}
Expand Down
Loading
Loading