Skip to content

Commit de54991

Browse files
authored
feat!: added more functionality (#207)
1 parent 5ab5d7e commit de54991

File tree

320 files changed

+17185
-756
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

320 files changed

+17185
-756
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
],
99
"plugins": ["lodash"],
1010
"rules": {
11-
"lodash/import-scope": [2, "method"]
11+
"lodash/import-scope": [2, "method"],
12+
"jsx-a11y/no-autofocus": "warn"
1213
}
1314
}

demo/HtmlPreview.tsx

Lines changed: 0 additions & 57 deletions
This file was deleted.

demo/PMSelection.tsx

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,52 @@
11
import React from 'react';
22

3-
import type {EditorView} from 'prosemirror-view';
3+
import {EditorView} from 'prosemirror-view';
4+
import {useEffectOnce, useUpdate} from 'react-use';
45

5-
import {ClassNameProps, isNodeSelection, isTextSelection, isWholeSelection} from '../src';
6+
import {type ClassNameProps, isNodeSelection, isTextSelection, isWholeSelection} from '../src';
7+
import type {Editor} from '../src/bundle';
68

7-
export type PMSelectionProps = ClassNameProps & {
9+
export type WysiwygSelectionProps = ClassNameProps & {
10+
editorRef: React.RefObject<Editor>;
11+
};
12+
13+
export function WysiwygSelection({editorRef, className}: WysiwygSelectionProps) {
14+
const rerender = useUpdate();
15+
useEffectOnce(() => {
16+
rerender();
17+
});
18+
19+
const editor = editorRef.current;
20+
const view = editor?.currentType === 'wysiwyg' && editor._wysiwygView;
21+
22+
React.useLayoutEffect(() => {
23+
if (!editor) return undefined;
24+
editor.on(
25+
// @ts-expect-error TODO: add public event for selection change
26+
'rerender-toolbar',
27+
rerender,
28+
);
29+
editor.on('change-editor-type', rerender);
30+
return () => {
31+
editor.off(
32+
// @ts-expect-error TODO: add public event for selection change
33+
'rerender-toolbar',
34+
rerender,
35+
);
36+
editor.off('change-editor-type', rerender);
37+
};
38+
}, [editor, rerender]);
39+
40+
if (!view) return null;
41+
42+
return <PMSelection view={view} className={className} />;
43+
}
44+
45+
type PMSelectionProps = ClassNameProps & {
846
view: EditorView;
947
};
1048

11-
export function PMSelection({view, className}: PMSelectionProps) {
49+
function PMSelection({view, className}: PMSelectionProps) {
1250
const sel = view.state.selection;
1351
const renderFromTo = () => (
1452
<>

demo/Playground.scss

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,26 @@
1515
@include text-header-2();
1616
}
1717

18-
&__preview-type {
18+
&__version {
1919
position: absolute;
2020
right: 0;
2121
bottom: 0;
22-
}
23-
24-
&__controls {
25-
display: flex;
26-
align-items: center;
27-
column-gap: 8px;
2822

29-
& > p {
30-
margin: 0;
31-
}
23+
@include text-code-inline-1();
3224
}
3325

3426
&__markup {
27+
overflow-y: auto;
28+
29+
margin: 0;
30+
padding: 5px 10px;
31+
3532
background-color: var(--g-color-base-generic);
3633
}
3734

3835
&__editor-view {
39-
min-height: 100px;
36+
min-height: 150px;
4037
margin: 20px 0;
41-
padding-left: 4px;
4238
}
4339

4440
&__pm-selection {

demo/Playground.stories.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,49 @@
11
import React from 'react';
22

3-
import type {ComponentMeta, Story} from '@storybook/react'; // eslint-disable-line import/no-extraneous-dependencies
3+
// eslint-disable-next-line import/no-extraneous-dependencies
4+
import type {ComponentMeta, Story} from '@storybook/react';
45

56
import {Playground as PlaygroundComponent, PlaygroundProps} from './Playground';
7+
import {parseLocation} from './location';
68
import {initialMdContent} from './md-content';
79

810
export default {
911
title: 'YFM Editor',
12+
component: PlaygroundComponent,
1013
} as ComponentMeta<any>;
1114

1215
type PlaygroundStoryProps = Pick<
1316
PlaygroundProps,
14-
'breaks' | 'allowHTML' | 'linkify' | 'linkifyTlds'
17+
| 'initialEditor'
18+
| 'settingsVisible'
19+
| 'breaks'
20+
| 'allowHTML'
21+
| 'linkify'
22+
| 'linkifyTlds'
23+
| 'sanitizeHtml'
24+
| 'prepareRawMarkup'
25+
| 'splitModeOrientation'
26+
| 'stickyToolbar'
27+
| 'initialSplitModeEnabled'
28+
| 'renderPreviewDefined'
29+
| 'height'
1530
>;
1631
export const Playground: Story<PlaygroundStoryProps> = (props) => (
17-
<PlaygroundComponent {...props} initial={initialMdContent} />
32+
<PlaygroundComponent {...props} initial={parseLocation() || initialMdContent} />
1833
);
1934

2035
Playground.args = {
36+
initialEditor: 'wysiwyg',
37+
settingsVisible: true,
2138
allowHTML: true,
2239
breaks: true,
2340
linkify: true,
2441
linkifyTlds: [],
42+
sanitizeHtml: false,
43+
prepareRawMarkup: false,
44+
splitModeOrientation: 'horizontal',
45+
stickyToolbar: true,
46+
initialSplitModeEnabled: false,
47+
renderPreviewDefined: true,
48+
height: 'initial',
2549
};

0 commit comments

Comments
 (0)