Skip to content

Commit

Permalink
feat(toolbars): fixed types
Browse files Browse the repository at this point in the history
  • Loading branch information
makhnatkin committed Dec 19, 2024
1 parent 0acc23b commit e29ff33
Show file tree
Hide file tree
Showing 7 changed files with 422 additions and 73 deletions.
4 changes: 2 additions & 2 deletions src/bundle/MarkdownEditorView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {useEnsuredForwardedRef, useKey, useUpdate} from 'react-use';
import {ClassNameProps, cn} from '../classname';
import {i18n} from '../i18n/bundle';
import {logger} from '../logger';
import {ToolbarsPresetOrEditorPreset} from '../modules/toolbars/types';
import type {ToolbarsPreset} from '../modules/toolbars/types';
import {ToasterContext, useBooleanState, useSticky} from '../react-utils';
import {isMac} from '../utils';

Expand All @@ -32,7 +32,7 @@ const b = cnEditorComponent;
export type MarkdownEditorViewProps = ClassNameProps & {
editor?: Editor;
autofocus?: boolean;
toolbarsPreset?: ToolbarsPresetOrEditorPreset;
toolbarsPreset?: ToolbarsPreset;
/**
* @deprecated use `toolbarsPreset` instead
*/
Expand Down
207 changes: 207 additions & 0 deletions src/bundle/config/markup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import {
import {MToolbarColors} from '../toolbar/markup/MToolbarColors';
import {MToolbarFilePopup} from '../toolbar/markup/MToolbarFilePopup';
import {MToolbarImagePopup} from '../toolbar/markup/MToolbarImagePopup';
import type {MarkdownEditorPreset} from '../types';

import {ActionName} from './action-names';
import {icons} from './icons';
Expand Down Expand Up @@ -544,3 +545,209 @@ export const mToolbarConfig: MToolbarData = [
],
[mImagePopupData, mFilePopupData, mTableButton, mCheckboxButton],
];

export const mToolbarConfigByPreset: Record<MarkdownEditorPreset, MToolbarData> = {
zero: [mHistoryGroupConfig],
commonmark: [
[mUndoItemData, mRedoItemData],
[mBoldItemData, mItalicItemData],
[
{
id: 'heading',
type: ToolbarDataType.ListButton,
icon: icons.headline,
withArrow: true,
title: i18n.bind(null, 'heading'),
data: [
mHeading1ItemData,
mHeading2ItemData,
mHeading3ItemData,
mHeading4ItemData,
mHeading5ItemData,
mHeading6ItemData,
],
},
{
id: 'list',
type: ToolbarDataType.ListButton,
icon: icons.bulletList,
withArrow: true,
title: i18n.bind(null, 'list'),
data: [mBulletListItemData, mOrderedListItemData],
},
mLinkButton,
mQuoteButton,
{
id: 'code',
type: ToolbarDataType.ListButton,
icon: icons.code,
withArrow: true,
title: i18n.bind(null, 'code'),
data: [mCodeItemData, mCodeblockItemData],
},
],
],
default: [
[mUndoItemData, mRedoItemData],
[mBoldItemData, mItalicItemData, mStrikethroughItemData],
[
{
id: 'heading',
type: ToolbarDataType.ListButton,
icon: icons.headline,
withArrow: true,
title: i18n.bind(null, 'heading'),
data: [
mHeading1ItemData,
mHeading2ItemData,
mHeading3ItemData,
mHeading4ItemData,
mHeading5ItemData,
mHeading6ItemData,
],
},
{
id: 'list',
type: ToolbarDataType.ListButton,
icon: icons.bulletList,
withArrow: true,
title: i18n.bind(null, 'list'),
data: [mBulletListItemData, mOrderedListItemData],
},
mLinkButton,
mQuoteButton,
{
id: 'code',
type: ToolbarDataType.ListButton,
icon: icons.code,
withArrow: true,
title: i18n.bind(null, 'code'),
data: [mCodeItemData, mCodeblockItemData],
},
],
],
yfm: [
[mUndoItemData, mRedoItemData],
[
mBoldItemData,
mItalicItemData,
mUnderlineItemData,
mStrikethroughItemData,
mMonospaceItemData,
],
[
{
id: 'heading',
type: ToolbarDataType.ListButton,
icon: icons.headline,
withArrow: true,
title: i18n.bind(null, 'heading'),
data: [
mHeading1ItemData,
mHeading2ItemData,
mHeading3ItemData,
mHeading4ItemData,
mHeading5ItemData,
mHeading6ItemData,
],
},
{
id: 'list',
type: ToolbarDataType.ListButton,
icon: icons.bulletList,
withArrow: true,
title: i18n.bind(null, 'list'),
data: [mBulletListItemData, mOrderedListItemData],
},
mLinkButton,
mNoteButton,
mCutButton,
mQuoteButton,
{
id: 'code',
type: ToolbarDataType.ListButton,
icon: icons.code,
withArrow: true,
title: i18n.bind(null, 'code'),
data: [mCodeItemData, mCodeblockItemData],
},
],
[mImagePopupData, mFilePopupData, mTableButton, mCheckboxButton],
],
full: mToolbarConfig.slice(),
};

export const mHiddenDataByPreset: Record<MarkdownEditorPreset, MToolbarItemData[]> = {
zero: [],
commonmark: [
mHeading1ItemData,
mHeading2ItemData,
mHeading3ItemData,
mHeading4ItemData,
mHeading5ItemData,
mHeading6ItemData,
mBulletListItemData,
mOrderedListItemData,
mLinkButton,
mQuoteButton,
mCodeblockItemData,
mHruleItemData,
],
default: [
mHeading1ItemData,
mHeading2ItemData,
mHeading3ItemData,
mHeading4ItemData,
mHeading5ItemData,
mHeading6ItemData,
mBulletListItemData,
mOrderedListItemData,
mLinkButton,
mQuoteButton,
mCodeblockItemData,
mHruleItemData,
],
yfm: [
mHeading1ItemData,
mHeading2ItemData,
mHeading3ItemData,
mHeading4ItemData,
mHeading5ItemData,
mHeading6ItemData,
mBulletListItemData,
mOrderedListItemData,
mLinkButton,
mQuoteButton,
mNoteButton,
mCutButton,
mCodeblockItemData,
mCheckboxButton,
mTableButton,
mImagePopupData,
mHruleItemData,
mFilePopupData,
mTabsItemData,
],
full: [
mHeading1ItemData,
mHeading2ItemData,
mHeading3ItemData,
mHeading4ItemData,
mHeading5ItemData,
mHeading6ItemData,
mBulletListItemData,
mOrderedListItemData,
mLinkButton,
mQuoteButton,
mNoteButton,
mCutButton,
mCodeblockItemData,
mCheckboxButton,
mTableButton,
mImagePopupData,
mHruleItemData,
mEmojiItemData,
mFilePopupData,
mTabsItemData,
],
};
Loading

0 comments on commit e29ff33

Please sign in to comment.