Skip to content

Commit e4b6647

Browse files
authored
Merge branch 'main' into feat-up-tabs
2 parents 354b94a + 7784598 commit e4b6647

File tree

20 files changed

+148
-53
lines changed

20 files changed

+148
-53
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## [13.25.1](https://github.com/gravity-ui/markdown-editor/compare/v13.25.0...v13.25.1) (2024-10-18)
4+
5+
6+
### Bug Fixes
7+
8+
* generics in GPT ([#425](https://github.com/gravity-ui/markdown-editor/issues/425)) ([e24aa27](https://github.com/gravity-ui/markdown-editor/commit/e24aa274c15edfb8a0d6ee3e10282ceeb098bbad))
9+
* **yfmCut:** reverted details, summary tags ([#431](https://github.com/gravity-ui/markdown-editor/issues/431)) ([8be5211](https://github.com/gravity-ui/markdown-editor/commit/8be5211001bd3023bd9fb9472239466b9a8199d0))
10+
311
## [13.25.0](https://github.com/gravity-ui/markdown-editor/compare/v13.24.0...v13.25.0) (2024-10-15)
412

513

demo/YFM.stories.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ This is an alert.
5454
Content displayed when clicked.
5555
5656
{% endcut %}
57+
58+
{% cut "Cut with nested сut header" %}
59+
60+
{% cut "Cut header" %}
61+
62+
Content displayed when clicked.
63+
64+
{% endcut %}
65+
66+
{% endcut %}
67+
5768
`.trim(),
5869

5970
yfmTabs: `

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gravity-ui/markdown-editor",
3-
"version": "13.25.0",
3+
"version": "13.25.1",
44
"description": "Markdown wysiwyg and markup editor",
55
"license": "MIT",
66
"repository": {

src/extensions/additional/GPT/GptDialog/GptDialog.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type {FC} from 'react';
21
import React, {useCallback, useRef, useState} from 'react';
32

43
import {ArrowRight, ArrowRotateLeft, ThumbsDown, ThumbsUp} from '@gravity-ui/icons';
@@ -50,7 +49,10 @@ export type GptDialogProps<
5049

5150
export const cnGptDialog = cn('gpt-dialog');
5251

53-
export const GptDialog: FC<GptDialogProps> = ({
52+
export const GptDialog = <
53+
AnswerData extends CommonAnswer = CommonAnswer,
54+
PromptData extends unknown = unknown,
55+
>({
5456
markup,
5557
answerRender,
5658
promptPresets,
@@ -66,7 +68,7 @@ export const GptDialog: FC<GptDialogProps> = ({
6668
onDislike,
6769
onUpdate,
6870
gptAlertProps,
69-
}) => {
71+
}: GptDialogProps<AnswerData, PromptData>) => {
7072
const {
7173
answer,
7274
customPrompt,

src/extensions/additional/GPT/MarkupGpt/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {keymap} from '@codemirror/view';
22

33
import {GptWidgetOptions} from '../../..';
4+
import {CommonAnswer} from '../ErrorScreen/types';
45
import {gptHotKeys} from '../constants';
56

67
import {runMarkupGpt} from './commands';
@@ -9,7 +10,10 @@ import {mGptPlugin} from './plugin';
910
export {mGptToolbarItem} from './toolbar';
1011
export {showMarkupGpt, hideMarkupGpt} from './commands';
1112

12-
export function mGptExtension(props: GptWidgetOptions) {
13+
export function mGptExtension<
14+
AnswerData extends CommonAnswer = CommonAnswer,
15+
PromptData extends unknown = unknown,
16+
>(props: GptWidgetOptions<AnswerData, PromptData>) {
1317
return [
1418
mGptPlugin(props).extension,
1519
keymap.of([

src/extensions/additional/GPT/MarkupGpt/plugin.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
type ViewUpdate,
1111
} from '../../../../cm/view';
1212
import {ReactRendererFacet} from '../../../../markup';
13+
import {CommonAnswer} from '../ErrorScreen/types';
1314
import {WIDGET_DECO_CLASS_NAME} from '../constants';
1415
import {isEmptyGptPrompts} from '../utils';
1516

@@ -35,7 +36,10 @@ class SpanWidget extends WidgetType {
3536
}
3637
}
3738

38-
export function mGptPlugin(gptProps: GptWidgetOptions) {
39+
export function mGptPlugin<
40+
AnswerData extends CommonAnswer = CommonAnswer,
41+
PromptData extends unknown = unknown,
42+
>(gptProps: GptWidgetOptions<AnswerData, PromptData>) {
3943
return ViewPlugin.fromClass(
4044
class implements PluginValue {
4145
readonly _view: EditorView;

src/extensions/additional/GPT/MarkupGpt/popup.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ import {CommonAnswer} from '../ErrorScreen/types';
66
import {GptDialog, GptDialogProps} from '../GptDialog/GptDialog';
77
import {cnGptPopup} from '../gptExtension/view';
88

9-
type Props = {
9+
type Props<AnswerData extends CommonAnswer = CommonAnswer, PromptData extends unknown = unknown> = {
1010
onClose: () => void;
1111
markup: string;
1212
onConfirmOk?: () => void;
1313
onConfirmCancel?: () => void;
14-
} & GptDialogProps &
14+
} & GptDialogProps<AnswerData, PromptData> &
1515
Pick<PopupProps, 'anchorRef' | 'container'>;
1616

17-
export function renderPopup(anchor: HTMLElement, props: Props) {
18-
const handleUpdate = (result?: CommonAnswer) => props.onUpdate?.(result);
17+
export function renderPopup<
18+
AnswerData extends CommonAnswer = CommonAnswer,
19+
PromptData extends unknown = unknown,
20+
>(anchor: HTMLElement, props: Props<AnswerData, PromptData>) {
21+
const handleUpdate = (result?: AnswerData) => props.onUpdate?.(result);
1922

2023
return (
2124
<Popup

src/extensions/additional/GPT/PresetList/PresetList.tsx

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,47 @@
11
import React from 'react';
2-
import type {FC} from 'react';
32

43
import {ActionTooltip, Button, DropdownMenu} from '@gravity-ui/uikit';
54

65
import {cn} from '../../../../classname';
76
import {i18n} from '../../../../i18n/gpt/dialog';
8-
import {type PromptPreset} from '../ErrorScreen/types';
7+
import {CommonAnswer, type PromptPreset} from '../ErrorScreen/types';
98
import type {GptDialogProps} from '../GptDialog/GptDialog';
109
import {gptHotKeys} from '../constants';
1110
import {useGptHotKeys} from '../hooks/useGptHotKeys';
1211
import {usePresetList} from '../hooks/usePresetList';
1312

1413
import './Presetlist.scss';
1514

16-
export type PresetListProps<PromptData extends unknown = unknown> = {
17-
disablePromptPresets: GptDialogProps['disablePromptPresets'];
18-
promptPresets: GptDialogProps['promptPresets'];
19-
onPresetClick: (data: PromptData) => void;
15+
export type PresetListProps<
16+
AnswerData extends CommonAnswer = CommonAnswer,
17+
PromptData extends unknown = unknown,
18+
> = {
19+
disablePromptPresets: GptDialogProps<AnswerData, PromptData>['disablePromptPresets'];
20+
promptPresets: GptDialogProps<AnswerData, PromptData>['promptPresets'];
21+
onPresetClick: (data?: PromptData) => void;
2022
};
2123

22-
type PresetItemType = {
23-
preset: PromptPreset<unknown>;
24-
onPresetClick: PresetListProps['onPresetClick'];
24+
type PresetItemType<
25+
AnswerData extends CommonAnswer = CommonAnswer,
26+
PromptData extends unknown = unknown,
27+
> = {
28+
preset: PromptPreset<PromptData>;
29+
onPresetClick: PresetListProps<AnswerData, PromptData>['onPresetClick'];
2530
disablePromptPresets?: PresetListProps['disablePromptPresets'];
2631
hotKey: string;
2732
};
2833

2934
export const cnGptDialogPresetList = cn('gpt-dialog-preset-list');
3035

31-
const PresetItem: FC<PresetItemType> = ({preset, onPresetClick, disablePromptPresets, hotKey}) => {
36+
const PresetItem = <
37+
AnswerData extends CommonAnswer = CommonAnswer,
38+
PromptData extends unknown = unknown,
39+
>({
40+
preset,
41+
onPresetClick,
42+
disablePromptPresets,
43+
hotKey,
44+
}: PresetItemType<AnswerData, PromptData>) => {
3245
useGptHotKeys(
3346
hotKey,
3447
() => {
@@ -52,13 +65,16 @@ const PresetItem: FC<PresetItemType> = ({preset, onPresetClick, disablePromptPre
5265
);
5366
};
5467

55-
export const PresetList: FC<PresetListProps> = ({
68+
export const PresetList = <
69+
AnswerData extends CommonAnswer = CommonAnswer,
70+
PromptData extends unknown = unknown,
71+
>({
5672
disablePromptPresets,
5773
promptPresets,
5874
onPresetClick,
59-
}) => {
75+
}: PresetListProps<AnswerData, PromptData>) => {
6076
const {presetsContainerRef, visiblePresets, hiddenPresets, showMoreButton, measured} =
61-
usePresetList({
77+
usePresetList<AnswerData, PromptData>({
6278
promptPresets,
6379
onPresetClick,
6480
});

src/extensions/additional/GPT/gptExtension/gptExtension.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import {Action, ExtensionWithOptions} from 'src/core';
2-
1+
import {Action, ExtensionBuilder} from '../../../../core';
32
import type {CommonAnswer} from '../ErrorScreen/types';
43
import {showGptWidget} from '../actions';
54
import {runGpt} from '../commands';
@@ -31,7 +30,13 @@ export type GptWidgetOptions<
3130
| 'gptAlertProps'
3231
>;
3332

34-
export const gptExtension: ExtensionWithOptions<GptWidgetOptions> = (builder, options) => {
33+
export const gptExtension = <
34+
AnswerData extends CommonAnswer = CommonAnswer,
35+
PromptData extends unknown = unknown,
36+
>(
37+
builder: ExtensionBuilder,
38+
options: GptWidgetOptions<AnswerData, PromptData>,
39+
) => {
3540
builder.addAction(gptActionName, showGptWidget);
3641
builder.addPlugin(({serializer, markupParser}) => {
3742
return gptWidgetPlugin({

0 commit comments

Comments
 (0)