Skip to content

Commit

Permalink
Merge branch 'main' into add-empty-row-placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
PMAWorks authored Dec 17, 2024
2 parents e70b7cb + 4355519 commit 88d0c49
Show file tree
Hide file tree
Showing 21 changed files with 207 additions and 123 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Changelog

## [14.6.0](https://github.com/gravity-ui/markdown-editor/compare/v14.5.1...v14.6.0) (2024-12-10)


### Features

* **bundle:** update view of text color action item in toolbar ([#514](https://github.com/gravity-ui/markdown-editor/issues/514)) ([54ac0d3](https://github.com/gravity-ui/markdown-editor/commit/54ac0d36499e572844e42cfff8f7781387731b00))


### Bug Fixes

* **Cursor:** input-rules does not work when cursor in virtual selection (GapCursorSelection) ([#515](https://github.com/gravity-ui/markdown-editor/issues/515)) ([9126756](https://github.com/gravity-ui/markdown-editor/commit/9126756fe5e241c6ab2badec4689b1df8f0009c3))
* **deps:** bumped @lezer/markdown to fix large text hang ([#512](https://github.com/gravity-ui/markdown-editor/issues/512)) ([8a8fce8](https://github.com/gravity-ui/markdown-editor/commit/8a8fce8ff5f9603f6e755264fc474c03a36d6bb7))
* Gpt extension render ([#519](https://github.com/gravity-ui/markdown-editor/issues/519)) ([89c9881](https://github.com/gravity-ui/markdown-editor/commit/89c9881331df2b0fae5968258a29b9c9eed179ef))

## [14.5.1](https://github.com/gravity-ui/markdown-editor/compare/v14.5.0...v14.5.1) (2024-12-02)


### Bug Fixes

* **Checkbox:** correct handling of checkbox click ([#510](https://github.com/gravity-ui/markdown-editor/issues/510)) ([c214076](https://github.com/gravity-ui/markdown-editor/commit/c2140766a32f9820498345d4eab907fcb803c9fc))

## [14.5.0](https://github.com/gravity-ui/markdown-editor/compare/v14.4.0...v14.5.0) (2024-11-28)


Expand Down
15 changes: 6 additions & 9 deletions demo/stories/gpt/GPT.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import React, {useState} from 'react';
import cloneDeep from 'lodash/cloneDeep';

import {
type MarkupString,
gptExtension,
logger,
mGptExtension,
mGptToolbarItem,
markupToolbarConfigs,
wGptToolbarItem,
wGptItemData,
wysiwygToolbarConfigs,
} from '../../../src';
import {Playground} from '../../components/Playground';
Expand All @@ -18,7 +17,7 @@ import {initialMdContent} from './content';
import {gptWidgetProps} from './gptWidgetOptions';

const wToolbarConfig = cloneDeep(wysiwygToolbarConfigs.wToolbarConfig);
wToolbarConfig.unshift([wGptToolbarItem]);
wToolbarConfig.unshift([wGptItemData]);
wToolbarConfig.push([
wysiwygToolbarConfigs.wMermaidItemData,
wysiwygToolbarConfigs.wYfmHtmlBlockItemData,
Expand All @@ -37,7 +36,7 @@ const wCommandMenuConfig = wysiwygToolbarConfigs.wCommandMenuConfig.concat(
wysiwygToolbarConfigs.wYfmHtmlBlockItemData,
);

wCommandMenuConfig.unshift(wysiwygToolbarConfigs.wGptItemData);
wCommandMenuConfig.unshift(wGptItemData);

const mToolbarConfig = cloneDeep(markupToolbarConfigs.mToolbarConfig);

Expand All @@ -49,24 +48,22 @@ mToolbarConfig.push([
mToolbarConfig.unshift([mGptToolbarItem]);

export const GPT = React.memo(() => {
const [yfmRaw, setYfmRaw] = React.useState<MarkupString>(initialMdContent);

const [showedAlertGpt, setShowedAlertGpt] = useState(true);

const gptExtensionProps = gptWidgetProps(setYfmRaw, {
const gptExtensionProps = gptWidgetProps({
showedGptAlert: Boolean(showedAlertGpt),
onCloseGptAlert: () => {
setShowedAlertGpt(false);
},
});

const markupExtension = mGptExtension(gptExtensionProps);
const wSelectionMenuConfig = [[wGptToolbarItem], ...wysiwygToolbarConfigs.wSelectionMenuConfig];
const wSelectionMenuConfig = [[wGptItemData], ...wysiwygToolbarConfigs.wSelectionMenuConfig];

return (
<Playground
settingsVisible
initial={yfmRaw}
initial={initialMdContent}
extraExtensions={(builder) => builder.use(gptExtension, gptExtensionProps)}
wysiwygCommandMenuConfig={wCommandMenuConfig}
extensionOptions={{selectionContext: {config: wSelectionMenuConfig}}}
Expand Down
7 changes: 2 additions & 5 deletions demo/stories/gpt/gptWidgetOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const gptRequestHandler = async ({
};

export const gptWidgetProps = (
setYfmRaw: (yfmRaw: string) => void,
gptAlertProps?: GptWidgetOptions['gptAlertProps'],
): GptWidgetOptions => {
return {
Expand Down Expand Up @@ -64,12 +63,10 @@ export const gptWidgetProps = (
onLike: async () => {},
onDislike: async () => {},
onApplyResult: (markup) => {
setYfmRaw(markup);
console.log('onApplyResult:', markup);
},
onUpdate: (event) => {
if (event?.rawText) {
setYfmRaw(event.rawText);
}
console.log('update:', event);
},
};
};
15 changes: 7 additions & 8 deletions docs/how-to-connect-gpt-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Add in tool bar
```ts
import {
...
wGptToolbarItem,
wGptItemData,
wysiwygToolbarConfigs,
} from '@gravity-ui/markdown-editor';

Expand All @@ -160,7 +160,7 @@ import {cloneDeep} from '@gravity-ui/markdown-editor/_/lodash';
export const Editor: React.FC<EditorProps> = (props) => {
...
const wToolbarConfig = cloneDeep(wysiwygToolbarConfigs.wToolbarConfig);
wToolbarConfig.unshift([wGptToolbarItem]);
wToolbarConfig.unshift([wGptItemData]);

...

Expand All @@ -176,7 +176,7 @@ Add in menu bar
```ts
export const Editor: React.FC<EditorProps> = (props) => {
...
const wSelectionMenuConfig = [[wGptToolbarItem], ...wysiwygToolbarConfigs.wSelectionMenuConfig];
const wSelectionMenuConfig = [[wGptItemData], ...wysiwygToolbarConfigs.wSelectionMenuConfig];

const mdEditor = useMarkdownEditor({
...
Expand All @@ -195,7 +195,7 @@ Add in command menu config (/)
export const Editor: React.FC<EditorProps> = (props) => {
...
const wCommandMenuConfig = wysiwygToolbarConfigs.wCommandMenuConfig // main commands
wCommandMenuConfig.unshift(wysiwygToolbarConfigs.wGptItemData); // add GPT command
wCommandMenuConfig.unshift(wGptItemData); // add GPT command

const mdEditor = useMarkdownEditor({
...
Expand All @@ -217,7 +217,6 @@ import React from 'react';
import {
gptExtension,
MarkdownEditorView,
wGptToolbarItem,
wysiwygToolbarConfigs,
useMarkdownEditor,
} from '@gravity-ui/markdown-editor';
Expand All @@ -227,12 +226,12 @@ import {gptWidgetProps} from './gptWidgetProps';

export const Editor: React.FC<EditorProps> = (props) => {
const wToolbarConfig = cloneDeep(wysiwygToolbarConfigs.wToolbarConfig);
wToolbarConfig.unshift([wGptToolbarItem]);
wToolbarConfig.unshift([wGptItemData]);

const wSelectionMenuConfig = [[wGptToolbarItem], ...wysiwygToolbarConfigs.wSelectionMenuConfig];
const wSelectionMenuConfig = [[wGptItemData], ...wysiwygToolbarConfigs.wSelectionMenuConfig];

const wCommandMenuConfig = wysiwygToolbarConfigs.wCommandMenuConfig // main commands
wCommandMenuConfig.unshift(wysiwygToolbarConfigs.wGptItemData); // add GPT command
wCommandMenuConfig.unshift(wGptItemData); // add GPT command

const mdEditor = useMarkdownEditor({
// ...
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gravity-ui/markdown-editor",
"version": "14.5.0",
"version": "14.6.0",
"description": "Markdown wysiwyg and markup editor",
"license": "MIT",
"repository": {
Expand Down Expand Up @@ -170,7 +170,7 @@
"@gravity-ui/i18n": "^1.1.0",
"@gravity-ui/icons": "^2.10.0",
"@lezer/highlight": "~1.2.1",
"@lezer/markdown": "~1.3.1",
"@lezer/markdown": "~1.3.2",
"@types/is-number": "^7.0.1",
"@types/markdown-it": "^12.2.3",
"base64-arraybuffer": "1.0.2",
Expand Down Expand Up @@ -300,8 +300,8 @@
"lodash": "^4.17.20",
"lowlight": "^3.0.0",
"markdown-it": "^13.0.0",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
},
"lint-staged": {
"*.{css,scss}": [
Expand Down
12 changes: 1 addition & 11 deletions src/bundle/config/wysiwyg.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {ActionStorage} from 'src/core';

import {headingType, pType} from '../../extensions';
import {gptHotKeys} from '../../extensions/additional/GPT/constants';
// for typings from Math
import type {} from '../../extensions/additional/Math';
import type {
Expand Down Expand Up @@ -244,16 +243,7 @@ export const wYfmHtmlBlockItemData: WToolbarSingleItemData = {
isActive: (e) => e.actions.createYfmHtmlBlock.isActive(),
isEnable: (e) => e.actions.createYfmHtmlBlock.isEnable(),
};
export const wGptItemData: WToolbarSingleItemData = {
id: ActionName.gpt,
type: ToolbarDataType.SingleButton,
title: i18n.bind(null, 'gpt'),
hotkey: gptHotKeys.openGptKeyTooltip,
icon: icons.gpt,
exec: (e) => e.actions.addGptWidget.run({}),
isActive: (e) => e.actions.addGptWidget.isActive(),
isEnable: (e) => e.actions.addGptWidget.isEnable(),
};

export const wMermaidItemData: WToolbarSingleItemData = {
id: ActionName.mermaid,
type: ToolbarDataType.SingleButton,
Expand Down
25 changes: 20 additions & 5 deletions src/bundle/toolbar/ToolbarButtonWithPopupMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ export type MenuItem = {
export type ToolbarButtonWithPopupMenuProps = Omit<
ToolbarBaseProps<ActionStorage> & {
icon: ToolbarIconData;
iconClassName?: string;
chevronIconClassName?: string;
title: string | (() => string);
menuItems: MenuItem[];
/** @default 'classic' */
_selectionType?: 'classic' | 'light';
},
'editor'
>;
Expand All @@ -37,8 +41,11 @@ export const ToolbarButtonWithPopupMenu: React.FC<ToolbarButtonWithPopupMenuProp
focus,
onClick,
icon,
iconClassName,
chevronIconClassName,
title,
menuItems,
_selectionType,
}) => {
const buttonRef = React.useRef<HTMLButtonElement>(null);
const [open, , hide, toggleOpen] = useBooleanState(false);
Expand All @@ -48,7 +55,7 @@ export const ToolbarButtonWithPopupMenu: React.FC<ToolbarButtonWithPopupMenuProp
menuItems.map((i) => ({...i, group: i.group || ''})),
'group',
),
[menuItems, groupBy],
[menuItems],
);

const someActive = menuItems.some(
Expand All @@ -64,6 +71,14 @@ export const ToolbarButtonWithPopupMenu: React.FC<ToolbarButtonWithPopupMenuProp
}
}, [hide, shouldForceHide]);

const [btnView, btnSelected] =
_selectionType === 'light'
? ([
popupOpen ? 'normal' : someActive ? 'flat-action' : 'flat',
popupOpen && someActive,
] as const)
: ([someActive || popupOpen ? 'normal' : 'flat', someActive] as const);

return (
<>
<ActionTooltip
Expand All @@ -75,15 +90,15 @@ export const ToolbarButtonWithPopupMenu: React.FC<ToolbarButtonWithPopupMenuProp
<Button
size="m"
ref={buttonRef}
view={someActive || popupOpen ? 'normal' : 'flat'}
selected={someActive}
view={btnView}
selected={btnSelected}
disabled={everyDisabled}
className={b(null, [className])}
onClick={toggleOpen}
>
<Icon data={icon.data} size={icon.size} />
<Icon data={icon.data} size={icon.size} className={iconClassName} />
{''}
<Icon data={ChevronDown} />
<Icon data={ChevronDown} className={chevronIconClassName} />
</Button>
</ActionTooltip>
<Popup anchorRef={buttonRef} open={popupOpen} onClose={hide}>
Expand Down
9 changes: 9 additions & 0 deletions src/bundle/toolbar/custom/ToolbarColors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@ $colors: ('gray', 'yellow', 'orange', 'red', 'green', 'blue', 'violet');

.g-md-toolbar-colors {
@each $name in $colors {
&__menu-icon_color_#{$name} {
color: var(--yfm-colorify-#{$name});
}

&__chevron-icon_color_#{$name} {
color: var(--yfm-colorify-#{$name});
}

&__item-icon_color_#{$name} {
color: var(--yfm-colorify-#{$name});
}
}

&__item-icon_color_default {
color: var(--g-color-text-primary);
}
Expand Down
3 changes: 3 additions & 0 deletions src/bundle/toolbar/custom/ToolbarColors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ export const ToolbarColors: React.FC<ToolbarColorsProps> = (props) => {
title={i18n('colorify')}
menuItems={items}
icon={textColorIcon}
_selectionType="light"
iconClassName={b('menu-icon', {color: currentColor})}
chevronIconClassName={b('chevron-icon', {color: currentColor})}
/>
);
};
2 changes: 1 addition & 1 deletion src/extensions/additional/GPT/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './toolbar';
export * from './wGptItemData';
export * from './gptExtension/gptExtension';
export * from './MarkupGpt';
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {gptHotKeys} from './constants';

export const cnGptButton = cn('gpt-button');

export const wGptToolbarItem: WToolbarSingleItemData = {
export const wGptItemData: WToolbarSingleItemData = {
type: ToolbarDataType.SingleButton,
id: 'gpt',
title: () => `${i18n('help-with-text')}`,
Expand Down
Loading

0 comments on commit 88d0c49

Please sign in to comment.