@gravity-ui/markdown-editor 13.17.1 → 13.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/build/cjs/bundle/config/action-names.d.ts +1 -1
- package/build/cjs/bundle/config/action-names.js +1 -0
- package/build/cjs/bundle/config/icons.d.ts +1 -1
- package/build/cjs/bundle/config/icons.js +3 -0
- package/build/cjs/bundle/config/wysiwyg.d.ts +1 -0
- package/build/cjs/bundle/config/wysiwyg.js +13 -1
- package/build/cjs/extensions/behavior/Clipboard/clipboard.js +4 -1
- package/build/cjs/extensions/markdown/Table/actions/innerActions.d.ts +1 -1
- package/build/cjs/extensions/yfm/GPT/ErrorScreen/ErrorScreen.css +18 -0
- package/build/cjs/extensions/yfm/GPT/ErrorScreen/ErrorScreen.d.ts +8 -0
- package/build/cjs/extensions/yfm/GPT/ErrorScreen/ErrorScreen.js +21 -0
- package/build/cjs/extensions/yfm/GPT/ErrorScreen/types.d.ts +14 -0
- package/build/cjs/extensions/yfm/GPT/ErrorScreen/types.js +2 -0
- package/build/cjs/extensions/yfm/GPT/GptDialog/GptDialog.css +75 -0
- package/build/cjs/extensions/yfm/GPT/GptDialog/GptDialog.d.ts +28 -0
- package/build/cjs/extensions/yfm/GPT/GptDialog/GptDialog.js +102 -0
- package/build/cjs/extensions/yfm/GPT/GptDialog/LoadingScreen/LoadingScreen.css +22 -0
- package/build/cjs/extensions/yfm/GPT/GptDialog/LoadingScreen/LoadingScreen.d.ts +3 -0
- package/build/cjs/extensions/yfm/GPT/GptDialog/LoadingScreen/LoadingScreen.js +21 -0
- package/build/cjs/extensions/yfm/GPT/IconRefuge/IconRefuge.classname.d.ts +1 -0
- package/build/cjs/extensions/yfm/GPT/IconRefuge/IconRefuge.classname.js +5 -0
- package/build/cjs/extensions/yfm/GPT/IconRefuge/IconRefuge.css +8 -0
- package/build/cjs/extensions/yfm/GPT/IconRefuge/IconRefuge.d.ts +14 -0
- package/build/cjs/extensions/yfm/GPT/IconRefuge/IconRefuge.js +28 -0
- package/build/cjs/extensions/yfm/GPT/IconRefuge/index.d.ts +2 -0
- package/build/cjs/extensions/yfm/GPT/IconRefuge/index.js +5 -0
- package/build/cjs/extensions/yfm/GPT/PresetList/PresetList.d.ts +9 -0
- package/build/cjs/extensions/yfm/GPT/PresetList/PresetList.js +29 -0
- package/build/cjs/extensions/yfm/GPT/PresetList/Presetlist.css +6 -0
- package/build/cjs/extensions/yfm/GPT/actions.d.ts +2 -0
- package/build/cjs/extensions/yfm/GPT/actions.js +14 -0
- package/build/cjs/extensions/yfm/GPT/commands.d.ts +2 -0
- package/build/cjs/extensions/yfm/GPT/commands.js +13 -0
- package/build/cjs/extensions/yfm/GPT/constants.d.ts +13 -0
- package/build/cjs/extensions/yfm/GPT/constants.js +15 -0
- package/build/cjs/extensions/yfm/GPT/gptExtension/gptExtension.d.ts +13 -0
- package/build/cjs/extensions/yfm/GPT/gptExtension/gptExtension.js +18 -0
- package/build/cjs/extensions/yfm/GPT/gptExtension/view.css +17 -0
- package/build/cjs/extensions/yfm/GPT/gptExtension/view.d.ts +36 -0
- package/build/cjs/extensions/yfm/GPT/gptExtension/view.js +167 -0
- package/build/cjs/extensions/yfm/GPT/hooks/useGpt.d.ts +27 -0
- package/build/cjs/extensions/yfm/GPT/hooks/useGpt.js +155 -0
- package/build/cjs/extensions/yfm/GPT/hooks/useGptHotKeys.d.ts +2 -0
- package/build/cjs/extensions/yfm/GPT/hooks/useGptHotKeys.js +8 -0
- package/build/cjs/extensions/yfm/GPT/hooks/useOverflowingHorizontalItems.d.ts +13 -0
- package/build/cjs/extensions/yfm/GPT/hooks/useOverflowingHorizontalItems.js +70 -0
- package/build/cjs/extensions/yfm/GPT/hooks/usePresetList.d.ts +14 -0
- package/build/cjs/extensions/yfm/GPT/hooks/usePresetList.js +36 -0
- package/build/cjs/extensions/yfm/GPT/index.d.ts +2 -0
- package/build/cjs/extensions/yfm/GPT/index.js +5 -0
- package/build/cjs/extensions/yfm/GPT/plugin.d.ts +13 -0
- package/build/cjs/extensions/yfm/GPT/plugin.js +47 -0
- package/build/cjs/extensions/yfm/GPT/toolbar.d.ts +3 -0
- package/build/cjs/extensions/yfm/GPT/toolbar.js +22 -0
- package/build/cjs/extensions/yfm/GPT/utils.d.ts +13 -0
- package/build/cjs/extensions/yfm/GPT/utils.js +31 -0
- package/build/cjs/extensions/yfm/YfmTable/plugins/YfmTableControls/actions.d.ts +1 -1
- package/build/cjs/extensions/yfm/YfmTable/plugins/YfmTableControls/actions.js +0 -8
- package/build/cjs/extensions/yfm/index.d.ts +1 -0
- package/build/cjs/extensions/yfm/index.js +1 -0
- package/build/cjs/i18n/gpt/dialog/en.json +16 -0
- package/build/cjs/i18n/gpt/dialog/index.d.ts +19 -0
- package/build/cjs/i18n/gpt/dialog/index.js +8 -0
- package/build/cjs/i18n/gpt/dialog/ru.json +16 -0
- package/build/cjs/i18n/gpt/errors/en.json +5 -0
- package/build/cjs/i18n/gpt/errors/index.d.ts +8 -0
- package/build/cjs/i18n/gpt/errors/index.js +8 -0
- package/build/cjs/i18n/gpt/errors/ru.json +5 -0
- package/build/cjs/i18n/gpt/extension/en.json +6 -0
- package/build/cjs/i18n/gpt/extension/index.d.ts +9 -0
- package/build/cjs/i18n/gpt/extension/index.js +8 -0
- package/build/cjs/i18n/gpt/extension/ru.json +6 -0
- package/build/cjs/i18n/gpt/loading/en.json +3 -0
- package/build/cjs/i18n/gpt/loading/index.d.ts +6 -0
- package/build/cjs/i18n/gpt/loading/index.js +8 -0
- package/build/cjs/i18n/gpt/loading/ru.json +3 -0
- package/build/cjs/i18n/menubar/en.json +1 -0
- package/build/cjs/i18n/menubar/index.d.ts +2 -1
- package/build/cjs/i18n/menubar/ru.json +1 -0
- package/build/cjs/icons/GPT.d.ts +2 -0
- package/build/cjs/icons/GPT.js +22 -0
- package/build/cjs/icons/GPTLoading.d.ts +2 -0
- package/build/cjs/icons/GPTLoading.js +12 -0
- package/build/cjs/icons/index.d.ts +3 -1
- package/build/cjs/icons/index.js +5 -1
- package/build/cjs/react-utils/useAutoFocus.d.ts +1 -1
- package/build/cjs/react-utils/useAutoFocus.js +2 -2
- package/build/cjs/react-utils/useNodeResizing.js +7 -2
- package/build/cjs/table-utils/commands/appendColumn.js +42 -33
- package/build/cjs/table-utils/commands/appendRow.js +40 -22
- package/build/cjs/table-utils/commands/removeColumn.js +18 -20
- package/build/cjs/table-utils/commands/removeRow.js +12 -9
- package/build/cjs/table-utils/table-desc.d.ts +53 -0
- package/build/cjs/table-utils/table-desc.js +149 -0
- package/build/cjs/table-utils/utils.d.ts +1 -1
- package/build/cjs/table-utils/utils.js +19 -12
- package/build/cjs/version.js +1 -1
- package/build/esm/bundle/config/action-names.d.ts +1 -1
- package/build/esm/bundle/config/action-names.js +1 -0
- package/build/esm/bundle/config/icons.d.ts +1 -1
- package/build/esm/bundle/config/icons.js +2 -0
- package/build/esm/bundle/config/wysiwyg.d.ts +1 -0
- package/build/esm/bundle/config/wysiwyg.js +12 -0
- package/build/esm/extensions/behavior/Clipboard/clipboard.js +4 -1
- package/build/esm/extensions/markdown/Table/actions/innerActions.d.ts +1 -1
- package/build/esm/extensions/yfm/GPT/ErrorScreen/ErrorScreen.css +18 -0
- package/build/esm/extensions/yfm/GPT/ErrorScreen/ErrorScreen.d.ts +9 -0
- package/build/esm/extensions/yfm/GPT/ErrorScreen/ErrorScreen.js +17 -0
- package/build/esm/extensions/yfm/GPT/ErrorScreen/types.d.ts +14 -0
- package/build/esm/extensions/yfm/GPT/ErrorScreen/types.js +1 -0
- package/build/esm/extensions/yfm/GPT/GptDialog/GptDialog.css +75 -0
- package/build/esm/extensions/yfm/GPT/GptDialog/GptDialog.d.ts +29 -0
- package/build/esm/extensions/yfm/GPT/GptDialog/GptDialog.js +98 -0
- package/build/esm/extensions/yfm/GPT/GptDialog/LoadingScreen/LoadingScreen.css +22 -0
- package/build/esm/extensions/yfm/GPT/GptDialog/LoadingScreen/LoadingScreen.d.ts +4 -0
- package/build/esm/extensions/yfm/GPT/GptDialog/LoadingScreen/LoadingScreen.js +17 -0
- package/build/esm/extensions/yfm/GPT/IconRefuge/IconRefuge.classname.d.ts +1 -0
- package/build/esm/extensions/yfm/GPT/IconRefuge/IconRefuge.classname.js +2 -0
- package/build/esm/extensions/yfm/GPT/IconRefuge/IconRefuge.css +8 -0
- package/build/esm/extensions/yfm/GPT/IconRefuge/IconRefuge.d.ts +15 -0
- package/build/esm/extensions/yfm/GPT/IconRefuge/IconRefuge.js +25 -0
- package/build/esm/extensions/yfm/GPT/IconRefuge/index.d.ts +2 -0
- package/build/esm/extensions/yfm/GPT/IconRefuge/index.js +1 -0
- package/build/esm/extensions/yfm/GPT/PresetList/PresetList.d.ts +10 -0
- package/build/esm/extensions/yfm/GPT/PresetList/PresetList.js +25 -0
- package/build/esm/extensions/yfm/GPT/PresetList/Presetlist.css +6 -0
- package/build/esm/extensions/yfm/GPT/actions.d.ts +2 -0
- package/build/esm/extensions/yfm/GPT/actions.js +10 -0
- package/build/esm/extensions/yfm/GPT/commands.d.ts +2 -0
- package/build/esm/extensions/yfm/GPT/commands.js +9 -0
- package/build/esm/extensions/yfm/GPT/constants.d.ts +13 -0
- package/build/esm/extensions/yfm/GPT/constants.js +12 -0
- package/build/esm/extensions/yfm/GPT/gptExtension/gptExtension.d.ts +13 -0
- package/build/esm/extensions/yfm/GPT/gptExtension/gptExtension.js +14 -0
- package/build/esm/extensions/yfm/GPT/gptExtension/view.css +17 -0
- package/build/esm/extensions/yfm/GPT/gptExtension/view.d.ts +37 -0
- package/build/esm/extensions/yfm/GPT/gptExtension/view.js +163 -0
- package/build/esm/extensions/yfm/GPT/hooks/useGpt.d.ts +27 -0
- package/build/esm/extensions/yfm/GPT/hooks/useGpt.js +151 -0
- package/build/esm/extensions/yfm/GPT/hooks/useGptHotKeys.d.ts +2 -0
- package/build/esm/extensions/yfm/GPT/hooks/useGptHotKeys.js +4 -0
- package/build/esm/extensions/yfm/GPT/hooks/useOverflowingHorizontalItems.d.ts +13 -0
- package/build/esm/extensions/yfm/GPT/hooks/useOverflowingHorizontalItems.js +65 -0
- package/build/esm/extensions/yfm/GPT/hooks/usePresetList.d.ts +14 -0
- package/build/esm/extensions/yfm/GPT/hooks/usePresetList.js +32 -0
- package/build/esm/extensions/yfm/GPT/index.d.ts +2 -0
- package/build/esm/extensions/yfm/GPT/index.js +2 -0
- package/build/esm/extensions/yfm/GPT/plugin.d.ts +13 -0
- package/build/esm/extensions/yfm/GPT/plugin.js +43 -0
- package/build/esm/extensions/yfm/GPT/toolbar.d.ts +3 -0
- package/build/esm/extensions/yfm/GPT/toolbar.js +18 -0
- package/build/esm/extensions/yfm/GPT/utils.d.ts +13 -0
- package/build/esm/extensions/yfm/GPT/utils.js +23 -0
- package/build/esm/extensions/yfm/YfmTable/plugins/YfmTableControls/actions.d.ts +1 -1
- package/build/esm/extensions/yfm/YfmTable/plugins/YfmTableControls/actions.js +1 -9
- package/build/esm/extensions/yfm/index.d.ts +1 -0
- package/build/esm/extensions/yfm/index.js +1 -0
- package/build/esm/i18n/gpt/dialog/en.json +16 -0
- package/build/esm/i18n/gpt/dialog/index.d.ts +19 -0
- package/build/esm/i18n/gpt/dialog/index.js +4 -0
- package/build/esm/i18n/gpt/dialog/ru.json +16 -0
- package/build/esm/i18n/gpt/errors/en.json +5 -0
- package/build/esm/i18n/gpt/errors/index.d.ts +8 -0
- package/build/esm/i18n/gpt/errors/index.js +4 -0
- package/build/esm/i18n/gpt/errors/ru.json +5 -0
- package/build/esm/i18n/gpt/extension/en.json +6 -0
- package/build/esm/i18n/gpt/extension/index.d.ts +9 -0
- package/build/esm/i18n/gpt/extension/index.js +4 -0
- package/build/esm/i18n/gpt/extension/ru.json +6 -0
- package/build/esm/i18n/gpt/loading/en.json +3 -0
- package/build/esm/i18n/gpt/loading/index.d.ts +6 -0
- package/build/esm/i18n/gpt/loading/index.js +4 -0
- package/build/esm/i18n/gpt/loading/ru.json +3 -0
- package/build/esm/i18n/menubar/en.json +1 -0
- package/build/esm/i18n/menubar/index.d.ts +2 -1
- package/build/esm/i18n/menubar/ru.json +1 -0
- package/build/esm/icons/GPT.d.ts +2 -0
- package/build/esm/icons/GPT.js +19 -0
- package/build/esm/icons/GPTLoading.d.ts +2 -0
- package/build/esm/icons/GPTLoading.js +9 -0
- package/build/esm/icons/index.d.ts +3 -1
- package/build/esm/icons/index.js +3 -1
- package/build/esm/react-utils/useAutoFocus.d.ts +1 -1
- package/build/esm/react-utils/useAutoFocus.js +2 -2
- package/build/esm/react-utils/useNodeResizing.js +7 -2
- package/build/esm/table-utils/commands/appendColumn.js +44 -35
- package/build/esm/table-utils/commands/appendRow.js +42 -24
- package/build/esm/table-utils/commands/removeColumn.js +18 -20
- package/build/esm/table-utils/commands/removeRow.js +14 -11
- package/build/esm/table-utils/table-desc.d.ts +53 -0
- package/build/esm/table-utils/table-desc.js +144 -0
- package/build/esm/table-utils/utils.d.ts +1 -1
- package/build/esm/table-utils/utils.js +18 -12
- package/build/esm/version.js +1 -1
- package/build/styles.css +146 -0
- package/package.json +2 -1
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import { Popup } from '@gravity-ui/uikit';
|
|
3
|
+
import { Slice } from 'prosemirror-model';
|
|
4
|
+
import { TextSelection } from 'prosemirror-state';
|
|
5
|
+
import { useMount } from 'react-use';
|
|
6
|
+
import { cn } from '../../../../classname';
|
|
7
|
+
import { getReactRendererFromState } from '../../../behavior';
|
|
8
|
+
import { GptDialog } from '../GptDialog/GptDialog';
|
|
9
|
+
import { WIDGET_DECO_CLASS_NAME, WIDGET_DECO_SPEC_FLAG, gptPopupPlacement } from '../constants';
|
|
10
|
+
import { pluginKey } from '../plugin';
|
|
11
|
+
import './view.css';
|
|
12
|
+
export const cnGptPopup = cn('gpt-popup');
|
|
13
|
+
export class GptWidgetDecoView {
|
|
14
|
+
constructor(view, params) {
|
|
15
|
+
this._decoElem = null;
|
|
16
|
+
this._onConfirmCancel = () => {
|
|
17
|
+
this._confirmOpen = false;
|
|
18
|
+
this._renderer.rerender();
|
|
19
|
+
};
|
|
20
|
+
this._onConfirmOk = () => {
|
|
21
|
+
this._onClose();
|
|
22
|
+
};
|
|
23
|
+
this._onGptAnswerUpdate = (answer) => {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
(_b = (_a = this._params).onUpdate) === null || _b === void 0 ? void 0 : _b.call(_a, answer);
|
|
26
|
+
};
|
|
27
|
+
this._onSubmit = (answer) => {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
const deco = this._getCurrentDecoration();
|
|
30
|
+
if (!deco)
|
|
31
|
+
return;
|
|
32
|
+
const { from, to } = deco;
|
|
33
|
+
const answerNode = this._parser.parse(answer);
|
|
34
|
+
const tr = this._view.state.tr;
|
|
35
|
+
const meta = { action: 'hide' };
|
|
36
|
+
tr.setMeta(pluginKey, meta);
|
|
37
|
+
tr.replace(from, to, new Slice(answerNode.content, 1, 1));
|
|
38
|
+
tr.setSelection(TextSelection.create(tr.doc, tr.mapping.map(to)));
|
|
39
|
+
this._view.dispatch(tr);
|
|
40
|
+
setTimeout(() => {
|
|
41
|
+
this._view.focus();
|
|
42
|
+
}, 0);
|
|
43
|
+
(_b = (_a = this._params).onApplyResult) === null || _b === void 0 ? void 0 : _b.call(_a, answer);
|
|
44
|
+
this._resetState();
|
|
45
|
+
};
|
|
46
|
+
this._onClose = () => {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
const deco = this._getCurrentDecoration();
|
|
49
|
+
if (!deco) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const tr = this._view.state.tr;
|
|
53
|
+
const meta = { action: 'hide' };
|
|
54
|
+
tr.setSelection(TextSelection.create(tr.doc, deco.from, deco.to));
|
|
55
|
+
tr.setMeta(pluginKey, meta);
|
|
56
|
+
this._view.dispatch(tr);
|
|
57
|
+
setTimeout(() => {
|
|
58
|
+
this._view.focus();
|
|
59
|
+
}, 0);
|
|
60
|
+
(_b = (_a = this._params).onClose) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
61
|
+
this._resetState();
|
|
62
|
+
};
|
|
63
|
+
this._view = view;
|
|
64
|
+
this._params = params;
|
|
65
|
+
this._serializer = params.serializer;
|
|
66
|
+
this._parser = params.parser;
|
|
67
|
+
this._confirmOpen = false;
|
|
68
|
+
this._renderer = getReactRendererFromState(view.state).createItem('gpt-widget-view', this._render.bind(this));
|
|
69
|
+
}
|
|
70
|
+
update(view, prevState) {
|
|
71
|
+
var _a;
|
|
72
|
+
const { state, dispatch } = view;
|
|
73
|
+
if (this._decoElem && !state.selection.eq(prevState.selection)) {
|
|
74
|
+
const transaction = state.tr;
|
|
75
|
+
const meta = { action: 'hide' };
|
|
76
|
+
dispatch(transaction.setMeta(pluginKey, meta));
|
|
77
|
+
this._view.focus();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const decoElements = Array.from(view.dom.querySelectorAll(`.${WIDGET_DECO_CLASS_NAME}`));
|
|
81
|
+
this._decoElem = (_a = decoElements.at(-1)) !== null && _a !== void 0 ? _a : null;
|
|
82
|
+
this._renderer.rerender();
|
|
83
|
+
}
|
|
84
|
+
destroy() {
|
|
85
|
+
this._resetState();
|
|
86
|
+
this._renderer.remove();
|
|
87
|
+
}
|
|
88
|
+
_resetState() {
|
|
89
|
+
this._decoElem = null;
|
|
90
|
+
this._confirmOpen = false;
|
|
91
|
+
}
|
|
92
|
+
_render() {
|
|
93
|
+
if (!this._decoElem)
|
|
94
|
+
return null;
|
|
95
|
+
const markup = this._getContentOfDecoration();
|
|
96
|
+
if (markup === undefined) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
return (React.createElement(Widget, { markup: markup, anchorRef: { current: this._decoElem }, answerRender: this._params.answerRender, promptPresets: this._params.promptPresets, disablePromptPresets: this._params.disablePromptPresets, customPromptPlaceholder: this._params.customPromptPlaceholder, disabledPromptPlaceholder: this._params.disabledPromptPlaceholder, gptAlertProps: this._params.gptAlertProps,
|
|
100
|
+
/* eslint-disable-next-line react/jsx-handler-names */
|
|
101
|
+
onApplyResult: this._onSubmit,
|
|
102
|
+
/* eslint-disable-next-line react/jsx-handler-names */
|
|
103
|
+
onCustomPromptApply: this._params.onCustomPromptApply,
|
|
104
|
+
/* eslint-disable-next-line react/jsx-handler-names */
|
|
105
|
+
onPromptPresetClick: this._params.onPromptPresetClick,
|
|
106
|
+
/* eslint-disable-next-line react/jsx-handler-names */
|
|
107
|
+
onTryAgain: this._params.onTryAgain,
|
|
108
|
+
/* eslint-disable-next-line react/jsx-handler-names */
|
|
109
|
+
onLike: this._params.onLike,
|
|
110
|
+
/* eslint-disable-next-line react/jsx-handler-names */
|
|
111
|
+
onDislike: this._params.onDislike,
|
|
112
|
+
/* eslint-disable-next-line react/jsx-handler-names */
|
|
113
|
+
onClose: this._onClose,
|
|
114
|
+
/* eslint-disable-next-line react/jsx-handler-names */
|
|
115
|
+
onUpdate: this._onGptAnswerUpdate,
|
|
116
|
+
/* eslint-disable-next-line react/jsx-handler-names */
|
|
117
|
+
confirmOpen: this._confirmOpen,
|
|
118
|
+
/* eslint-disable-next-line react/jsx-handler-names */
|
|
119
|
+
onConfirmOk: this._onConfirmOk,
|
|
120
|
+
/* eslint-disable-next-line react/jsx-handler-names */
|
|
121
|
+
onConfirmCancel: this._onConfirmCancel, container: this._params.gptPopupContainer }));
|
|
122
|
+
}
|
|
123
|
+
_getContentOfDecoration() {
|
|
124
|
+
const deco = this._getCurrentDecoration();
|
|
125
|
+
if (!deco)
|
|
126
|
+
return undefined;
|
|
127
|
+
const { from, to } = deco;
|
|
128
|
+
try {
|
|
129
|
+
const fragment = this._view.state.doc.slice(from, to, true).content;
|
|
130
|
+
const yfmMarkup = this._serializer.serialize(fragment);
|
|
131
|
+
return yfmMarkup;
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
console.error(error);
|
|
135
|
+
return this._view.state.doc.textBetween(from, to, '\n', '');
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
_getCurrentDecoration() {
|
|
139
|
+
var _a;
|
|
140
|
+
return (_a = this._getPluginState()) === null || _a === void 0 ? void 0 : _a.find(undefined, undefined,
|
|
141
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return
|
|
142
|
+
(spec) => spec[WIDGET_DECO_SPEC_FLAG])[0];
|
|
143
|
+
}
|
|
144
|
+
_getPluginState() {
|
|
145
|
+
return pluginKey.getState(this._view.state);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function Widget({ markup, anchorRef, answerRender, promptPresets, disablePromptPresets, customPromptPlaceholder, disabledPromptPlaceholder, onCustomPromptApply, onApplyResult, onPromptPresetClick, onTryAgain, onLike, onDislike, onClose, onUpdate, container, gptAlertProps, }) {
|
|
149
|
+
useMount(() => {
|
|
150
|
+
if ((anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current) && 'scrollIntoView' in anchorRef.current) {
|
|
151
|
+
anchorRef.current.scrollIntoView({
|
|
152
|
+
behavior: 'smooth',
|
|
153
|
+
block: 'center',
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
const handleUpdate = useCallback((result) => {
|
|
158
|
+
onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate(result);
|
|
159
|
+
}, [onUpdate]);
|
|
160
|
+
return (React.createElement(React.Fragment, null,
|
|
161
|
+
React.createElement(Popup, { className: cnGptPopup(), contentClassName: cnGptPopup('content'), open: true, anchorRef: anchorRef, placement: gptPopupPlacement, onOutsideClick: onClose, focusTrap: true, autoFocus: !onCustomPromptApply && true, strategy: "absolute", container: container, onEscapeKeyDown: onClose },
|
|
162
|
+
React.createElement(GptDialog, { markup: markup, answerRender: answerRender, promptPresets: promptPresets, disablePromptPresets: disablePromptPresets, customPromptPlaceholder: customPromptPlaceholder, disabledPromptPlaceholder: disabledPromptPlaceholder, onApplyResult: onApplyResult, onCustomPromptApply: onCustomPromptApply, onPromptPresetClick: onPromptPresetClick, onTryAgain: onTryAgain, onLike: onLike, onDislike: onDislike, onClose: onClose, onUpdate: handleUpdate, gptAlertProps: gptAlertProps }))));
|
|
163
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CommonAnswer, GptRequestData } from '../ErrorScreen/types';
|
|
2
|
+
import type { GptDialogProps } from '../GptDialog/GptDialog';
|
|
3
|
+
declare type UseGptProps<AnswerData extends CommonAnswer = CommonAnswer, PromptData extends unknown = unknown> = Pick<GptDialogProps<AnswerData, PromptData>, 'markup' | 'promptPresets' | 'onCustomPromptApply' | 'onPromptPresetClick' | 'onTryAgain' | 'onLike' | 'onDislike' | 'onApplyResult' | 'onUpdate'>;
|
|
4
|
+
export declare const useGpt: <AnswerData extends CommonAnswer = CommonAnswer, PromptData extends unknown = unknown>({ markup, promptPresets, onCustomPromptApply, onPromptPresetClick, onTryAgain, onLike, onDislike, onApplyResult, onUpdate, }: UseGptProps<AnswerData, PromptData>) => {
|
|
5
|
+
answer: AnswerData | undefined;
|
|
6
|
+
customPrompt: string;
|
|
7
|
+
lastRequestData: GptRequestData<PromptData> | undefined;
|
|
8
|
+
loading: boolean;
|
|
9
|
+
error: boolean;
|
|
10
|
+
mode: "custom-and-presets" | "only-custom" | "only-presets";
|
|
11
|
+
feedbackType: "dislike" | "like" | undefined;
|
|
12
|
+
feedbackTypeLoading: "dislike" | "like" | undefined;
|
|
13
|
+
handleLike: () => Promise<void>;
|
|
14
|
+
handleDislike: () => Promise<void>;
|
|
15
|
+
handleCustomPromptUpdate: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
16
|
+
handleCustomPromptKeyPress: import("react").KeyboardEventHandler<HTMLInputElement>;
|
|
17
|
+
handleCustomPromptApply: () => Promise<void>;
|
|
18
|
+
handlePresetClick: (data: PromptData) => void;
|
|
19
|
+
handleTryAgain: () => Promise<void>;
|
|
20
|
+
handleFreshStart: () => void;
|
|
21
|
+
handleApplyResult: () => void;
|
|
22
|
+
showTryAgainButton: boolean;
|
|
23
|
+
showAnswer: boolean;
|
|
24
|
+
showError: boolean;
|
|
25
|
+
showAnswerActions: boolean | undefined;
|
|
26
|
+
};
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
|
+
import { isEnter } from '../utils';
|
|
3
|
+
export const useGpt = ({ markup, promptPresets, onCustomPromptApply, onPromptPresetClick, onTryAgain, onLike, onDislike, onApplyResult, onUpdate, }) => {
|
|
4
|
+
const [answer, setAnswer] = useState();
|
|
5
|
+
const [lastRequestData, setLastRequestData] = useState();
|
|
6
|
+
const [customPrompt, setCustomPrompt] = useState('');
|
|
7
|
+
const [loading, setLoading] = useState(false);
|
|
8
|
+
const [error, setError] = useState(false);
|
|
9
|
+
const [feedbackType, setFeedbackType] = useState(undefined);
|
|
10
|
+
const [feedbackTypeLoading, setFeedbackTypeLoading] = useState(undefined);
|
|
11
|
+
const makeRequest = useCallback(async (requestFunction, data) => {
|
|
12
|
+
if (!requestFunction) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
let result;
|
|
16
|
+
try {
|
|
17
|
+
setLoading(true);
|
|
18
|
+
setError(false);
|
|
19
|
+
setLastRequestData(data);
|
|
20
|
+
result = await requestFunction(data);
|
|
21
|
+
if (result) {
|
|
22
|
+
setAnswer(result);
|
|
23
|
+
setFeedbackType(undefined);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
console.error(error);
|
|
28
|
+
setError(true);
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
setLoading(false);
|
|
32
|
+
setTimeout(() => {
|
|
33
|
+
// hack for popup rerender
|
|
34
|
+
// When a lot of text is entered into the GPT popup,
|
|
35
|
+
// it expands and goes beyond the boundaries. However,
|
|
36
|
+
// the popup does not handle height changes.
|
|
37
|
+
window.dispatchEvent(new CustomEvent('scroll'));
|
|
38
|
+
});
|
|
39
|
+
onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate(result);
|
|
40
|
+
}
|
|
41
|
+
}, [onUpdate]);
|
|
42
|
+
const handleLike = useCallback(async () => {
|
|
43
|
+
if (!onLike || !lastRequestData) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
setFeedbackType(undefined);
|
|
48
|
+
setFeedbackTypeLoading('like');
|
|
49
|
+
await onLike(lastRequestData);
|
|
50
|
+
setFeedbackType('like');
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
console.error(error);
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
setFeedbackTypeLoading(undefined);
|
|
57
|
+
}
|
|
58
|
+
}, [lastRequestData, onLike]);
|
|
59
|
+
const handleDislike = useCallback(async () => {
|
|
60
|
+
if (!onDislike || !lastRequestData) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
setFeedbackType(undefined);
|
|
65
|
+
setFeedbackTypeLoading('dislike');
|
|
66
|
+
await onDislike(lastRequestData);
|
|
67
|
+
setFeedbackType('dislike');
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.error(error);
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
setFeedbackTypeLoading(undefined);
|
|
74
|
+
}
|
|
75
|
+
}, [lastRequestData, onDislike]);
|
|
76
|
+
const handleCustomPromptApply = useCallback(async () => {
|
|
77
|
+
if (!customPrompt) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const gptRequestData = {
|
|
81
|
+
markup,
|
|
82
|
+
customPrompt,
|
|
83
|
+
};
|
|
84
|
+
await makeRequest(onCustomPromptApply, gptRequestData);
|
|
85
|
+
}, [customPrompt, makeRequest, markup, onCustomPromptApply]);
|
|
86
|
+
const handleCustomPromptKeyPress = useCallback(async (event) => {
|
|
87
|
+
if (!isEnter(event)) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
await handleCustomPromptApply();
|
|
91
|
+
}, [handleCustomPromptApply]);
|
|
92
|
+
const handlePresetClick = useCallback(async (data) => {
|
|
93
|
+
const gptRequestData = {
|
|
94
|
+
markup,
|
|
95
|
+
promptData: data,
|
|
96
|
+
};
|
|
97
|
+
await makeRequest(onPromptPresetClick, gptRequestData);
|
|
98
|
+
}, [makeRequest, markup, onPromptPresetClick]);
|
|
99
|
+
const handleTryAgain = useCallback(async () => {
|
|
100
|
+
if (!lastRequestData) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
await makeRequest(onTryAgain, lastRequestData);
|
|
104
|
+
}, [lastRequestData, makeRequest, onTryAgain]);
|
|
105
|
+
const handleApplyResult = useCallback(() => {
|
|
106
|
+
var _a;
|
|
107
|
+
onApplyResult((_a = answer === null || answer === void 0 ? void 0 : answer.rawText) !== null && _a !== void 0 ? _a : '');
|
|
108
|
+
}, [answer === null || answer === void 0 ? void 0 : answer.rawText, onApplyResult]);
|
|
109
|
+
const handleFreshStart = useCallback(() => {
|
|
110
|
+
setError(false);
|
|
111
|
+
setLastRequestData(undefined);
|
|
112
|
+
setAnswer(undefined);
|
|
113
|
+
setCustomPrompt('');
|
|
114
|
+
setFeedbackType(undefined);
|
|
115
|
+
onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate(undefined);
|
|
116
|
+
}, [onUpdate]);
|
|
117
|
+
const showTryAgainButton = Boolean(lastRequestData && onTryAgain && !loading);
|
|
118
|
+
const showAnswer = Boolean(answer && !loading && !error);
|
|
119
|
+
const showError = error && !loading;
|
|
120
|
+
const showAnswerActions = (onLike || onDislike) && showAnswer;
|
|
121
|
+
let mode = 'custom-and-presets';
|
|
122
|
+
if (onCustomPromptApply && !(promptPresets === null || promptPresets === void 0 ? void 0 : promptPresets.length)) {
|
|
123
|
+
mode = 'only-custom';
|
|
124
|
+
}
|
|
125
|
+
else if (!onCustomPromptApply && (promptPresets === null || promptPresets === void 0 ? void 0 : promptPresets.length)) {
|
|
126
|
+
mode = 'only-presets';
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
answer,
|
|
130
|
+
customPrompt,
|
|
131
|
+
lastRequestData,
|
|
132
|
+
loading,
|
|
133
|
+
error,
|
|
134
|
+
mode,
|
|
135
|
+
feedbackType,
|
|
136
|
+
feedbackTypeLoading,
|
|
137
|
+
handleLike,
|
|
138
|
+
handleDislike,
|
|
139
|
+
handleCustomPromptUpdate: setCustomPrompt,
|
|
140
|
+
handleCustomPromptKeyPress,
|
|
141
|
+
handleCustomPromptApply,
|
|
142
|
+
handlePresetClick,
|
|
143
|
+
handleTryAgain,
|
|
144
|
+
handleFreshStart,
|
|
145
|
+
handleApplyResult,
|
|
146
|
+
showTryAgainButton,
|
|
147
|
+
showAnswer,
|
|
148
|
+
showError,
|
|
149
|
+
showAnswerActions,
|
|
150
|
+
};
|
|
151
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { RefObject } from 'react';
|
|
2
|
+
export declare type UseOverflowingContainerListItemsProps<ItemType extends unknown> = {
|
|
3
|
+
containerRef: RefObject<HTMLElement>;
|
|
4
|
+
items?: ItemType[];
|
|
5
|
+
itemSelector: string;
|
|
6
|
+
moreButtonSelector: string;
|
|
7
|
+
marginBetweenItems?: number;
|
|
8
|
+
};
|
|
9
|
+
export declare function useOverflowingHorizontalItems<ItemType>({ containerRef, items, itemSelector, moreButtonSelector, marginBetweenItems, }: UseOverflowingContainerListItemsProps<ItemType>): {
|
|
10
|
+
visibleItems: ItemType[];
|
|
11
|
+
hiddenItems: ItemType[];
|
|
12
|
+
measured: boolean;
|
|
13
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { useLayoutEffect, useMemo, useState } from 'react';
|
|
2
|
+
import debounceFn from 'lodash/debounce';
|
|
3
|
+
export function useOverflowingHorizontalItems({ containerRef, items, itemSelector, moreButtonSelector, marginBetweenItems = 0, }) {
|
|
4
|
+
const [containerWidth, setContainerWidth] = useState(0);
|
|
5
|
+
const [itemWidths, setItemWidths] = useState([]);
|
|
6
|
+
const [moreButtonWidth, setMoreButtonWidth] = useState(0);
|
|
7
|
+
useLayoutEffect(() => {
|
|
8
|
+
const measureItemSizes = () => {
|
|
9
|
+
var _a, _b, _c;
|
|
10
|
+
const itemElements = Array.from((_b = (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.querySelectorAll(itemSelector)) !== null && _b !== void 0 ? _b : []);
|
|
11
|
+
const moreButton = (_c = containerRef.current) === null || _c === void 0 ? void 0 : _c.querySelector(moreButtonSelector);
|
|
12
|
+
setItemWidths(itemElements.map((item) => item.clientWidth));
|
|
13
|
+
if (moreButton) {
|
|
14
|
+
setMoreButtonWidth(moreButton.clientWidth);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
requestAnimationFrame(measureItemSizes);
|
|
18
|
+
}, [containerRef, itemSelector, moreButtonSelector]);
|
|
19
|
+
useLayoutEffect(() => {
|
|
20
|
+
const container = containerRef.current;
|
|
21
|
+
if (!container) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const updateContainerSize = (entries) => {
|
|
25
|
+
if (entries.length > 0) {
|
|
26
|
+
setContainerWidth(entries[0].contentRect.width);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const updateContainerSizeDebounced = debounceFn(updateContainerSize, 100);
|
|
30
|
+
const containerResizeObserver = new ResizeObserver(updateContainerSizeDebounced);
|
|
31
|
+
containerResizeObserver.observe(container);
|
|
32
|
+
return () => containerResizeObserver.unobserve(container);
|
|
33
|
+
}, [containerRef]);
|
|
34
|
+
const isMeasured = itemWidths.length > 0;
|
|
35
|
+
const { visibleItems, hiddenItems } = useMemo(() => {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
if (!isMeasured) {
|
|
38
|
+
return {
|
|
39
|
+
visibleItems: items !== null && items !== void 0 ? items : [],
|
|
40
|
+
hiddenItems: [],
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const itemsCount = itemWidths.length;
|
|
44
|
+
let visibleItemsCount = 0;
|
|
45
|
+
const spaceForMoreButton = moreButtonWidth + marginBetweenItems;
|
|
46
|
+
let remainingContainerWidth = containerWidth;
|
|
47
|
+
for (const width of itemWidths) {
|
|
48
|
+
const itemWidthWithMargin = width + marginBetweenItems;
|
|
49
|
+
remainingContainerWidth -= itemWidthWithMargin;
|
|
50
|
+
if (remainingContainerWidth < spaceForMoreButton) {
|
|
51
|
+
const isMoreThanOneItemLeft = itemsCount !== visibleItemsCount + 1;
|
|
52
|
+
const hasNoSpaceForTheLastItem = remainingContainerWidth < 0;
|
|
53
|
+
if (isMoreThanOneItemLeft || hasNoSpaceForTheLastItem) {
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
visibleItemsCount++;
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
visibleItems: (_a = items === null || items === void 0 ? void 0 : items.slice(0, visibleItemsCount)) !== null && _a !== void 0 ? _a : [],
|
|
61
|
+
hiddenItems: (_b = items === null || items === void 0 ? void 0 : items.slice(visibleItemsCount)) !== null && _b !== void 0 ? _b : [],
|
|
62
|
+
};
|
|
63
|
+
}, [containerWidth, isMeasured, itemWidths, items, marginBetweenItems, moreButtonWidth]);
|
|
64
|
+
return { visibleItems, hiddenItems, measured: isMeasured };
|
|
65
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DropdownMenuItem } from '@gravity-ui/uikit';
|
|
2
|
+
import type { GptDialogProps } from '../GptDialog/GptDialog';
|
|
3
|
+
import type { PresetListProps } from '../PresetList/PresetList';
|
|
4
|
+
declare type UsePresetListProps = Pick<GptDialogProps, 'promptPresets'> & {
|
|
5
|
+
onPresetClick: PresetListProps['onPresetClick'];
|
|
6
|
+
};
|
|
7
|
+
export declare const usePresetList: ({ promptPresets, onPresetClick }: UsePresetListProps) => {
|
|
8
|
+
measured: boolean;
|
|
9
|
+
showMoreButton: boolean;
|
|
10
|
+
presetsContainerRef: import("react").RefObject<HTMLDivElement>;
|
|
11
|
+
visiblePresets: import("../ErrorScreen/types").PromptPreset<unknown>[];
|
|
12
|
+
hiddenPresets: DropdownMenuItem<unknown>[];
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useMemo, useRef } from 'react';
|
|
2
|
+
import { cnGptDialogPresetList } from '../PresetList/PresetList';
|
|
3
|
+
import { useOverflowingHorizontalItems } from './useOverflowingHorizontalItems';
|
|
4
|
+
export const usePresetList = ({ promptPresets, onPresetClick }) => {
|
|
5
|
+
const presetsContainerRef = useRef(null);
|
|
6
|
+
const { visibleItems, hiddenItems, measured } = useOverflowingHorizontalItems({
|
|
7
|
+
containerRef: presetsContainerRef,
|
|
8
|
+
items: promptPresets,
|
|
9
|
+
itemSelector: `.${cnGptDialogPresetList('preset')}`,
|
|
10
|
+
moreButtonSelector: `.${cnGptDialogPresetList('more-button-wrapper')}`,
|
|
11
|
+
marginBetweenItems: 8,
|
|
12
|
+
});
|
|
13
|
+
const hiddenPresets = useMemo(() => {
|
|
14
|
+
const items = [];
|
|
15
|
+
for (const item of hiddenItems) {
|
|
16
|
+
items.push({
|
|
17
|
+
text: item.display,
|
|
18
|
+
action: () => onPresetClick(item.data),
|
|
19
|
+
items: [],
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return items;
|
|
23
|
+
}, [onPresetClick, hiddenItems]);
|
|
24
|
+
const showMoreButton = !measured || hiddenPresets.length > 0;
|
|
25
|
+
return {
|
|
26
|
+
measured,
|
|
27
|
+
showMoreButton,
|
|
28
|
+
presetsContainerRef,
|
|
29
|
+
visiblePresets: visibleItems,
|
|
30
|
+
hiddenPresets,
|
|
31
|
+
};
|
|
32
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
2
|
+
import { DecorationSet } from 'prosemirror-view';
|
|
3
|
+
import type { GptWidgetDecoViewParams } from './gptExtension/view';
|
|
4
|
+
export declare type GptWidgetMeta = {
|
|
5
|
+
action: 'show';
|
|
6
|
+
from: number;
|
|
7
|
+
to: number;
|
|
8
|
+
} | {
|
|
9
|
+
action: 'hide';
|
|
10
|
+
};
|
|
11
|
+
declare const key: PluginKey<DecorationSet>;
|
|
12
|
+
export { key as pluginKey };
|
|
13
|
+
export declare const gptWidgetPlugin: (params: GptWidgetDecoViewParams) => Plugin;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
2
|
+
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
3
|
+
import { WIDGET_DECO_CLASS_NAME, WIDGET_DECO_SPEC_FLAG } from './constants';
|
|
4
|
+
import { GptWidgetDecoView } from './gptExtension/view';
|
|
5
|
+
const key = new PluginKey('gpt-widget');
|
|
6
|
+
export { key as pluginKey };
|
|
7
|
+
export const gptWidgetPlugin = (params) => {
|
|
8
|
+
return new Plugin({
|
|
9
|
+
key,
|
|
10
|
+
state: {
|
|
11
|
+
init: () => DecorationSet.empty,
|
|
12
|
+
apply: (tr, decos) => {
|
|
13
|
+
const meta = tr.getMeta(key);
|
|
14
|
+
const paramsGpt = params;
|
|
15
|
+
if ((meta === null || meta === void 0 ? void 0 : meta.action) === 'show') {
|
|
16
|
+
if (meta.to === meta.from) {
|
|
17
|
+
const spanElem = document.createElement('span');
|
|
18
|
+
spanElem.className = WIDGET_DECO_CLASS_NAME;
|
|
19
|
+
spanElem.textContent = ' ';
|
|
20
|
+
paramsGpt.disablePromptPresets = true;
|
|
21
|
+
return DecorationSet.create(tr.doc, [
|
|
22
|
+
Decoration.widget(meta.from, spanElem, {
|
|
23
|
+
[WIDGET_DECO_SPEC_FLAG]: true,
|
|
24
|
+
}),
|
|
25
|
+
]);
|
|
26
|
+
}
|
|
27
|
+
return DecorationSet.create(tr.doc, [
|
|
28
|
+
Decoration.inline(meta.from, meta.to, { nodeName: 'span', class: WIDGET_DECO_CLASS_NAME }, { [WIDGET_DECO_SPEC_FLAG]: true }),
|
|
29
|
+
]);
|
|
30
|
+
}
|
|
31
|
+
if ((meta === null || meta === void 0 ? void 0 : meta.action) === 'hide') {
|
|
32
|
+
paramsGpt.disablePromptPresets = false;
|
|
33
|
+
return DecorationSet.empty;
|
|
34
|
+
}
|
|
35
|
+
return decos.map(tr.mapping, tr.doc);
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
props: {
|
|
39
|
+
decorations: (state) => key.getState(state),
|
|
40
|
+
},
|
|
41
|
+
view: (view) => new GptWidgetDecoView(view, params),
|
|
42
|
+
});
|
|
43
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { cn } from '@bem-react/classname';
|
|
2
|
+
import { i18n } from '../../../i18n/gpt/extension';
|
|
3
|
+
import gptIcon from '../../../icons/GPT';
|
|
4
|
+
import { ToolbarDataType } from '../../../toolbar';
|
|
5
|
+
import { gptHotKeys } from './constants';
|
|
6
|
+
export const cnGptButton = cn('gpt-button');
|
|
7
|
+
export const wGptToolbarItem = {
|
|
8
|
+
type: ToolbarDataType.SingleButton,
|
|
9
|
+
id: 'gpt',
|
|
10
|
+
title: () => `${i18n('help-with-text')}`,
|
|
11
|
+
hotkey: gptHotKeys.openGptKeyTooltip,
|
|
12
|
+
icon: { data: gptIcon },
|
|
13
|
+
disabledPopoverVisible: false,
|
|
14
|
+
exec: (actionsStorage) => actionsStorage.actions.addGptWidget.run({}),
|
|
15
|
+
isActive: (actionsStorage) => actionsStorage.actions.addGptWidget.isActive(),
|
|
16
|
+
isEnable: (actionsStorage) => actionsStorage.actions.addGptWidget.isEnable(),
|
|
17
|
+
className: cnGptButton(),
|
|
18
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { GptDialogProps } from './GptDialog/GptDialog';
|
|
3
|
+
declare type CombinedKeyboardEvent = KeyboardEvent | React.KeyboardEvent;
|
|
4
|
+
export declare function getAlertGptInfo(gptAlert: GptDialogProps['gptAlertProps']): {
|
|
5
|
+
alertMessage: string;
|
|
6
|
+
alertTheme: import("@gravity-ui/uikit/build/esm/components/Alert/types").AlertTheme;
|
|
7
|
+
alertClassName: string | undefined;
|
|
8
|
+
};
|
|
9
|
+
export declare function getDisableReplaceButtonText(disablePromptPresets?: boolean): string;
|
|
10
|
+
export declare function getInputPlaceHolder(disablePromptPresets?: boolean, disabledPromptPlaceholder?: string, customPromptPlaceholder?: string): string | undefined;
|
|
11
|
+
export declare const isEnter: (event: CombinedKeyboardEvent) => boolean;
|
|
12
|
+
export declare function focusWithoutScroll(element?: HTMLElement | null): void;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { i18n } from '../../../i18n/gpt/dialog';
|
|
2
|
+
export function getAlertGptInfo(gptAlert) {
|
|
3
|
+
return {
|
|
4
|
+
alertMessage: (gptAlert === null || gptAlert === void 0 ? void 0 : gptAlert.message) || i18n('alert-gpt-presets-info'),
|
|
5
|
+
alertTheme: (gptAlert === null || gptAlert === void 0 ? void 0 : gptAlert.theme) || 'info',
|
|
6
|
+
alertClassName: gptAlert === null || gptAlert === void 0 ? void 0 : gptAlert.className,
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export function getDisableReplaceButtonText(disablePromptPresets) {
|
|
10
|
+
return disablePromptPresets ? i18n(`replace-disabled`) : i18n(`replace`);
|
|
11
|
+
}
|
|
12
|
+
export function getInputPlaceHolder(disablePromptPresets, disabledPromptPlaceholder, customPromptPlaceholder) {
|
|
13
|
+
return disablePromptPresets ? disabledPromptPlaceholder : customPromptPlaceholder;
|
|
14
|
+
}
|
|
15
|
+
export const isEnter = (event) => event.code === 'Enter' || event.code === 'NumpadEnter';
|
|
16
|
+
export function focusWithoutScroll(element) {
|
|
17
|
+
const x = window.scrollX;
|
|
18
|
+
const y = window.scrollY;
|
|
19
|
+
element === null || element === void 0 ? void 0 : element.focus({
|
|
20
|
+
preventScroll: true,
|
|
21
|
+
});
|
|
22
|
+
window.scrollTo(x, y);
|
|
23
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const controlActions: Record<"deleteTable" | "
|
|
1
|
+
export declare const controlActions: Record<"deleteTable" | "deleteRow" | "deleteColumn" | "appendColumn" | "appendRow", import("../../../../../core").ActionSpec>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { appendColumn, appendRow, removeColumn, removeRow } from '../../../../../table-utils';
|
|
2
2
|
import { defineActions } from '../../../../../utils/actions';
|
|
3
3
|
import { removeNode } from '../../../../../utils/remove-node';
|
|
4
4
|
import { tableControlsPluginKey } from './buttons';
|
|
@@ -20,18 +20,10 @@ const removeYfmTable = (state, dispatch, _, attrs) => {
|
|
|
20
20
|
return true;
|
|
21
21
|
};
|
|
22
22
|
export const controlActions = defineActions({
|
|
23
|
-
addRow: {
|
|
24
|
-
isEnable: addRowAfter,
|
|
25
|
-
run: addRowAfter,
|
|
26
|
-
},
|
|
27
23
|
deleteRow: {
|
|
28
24
|
isEnable: removeRow,
|
|
29
25
|
run: removeRow,
|
|
30
26
|
},
|
|
31
|
-
addColumn: {
|
|
32
|
-
isEnable: addColumnAfter,
|
|
33
|
-
run: addColumnAfter,
|
|
34
|
-
},
|
|
35
27
|
deleteColumn: {
|
|
36
28
|
isEnable: removeColumn,
|
|
37
29
|
run: removeColumn,
|