Skip to content

Commit

Permalink
feat!: added more functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
smsochneg committed Mar 25, 2024
1 parent 5ab5d7e commit 001da37
Show file tree
Hide file tree
Showing 320 changed files with 17,185 additions and 756 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
],
"plugins": ["lodash"],
"rules": {
"lodash/import-scope": [2, "method"]
"lodash/import-scope": [2, "method"],
"jsx-a11y/no-autofocus": "warn"
}
}
57 changes: 0 additions & 57 deletions demo/HtmlPreview.tsx

This file was deleted.

46 changes: 42 additions & 4 deletions demo/PMSelection.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,52 @@
import React from 'react';

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

import {ClassNameProps, isNodeSelection, isTextSelection, isWholeSelection} from '../src';
import {type ClassNameProps, isNodeSelection, isTextSelection, isWholeSelection} from '../src';
import type {Editor} from '../src/bundle';

export type PMSelectionProps = ClassNameProps & {
export type WysiwygSelectionProps = ClassNameProps & {
editorRef: React.RefObject<Editor>;
};

export function WysiwygSelection({editorRef, className}: WysiwygSelectionProps) {
const rerender = useUpdate();
useEffectOnce(() => {
rerender();
});

const editor = editorRef.current;
const view = editor?.currentType === 'wysiwyg' && editor._wysiwygView;

React.useLayoutEffect(() => {
if (!editor) return undefined;
editor.on(
// @ts-expect-error TODO: add public event for selection change
'rerender-toolbar',
rerender,
);
editor.on('change-editor-type', rerender);
return () => {
editor.off(
// @ts-expect-error TODO: add public event for selection change
'rerender-toolbar',
rerender,
);
editor.off('change-editor-type', rerender);
};
}, [editor, rerender]);

if (!view) return null;

return <PMSelection view={view} className={className} />;
}

type PMSelectionProps = ClassNameProps & {
view: EditorView;
};

export function PMSelection({view, className}: PMSelectionProps) {
function PMSelection({view, className}: PMSelectionProps) {
const sel = view.state.selection;
const renderFromTo = () => (
<>
Expand Down
20 changes: 8 additions & 12 deletions demo/Playground.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,26 @@
@include text-header-2();
}

&__preview-type {
&__version {
position: absolute;
right: 0;
bottom: 0;
}

&__controls {
display: flex;
align-items: center;
column-gap: 8px;

& > p {
margin: 0;
}
@include text-code-inline-1();
}

&__markup {
overflow-y: auto;

margin: 0;
padding: 5px 10px;

background-color: var(--g-color-base-generic);
}

&__editor-view {
min-height: 100px;
min-height: 150px;
margin: 20px 0;
padding-left: 4px;
}

&__pm-selection {
Expand Down
30 changes: 27 additions & 3 deletions demo/Playground.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,49 @@
import React from 'react';

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

import {Playground as PlaygroundComponent, PlaygroundProps} from './Playground';
import {parseLocation} from './location';
import {initialMdContent} from './md-content';

export default {
title: 'YFM Editor',
component: PlaygroundComponent,
} as ComponentMeta<any>;

Check warning on line 13 in demo/Playground.stories.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type

type PlaygroundStoryProps = Pick<
PlaygroundProps,
'breaks' | 'allowHTML' | 'linkify' | 'linkifyTlds'
| 'initialEditor'
| 'settingsVisible'
| 'breaks'
| 'allowHTML'
| 'linkify'
| 'linkifyTlds'
| 'sanitizeHtml'
| 'prepareRawMarkup'
| 'splitModeOrientation'
| 'stickyToolbar'
| 'initialSplitModeEnabled'
| 'renderPreviewDefined'
| 'height'
>;
export const Playground: Story<PlaygroundStoryProps> = (props) => (
<PlaygroundComponent {...props} initial={initialMdContent} />
<PlaygroundComponent {...props} initial={parseLocation() || initialMdContent} />
);

Playground.args = {
initialEditor: 'wysiwyg',
settingsVisible: true,
allowHTML: true,
breaks: true,
linkify: true,
linkifyTlds: [],
sanitizeHtml: false,
prepareRawMarkup: false,
splitModeOrientation: 'horizontal',
stickyToolbar: true,
initialSplitModeEnabled: false,
renderPreviewDefined: true,
height: 'initial',
};
Loading

0 comments on commit 001da37

Please sign in to comment.