@gravity-ui/markdown-editor 13.23.0 → 13.25.0
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 +2 -0
- package/build/cjs/bundle/MarkdownEditorView.css +1 -0
- package/build/cjs/bundle/MarkdownEditorView.d.ts +4 -0
- package/build/cjs/bundle/MarkdownEditorView.js +28 -16
- package/build/cjs/bundle/config/action-names.d.ts +1 -1
- package/build/cjs/bundle/config/wysiwyg.js +1 -2
- package/build/cjs/bundle/settings/index.d.ts +1 -0
- package/build/cjs/bundle/settings/index.js +7 -6
- package/build/cjs/extensions/additional/GPT/MarkupGpt/commands.d.ts +4 -0
- package/build/cjs/extensions/additional/GPT/MarkupGpt/commands.js +18 -0
- package/build/cjs/extensions/additional/GPT/MarkupGpt/effects.d.ts +2 -0
- package/build/cjs/extensions/additional/GPT/MarkupGpt/effects.js +6 -0
- package/build/cjs/extensions/additional/GPT/MarkupGpt/index.d.ts +4 -0
- package/build/cjs/extensions/additional/GPT/MarkupGpt/index.js +24 -0
- package/build/cjs/extensions/additional/GPT/MarkupGpt/plugin.d.ts +22 -0
- package/build/cjs/extensions/additional/GPT/MarkupGpt/plugin.js +121 -0
- package/build/cjs/extensions/additional/GPT/MarkupGpt/popup.d.ts +11 -0
- package/build/cjs/extensions/additional/GPT/MarkupGpt/popup.js +14 -0
- package/build/cjs/extensions/additional/GPT/MarkupGpt/toolbar.d.ts +2 -0
- package/build/cjs/extensions/additional/GPT/MarkupGpt/toolbar.js +18 -0
- package/build/cjs/extensions/{yfm → additional}/GPT/index.d.ts +1 -0
- package/build/cjs/extensions/{yfm → additional}/GPT/index.js +1 -0
- package/build/cjs/extensions/{yfm → additional}/GPT/plugin.js +6 -0
- package/build/cjs/extensions/{yfm → additional}/GPT/utils.d.ts +2 -0
- package/build/cjs/extensions/{yfm → additional}/GPT/utils.js +12 -1
- package/build/cjs/extensions/additional/index.d.ts +1 -0
- package/build/cjs/extensions/additional/index.js +4 -0
- package/build/cjs/extensions/behavior/SelectionContext/index.js +2 -1
- package/build/cjs/extensions/index.d.ts +1 -0
- package/build/cjs/extensions/index.js +1 -0
- package/build/cjs/extensions/yfm/Math/commands.d.ts +6 -2
- package/build/cjs/extensions/yfm/Math/commands.js +33 -7
- package/build/cjs/extensions/yfm/Math/index.js +1 -1
- package/build/cjs/extensions/yfm/Math/view-and-edit.js +4 -4
- package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/schema.js +6 -6
- package/build/cjs/extensions/yfm/YfmCut/actions/toYfmCut.js +1 -1
- package/build/cjs/extensions/yfm/YfmCut/index.css +12 -0
- package/build/cjs/extensions/yfm/YfmCut/nodeviews/yfm-cut-title.js +2 -1
- package/build/cjs/extensions/yfm/YfmCut/plugins/auto-open.js +3 -1
- package/build/cjs/extensions/yfm/index.d.ts +1 -1
- package/build/cjs/extensions/yfm/index.js +1 -1
- package/build/cjs/i18n/gpt/dialog/en.json +1 -1
- package/build/cjs/i18n/gpt/dialog/ru.json +1 -1
- package/build/cjs/i18n/menubar/index.d.ts +1 -1
- package/build/cjs/version.js +1 -1
- package/build/esm/bundle/MarkdownEditorView.css +1 -0
- package/build/esm/bundle/MarkdownEditorView.d.ts +4 -0
- package/build/esm/bundle/MarkdownEditorView.js +28 -16
- package/build/esm/bundle/config/action-names.d.ts +1 -1
- package/build/esm/bundle/config/wysiwyg.js +1 -2
- package/build/esm/bundle/settings/index.d.ts +1 -0
- package/build/esm/bundle/settings/index.js +7 -6
- package/build/esm/extensions/additional/GPT/MarkupGpt/commands.d.ts +4 -0
- package/build/esm/extensions/additional/GPT/MarkupGpt/commands.js +12 -0
- package/build/esm/extensions/additional/GPT/MarkupGpt/effects.d.ts +2 -0
- package/build/esm/extensions/additional/GPT/MarkupGpt/effects.js +3 -0
- package/build/esm/extensions/additional/GPT/MarkupGpt/index.d.ts +4 -0
- package/build/esm/extensions/additional/GPT/MarkupGpt/index.js +17 -0
- package/build/esm/extensions/additional/GPT/MarkupGpt/plugin.d.ts +22 -0
- package/build/esm/extensions/additional/GPT/MarkupGpt/plugin.js +117 -0
- package/build/esm/extensions/additional/GPT/MarkupGpt/popup.d.ts +11 -0
- package/build/esm/extensions/additional/GPT/MarkupGpt/popup.js +9 -0
- package/build/esm/extensions/additional/GPT/MarkupGpt/toolbar.d.ts +2 -0
- package/build/esm/extensions/additional/GPT/MarkupGpt/toolbar.js +15 -0
- package/build/esm/extensions/{yfm → additional}/GPT/index.d.ts +1 -0
- package/build/esm/extensions/{yfm → additional}/GPT/index.js +1 -0
- package/build/esm/extensions/{yfm → additional}/GPT/plugin.js +6 -0
- package/build/esm/extensions/{yfm → additional}/GPT/utils.d.ts +2 -0
- package/build/esm/extensions/{yfm → additional}/GPT/utils.js +10 -0
- package/build/esm/extensions/additional/index.d.ts +1 -0
- package/build/esm/extensions/additional/index.js +1 -0
- package/build/esm/extensions/behavior/SelectionContext/index.js +3 -2
- package/build/esm/extensions/index.d.ts +1 -0
- package/build/esm/extensions/index.js +1 -0
- package/build/esm/extensions/yfm/Math/commands.d.ts +6 -2
- package/build/esm/extensions/yfm/Math/commands.js +30 -5
- package/build/esm/extensions/yfm/Math/index.js +2 -2
- package/build/esm/extensions/yfm/Math/view-and-edit.js +6 -5
- package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/schema.js +6 -6
- package/build/esm/extensions/yfm/YfmCut/actions/toYfmCut.js +1 -1
- package/build/esm/extensions/yfm/YfmCut/index.css +12 -0
- package/build/esm/extensions/yfm/YfmCut/nodeviews/yfm-cut-title.js +2 -1
- package/build/esm/extensions/yfm/YfmCut/plugins/auto-open.js +3 -1
- package/build/esm/extensions/yfm/index.d.ts +1 -1
- package/build/esm/extensions/yfm/index.js +1 -1
- package/build/esm/i18n/gpt/dialog/en.json +1 -1
- package/build/esm/i18n/gpt/dialog/ru.json +1 -1
- package/build/esm/i18n/menubar/index.d.ts +1 -1
- package/build/esm/version.js +1 -1
- package/build/styles.css +141 -128
- package/package.json +3 -3
- /package/build/cjs/extensions/{yfm → additional}/GPT/ErrorScreen/ErrorScreen.css +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/ErrorScreen/ErrorScreen.d.ts +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/ErrorScreen/ErrorScreen.js +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/ErrorScreen/types.d.ts +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/ErrorScreen/types.js +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/GptDialog/GptDialog.css +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/GptDialog/GptDialog.d.ts +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/GptDialog/GptDialog.js +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/GptDialog/LoadingScreen/LoadingScreen.css +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/GptDialog/LoadingScreen/LoadingScreen.d.ts +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/GptDialog/LoadingScreen/LoadingScreen.js +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/IconRefuge/IconRefuge.classname.d.ts +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/IconRefuge/IconRefuge.classname.js +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/IconRefuge/IconRefuge.css +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/IconRefuge/IconRefuge.d.ts +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/IconRefuge/IconRefuge.js +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/IconRefuge/index.d.ts +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/IconRefuge/index.js +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/PresetList/PresetList.d.ts +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/PresetList/PresetList.js +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/PresetList/Presetlist.css +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/actions.d.ts +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/actions.js +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/commands.d.ts +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/commands.js +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/constants.d.ts +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/constants.js +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/gptExtension/gptExtension.d.ts +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/gptExtension/gptExtension.js +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/gptExtension/view.css +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/gptExtension/view.d.ts +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/gptExtension/view.js +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/hooks/useGpt.d.ts +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/hooks/useGpt.js +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/hooks/useGptHotKeys.d.ts +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/hooks/useGptHotKeys.js +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/hooks/useOverflowingHorizontalItems.d.ts +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/hooks/useOverflowingHorizontalItems.js +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/hooks/usePresetList.d.ts +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/hooks/usePresetList.js +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/plugin.d.ts +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/toolbar.d.ts +0 -0
- /package/build/cjs/extensions/{yfm → additional}/GPT/toolbar.js +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/ErrorScreen/ErrorScreen.css +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/ErrorScreen/ErrorScreen.d.ts +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/ErrorScreen/ErrorScreen.js +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/ErrorScreen/types.d.ts +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/ErrorScreen/types.js +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/GptDialog/GptDialog.css +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/GptDialog/GptDialog.d.ts +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/GptDialog/GptDialog.js +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/GptDialog/LoadingScreen/LoadingScreen.css +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/GptDialog/LoadingScreen/LoadingScreen.d.ts +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/GptDialog/LoadingScreen/LoadingScreen.js +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/IconRefuge/IconRefuge.classname.d.ts +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/IconRefuge/IconRefuge.classname.js +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/IconRefuge/IconRefuge.css +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/IconRefuge/IconRefuge.d.ts +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/IconRefuge/IconRefuge.js +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/IconRefuge/index.d.ts +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/IconRefuge/index.js +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/PresetList/PresetList.d.ts +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/PresetList/PresetList.js +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/PresetList/Presetlist.css +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/actions.d.ts +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/actions.js +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/commands.d.ts +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/commands.js +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/constants.d.ts +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/constants.js +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/gptExtension/gptExtension.d.ts +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/gptExtension/gptExtension.js +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/gptExtension/view.css +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/gptExtension/view.d.ts +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/gptExtension/view.js +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/hooks/useGpt.d.ts +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/hooks/useGpt.js +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/hooks/useGptHotKeys.d.ts +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/hooks/useGptHotKeys.js +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/hooks/useOverflowingHorizontalItems.d.ts +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/hooks/useOverflowingHorizontalItems.js +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/hooks/usePresetList.d.ts +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/hooks/usePresetList.js +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/plugin.d.ts +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/toolbar.d.ts +0 -0
- /package/build/esm/extensions/{yfm → additional}/GPT/toolbar.js +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.moveCursorLeftOfMathInline = exports.moveCursorRightOfMathInline = exports.removeEmptyMathInlineIfCursorIsAtBeginning = exports.ignoreIfCursorInsideMathInline = void 0;
|
|
4
4
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
5
5
|
const selection_1 = require("../../../utils/selection");
|
|
6
6
|
const const_1 = require("./const");
|
|
@@ -30,15 +30,41 @@ const removeEmptyMathInlineIfCursorIsAtBeginning = ({ tr, schema }, dispatch) =>
|
|
|
30
30
|
};
|
|
31
31
|
exports.removeEmptyMathInlineIfCursorIsAtBeginning = removeEmptyMathInlineIfCursorIsAtBeginning;
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* Handle cursor movement to the right at the boundary of a MathInline block
|
|
34
34
|
*/
|
|
35
|
-
const
|
|
35
|
+
const moveCursorRightOfMathInline = ({ tr, schema }, dispatch) => {
|
|
36
36
|
var _a;
|
|
37
37
|
const $cursor = (0, selection_1.get$Cursor)(tr.selection);
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
if ($cursor) {
|
|
39
|
+
const mathType = (0, const_1.mathIType)(schema);
|
|
40
|
+
const isOnBeforeOfMathInline = ((_a = $cursor.nodeAfter) === null || _a === void 0 ? void 0 : _a.type) === mathType;
|
|
41
|
+
const isOnEndOfMathInline = $cursor.parentOffset === $cursor.parent.content.size &&
|
|
42
|
+
$cursor.parent.type === mathType;
|
|
43
|
+
if (isOnBeforeOfMathInline || isOnEndOfMathInline) {
|
|
44
|
+
const newPos = $cursor.pos + 1;
|
|
45
|
+
dispatch === null || dispatch === void 0 ? void 0 : dispatch(tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, newPos)));
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
};
|
|
51
|
+
exports.moveCursorRightOfMathInline = moveCursorRightOfMathInline;
|
|
52
|
+
/**
|
|
53
|
+
* Handle cursor movement to the left at the boundary of a MathInline block
|
|
54
|
+
*/
|
|
55
|
+
const moveCursorLeftOfMathInline = ({ tr, schema }, dispatch) => {
|
|
56
|
+
var _a;
|
|
57
|
+
const $cursor = (0, selection_1.get$Cursor)(tr.selection);
|
|
58
|
+
if ($cursor) {
|
|
59
|
+
const mathType = (0, const_1.mathIType)(schema);
|
|
60
|
+
const isOnAfterOfMathInline = ((_a = $cursor.nodeBefore) === null || _a === void 0 ? void 0 : _a.type) === mathType;
|
|
61
|
+
const isOnStartOfMathInline = $cursor.parentOffset === 0 && $cursor.parent.type === mathType;
|
|
62
|
+
if (isOnAfterOfMathInline || isOnStartOfMathInline) {
|
|
63
|
+
const newPos = $cursor.pos - 1;
|
|
64
|
+
dispatch === null || dispatch === void 0 ? void 0 : dispatch(tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, newPos)));
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
41
67
|
}
|
|
42
68
|
return false;
|
|
43
69
|
};
|
|
44
|
-
exports.
|
|
70
|
+
exports.moveCursorLeftOfMathInline = moveCursorLeftOfMathInline;
|
|
@@ -24,7 +24,7 @@ const Math = (builder, opts) => {
|
|
|
24
24
|
builder.use(MathSpecs_1.MathSpecs);
|
|
25
25
|
builder.addKeymap(() => ({
|
|
26
26
|
Enter: commands_1.ignoreIfCursorInsideMathInline,
|
|
27
|
-
Backspace: (0, prosemirror_commands_1.chainCommands)(commands_1.
|
|
27
|
+
Backspace: (0, prosemirror_commands_1.chainCommands)(commands_1.removeEmptyMathInlineIfCursorIsAtBeginning, commands_1.moveCursorLeftOfMathInline),
|
|
28
28
|
}));
|
|
29
29
|
builder
|
|
30
30
|
.addPlugin(() => (0, view_and_edit_1.mathViewAndEditPlugin)(Object.assign(Object.assign({}, opts), { reactRenderer: builder.context.get('reactrenderer') })))
|
|
@@ -8,7 +8,6 @@ const selection_1 = require("../../../utils/selection");
|
|
|
8
8
|
const commands_1 = require("./commands");
|
|
9
9
|
const const_1 = require("./const");
|
|
10
10
|
const hint_1 = require("./hint");
|
|
11
|
-
// eslint-disable-line import/order
|
|
12
11
|
const MATH_ACTIVE_DECO = 'math_active_decoration';
|
|
13
12
|
class MathNodeView {
|
|
14
13
|
constructor(node, opts) {
|
|
@@ -162,13 +161,14 @@ class MathBlockNodeView extends MathNodeView {
|
|
|
162
161
|
exports.MathBlockNodeView = MathBlockNodeView;
|
|
163
162
|
const mathViewAndEditPlugin = (options) => new prosemirror_state_1.Plugin({
|
|
164
163
|
props: {
|
|
164
|
+
handleKeyDown: (0, prosemirror_keymap_1.keydownHandler)({
|
|
165
|
+
ArrowRight: commands_1.moveCursorRightOfMathInline,
|
|
166
|
+
ArrowLeft: commands_1.moveCursorLeftOfMathInline,
|
|
167
|
+
}),
|
|
165
168
|
nodeViews: {
|
|
166
169
|
[const_1.MathNode.Block]: (node) => new MathBlockNodeView(node, options),
|
|
167
170
|
[const_1.MathNode.Inline]: (node) => new MathInlineNodeView(node, options),
|
|
168
171
|
},
|
|
169
|
-
handleKeyDown: (0, prosemirror_keymap_1.keydownHandler)({
|
|
170
|
-
ArrowLeft: commands_1.moveCursorToEndOfMathInline,
|
|
171
|
-
}),
|
|
172
172
|
decorations: (state) => {
|
|
173
173
|
const { selection } = state;
|
|
174
174
|
if ((0, selection_1.isTextSelection)(selection)) {
|
|
@@ -10,12 +10,12 @@ const getSchemaSpecs = (opts, placeholder) => {
|
|
|
10
10
|
var _a, _b, _c, _d;
|
|
11
11
|
return ({
|
|
12
12
|
[const_1.CutNode.Cut]: {
|
|
13
|
-
attrs: { class: { default: 'yfm-cut' } },
|
|
13
|
+
attrs: { class: { default: 'yfm-cut' }, open: { default: null } },
|
|
14
14
|
content: `${const_1.CutNode.CutTitle} ${const_1.CutNode.CutContent}`,
|
|
15
15
|
group: 'block yfm-cut',
|
|
16
|
-
parseDOM: [{ tag: '
|
|
16
|
+
parseDOM: [{ tag: '.yfm-cut' }],
|
|
17
17
|
toDOM(node) {
|
|
18
|
-
return ['
|
|
18
|
+
return ['details', node.attrs, 0];
|
|
19
19
|
},
|
|
20
20
|
selectable: true,
|
|
21
21
|
allowSelection: true,
|
|
@@ -26,9 +26,9 @@ const getSchemaSpecs = (opts, placeholder) => {
|
|
|
26
26
|
attrs: { class: { default: 'yfm-cut-title' } },
|
|
27
27
|
content: 'inline*',
|
|
28
28
|
group: 'block yfm-cut',
|
|
29
|
-
parseDOM: [{ tag: '
|
|
29
|
+
parseDOM: [{ tag: '.yfm-cut-title' }],
|
|
30
30
|
toDOM(node) {
|
|
31
|
-
return ['
|
|
31
|
+
return ['summary', node.attrs, 0];
|
|
32
32
|
},
|
|
33
33
|
placeholder: {
|
|
34
34
|
content: (_b = (_a = placeholder === null || placeholder === void 0 ? void 0 : placeholder[const_1.CutNode.CutTitle]) !== null && _a !== void 0 ? _a : opts === null || opts === void 0 ? void 0 : opts.yfmCutTitlePlaceholder) !== null && _b !== void 0 ? _b : DEFAULT_PLACEHOLDERS.Title,
|
|
@@ -43,7 +43,7 @@ const getSchemaSpecs = (opts, placeholder) => {
|
|
|
43
43
|
attrs: { class: { default: 'yfm-cut-content' } },
|
|
44
44
|
content: '(block | paragraph)+',
|
|
45
45
|
group: 'block yfm-cut',
|
|
46
|
-
parseDOM: [{ tag: '
|
|
46
|
+
parseDOM: [{ tag: '.yfm-cut-content' }],
|
|
47
47
|
toDOM(node) {
|
|
48
48
|
return ['div', node.attrs, 0];
|
|
49
49
|
},
|
|
@@ -5,7 +5,7 @@ const prosemirror_state_1 = require("prosemirror-state");
|
|
|
5
5
|
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
6
6
|
const const_1 = require("../const");
|
|
7
7
|
const createYfmCutNode = (schema) => (content) => {
|
|
8
|
-
return (0, const_1.cutType)(schema).create({ class: 'yfm-cut open' }, [
|
|
8
|
+
return (0, const_1.cutType)(schema).create({ class: 'yfm-cut open', open: true }, [
|
|
9
9
|
(0, const_1.cutTitleType)(schema).create(null),
|
|
10
10
|
(0, const_1.cutContentType)(schema).create(null, content),
|
|
11
11
|
]);
|
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
.ProseMirror.yfm .yfm-cut {
|
|
2
2
|
border: 1px dashed transparent;
|
|
3
3
|
border-radius: var(--g-border-radius-s);
|
|
4
|
+
/* TODO: Remove this after updating @diplodoc/transform to version 4.19.0 or higher */
|
|
5
|
+
/* This ensures backward compatibility with earlier versions of cut-extension */
|
|
4
6
|
}
|
|
5
7
|
.ProseMirror.yfm .yfm-cut:hover {
|
|
6
8
|
border-color: var(--g-color-line-generic);
|
|
7
9
|
}
|
|
8
10
|
.ProseMirror.yfm .yfm-cut.yfm-cut-active {
|
|
9
11
|
border-color: var(--g-color-line-generic);
|
|
12
|
+
}
|
|
13
|
+
.ProseMirror.yfm .yfm-cut .yfm-cut-title:focus {
|
|
14
|
+
outline: 0;
|
|
15
|
+
}
|
|
16
|
+
.ProseMirror.yfm .yfm-cut .yfm-cut-title {
|
|
17
|
+
list-style: none;
|
|
18
|
+
}
|
|
19
|
+
.ProseMirror.yfm .yfm-cut .yfm-cut-title::-webkit-details-marker,
|
|
20
|
+
.ProseMirror.yfm .yfm-cut .yfm-cut-title::marker {
|
|
21
|
+
display: none;
|
|
10
22
|
}
|
|
@@ -4,7 +4,7 @@ exports.YfmCutTitleNodeView = void 0;
|
|
|
4
4
|
class YfmCutTitleNodeView {
|
|
5
5
|
constructor(node) {
|
|
6
6
|
this.node = node;
|
|
7
|
-
this.dom = document.createElement('
|
|
7
|
+
this.dom = document.createElement('summary');
|
|
8
8
|
this.dom.classList.add('yfm-cut-title');
|
|
9
9
|
this.dom.replaceChildren((this.contentDOM = document.createElement('div')));
|
|
10
10
|
this.contentDOM.classList.add('g-md-yfm-cut-title-inner');
|
|
@@ -12,6 +12,7 @@ class YfmCutTitleNodeView {
|
|
|
12
12
|
// ignore clicking on the title content
|
|
13
13
|
// you can open/close yfm-cut by clicking on the arrow icon
|
|
14
14
|
e.stopPropagation();
|
|
15
|
+
e.preventDefault();
|
|
15
16
|
});
|
|
16
17
|
}
|
|
17
18
|
update(node) {
|
|
@@ -42,6 +42,7 @@ function openParentYfmCuts($pos, domAtPos) {
|
|
|
42
42
|
if ($pos.node(depth - 1).type === (0, const_1.cutType)(schema)) {
|
|
43
43
|
const { node: cutDomNode } = domAtPos($pos.start(depth - 1), 0);
|
|
44
44
|
cutDomNode.classList.add('open');
|
|
45
|
+
cutDomNode.setAttribute('open', 'true');
|
|
45
46
|
depth--;
|
|
46
47
|
}
|
|
47
48
|
}
|
|
@@ -89,9 +90,10 @@ class CutAutoOpenOnDragOver {
|
|
|
89
90
|
this._timeout = setTimeout(this._openCut.bind(this), CutAutoOpenOnDragOver.OPEN_TIMEOUT);
|
|
90
91
|
}
|
|
91
92
|
_openCut() {
|
|
92
|
-
var _a;
|
|
93
|
+
var _a, _b;
|
|
93
94
|
if (this._editorView.dragging) {
|
|
94
95
|
(_a = this._cutElem) === null || _a === void 0 ? void 0 : _a.classList.add('open');
|
|
96
|
+
(_b = this._cutElem) === null || _b === void 0 ? void 0 : _b.setAttribute('open', 'true');
|
|
95
97
|
}
|
|
96
98
|
this._clear();
|
|
97
99
|
}
|
|
@@ -14,4 +14,4 @@ tslib_1.__exportStar(require("./YfmHeading"), exports);
|
|
|
14
14
|
tslib_1.__exportStar(require("./YfmNote"), exports);
|
|
15
15
|
tslib_1.__exportStar(require("./YfmTable"), exports);
|
|
16
16
|
tslib_1.__exportStar(require("./YfmTabs"), exports);
|
|
17
|
-
tslib_1.__exportStar(require("
|
|
17
|
+
tslib_1.__exportStar(require("../additional/GPT"), exports);
|
|
@@ -12,5 +12,5 @@
|
|
|
12
12
|
"replace": "Заменить выделенный текст",
|
|
13
13
|
"replace-disabled": "Вставить текст",
|
|
14
14
|
"try-again": "Иначе",
|
|
15
|
-
"alert-gpt-presets-info": "Выделите текст, чтобы увидеть пресеты
|
|
15
|
+
"alert-gpt-presets-info": "Выделите текст, чтобы увидеть пресеты GPT"
|
|
16
16
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const i18n: <G extends "bold" | "code" | "link" | "italic" | "strike" | "underline" | "mark" | "quote" | "colorify" | "mono" | "text" | "html" | "cut" | "table" | "image" | "code_inline" | "list" | "heading" | "note" | "file" | "codeblock" | "checkbox" | "emoji" | "tabs" | "math" | "heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "gpt" | "undo" | "redo" | "math_inline" | "math_block" | "colorify__color_blue" | "colorify__color_default" | "colorify__color_gray" | "colorify__color_green" | "colorify__color_orange" | "colorify__color_red" | "colorify__color_violet" | "colorify__color_yellow" | "colorify__group_text" | "folding-heading" | "folding-heading_hint" | "hrule" | "list__action_lift" | "list__action_sink" | "list_action_disabled" | "
|
|
1
|
+
export declare const i18n: <G extends "bold" | "code" | "link" | "italic" | "strike" | "underline" | "mark" | "quote" | "colorify" | "mono" | "text" | "html" | "cut" | "table" | "image" | "code_inline" | "list" | "heading" | "note" | "file" | "codeblock" | "checkbox" | "emoji" | "tabs" | "math" | "heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "gpt" | "undo" | "redo" | "math_inline" | "math_block" | "mermaid" | "colorify__color_blue" | "colorify__color_default" | "colorify__color_gray" | "colorify__color_green" | "colorify__color_orange" | "colorify__color_red" | "colorify__color_violet" | "colorify__color_yellow" | "colorify__group_text" | "folding-heading" | "folding-heading_hint" | "hrule" | "list__action_lift" | "list__action_sink" | "list_action_disabled" | "more_action" | "olist" | "ulist", S extends string>(key: G | (string extends S ? S : never), params?: {
|
|
2
2
|
[key: string]: any;
|
|
3
3
|
} | undefined) => S extends G ? {
|
|
4
4
|
bold: string;
|
package/build/cjs/version.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VERSION = void 0;
|
|
4
4
|
/** During build process, the current version will be injected here */
|
|
5
|
-
exports.VERSION = typeof '13.
|
|
5
|
+
exports.VERSION = typeof '13.25.0' !== 'undefined' ? '13.25.0' : 'unknown';
|
|
@@ -17,6 +17,8 @@ export declare type MarkdownEditorViewProps = ClassNameProps & {
|
|
|
17
17
|
settingsVisible?: boolean;
|
|
18
18
|
toaster: ToasterPublicMethods;
|
|
19
19
|
stickyToolbar: boolean;
|
|
20
|
+
enableSubmitInPreview?: boolean;
|
|
21
|
+
hidePreviewAfterSubmit?: boolean;
|
|
20
22
|
};
|
|
21
23
|
export declare const MarkdownEditorView: React.ForwardRefExoticComponent<ClassNameProps & {
|
|
22
24
|
editor?: Editor | undefined;
|
|
@@ -29,4 +31,6 @@ export declare const MarkdownEditorView: React.ForwardRefExoticComponent<ClassNa
|
|
|
29
31
|
settingsVisible?: boolean | undefined;
|
|
30
32
|
toaster: ToasterPublicMethods;
|
|
31
33
|
stickyToolbar: boolean;
|
|
34
|
+
enableSubmitInPreview?: boolean | undefined;
|
|
35
|
+
hidePreviewAfterSubmit?: boolean | undefined;
|
|
32
36
|
} & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -30,7 +30,7 @@ export const MarkdownEditorView = React.forwardRef((props, ref) => {
|
|
|
30
30
|
const editor = ((_a = props.editor) !== null && _a !== void 0 ? _a : context);
|
|
31
31
|
if (!editor)
|
|
32
32
|
throw new Error('[MarkdownEditorView]: an instance of the editor must be passed through the props or context');
|
|
33
|
-
const { autofocus, className, settingsVisible = true, markupToolbarConfig = mToolbarConfigByPreset[editor.preset], wysiwygToolbarConfig = wToolbarConfigByPreset[editor.preset], markupHiddenActionsConfig = mHiddenDataByPreset[editor.preset], wysiwygHiddenActionsConfig = wHiddenDataByPreset[editor.preset], toaster, stickyToolbar, } = props;
|
|
33
|
+
const { autofocus, className, settingsVisible = true, markupToolbarConfig = mToolbarConfigByPreset[editor.preset], wysiwygToolbarConfig = wToolbarConfigByPreset[editor.preset], markupHiddenActionsConfig = mHiddenDataByPreset[editor.preset], wysiwygHiddenActionsConfig = wHiddenDataByPreset[editor.preset], toaster, stickyToolbar, enableSubmitInPreview = true, hidePreviewAfterSubmit = false, } = props;
|
|
34
34
|
const rerender = useUpdate();
|
|
35
35
|
React.useLayoutEffect(() => {
|
|
36
36
|
editor.on('rerender', rerender);
|
|
@@ -57,7 +57,10 @@ export const MarkdownEditorView = React.forwardRef((props, ref) => {
|
|
|
57
57
|
const editorMode = editor.currentMode;
|
|
58
58
|
const markupSplitMode = editor.splitModeEnabled && editor.splitMode && editorMode === 'markup';
|
|
59
59
|
const canRenderPreview = Boolean(editor.renderPreview && editorMode === 'markup' && !editor.splitModeEnabled);
|
|
60
|
-
useKey((e) => canRenderPreview && isPreviewKeyDown(e), () =>
|
|
60
|
+
useKey((e) => canRenderPreview && isPreviewKeyDown(e), (e) => {
|
|
61
|
+
e.preventDefault();
|
|
62
|
+
onShowPreviewChange(!showPreview);
|
|
63
|
+
}, { event: 'keydown' }, [showPreview, editorMode, onShowPreviewChange, canRenderPreview]);
|
|
61
64
|
const editorWrapperRef = useRef(null);
|
|
62
65
|
const splitModeViewWrapperRef = useRef(null);
|
|
63
66
|
useEffect(() => {
|
|
@@ -65,19 +68,28 @@ export const MarkdownEditorView = React.forwardRef((props, ref) => {
|
|
|
65
68
|
divRef.current.focus();
|
|
66
69
|
}
|
|
67
70
|
}, [divRef, showPreview]);
|
|
68
|
-
useKey((e) =>
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
editor.
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
useKey((e) => enableSubmitInPreview &&
|
|
72
|
+
showPreview &&
|
|
73
|
+
isWrapperFocused(divRef) &&
|
|
74
|
+
isSubmitKeyDown(e), () => {
|
|
75
|
+
editor.emit('submit', null);
|
|
76
|
+
if (hidePreviewAfterSubmit) {
|
|
77
|
+
onShowPreviewChange(false);
|
|
78
|
+
}
|
|
79
|
+
}, { event: 'keydown' }, [hidePreviewAfterSubmit, enableSubmitInPreview, showPreview, showPreview]);
|
|
80
|
+
const settings = useMemo(() => (React.createElement(Settings, { mode: editorMode, settingsVisible: settingsVisible, onModeChange: onModeChange, toolbarVisibility: editor.toolbarVisible && !showPreview, onToolbarVisibilityChange: onToolbarVisibilityChange, onSplitModeChange: onSplitModeChange, splitModeEnabled: editor.splitModeEnabled, splitMode: editor.splitMode, stickyToolbar: stickyToolbar, onShowPreviewChange: onShowPreviewChange, showPreview: showPreview, renderPreviewButton: canRenderPreview })), [
|
|
75
81
|
editorMode,
|
|
82
|
+
settingsVisible,
|
|
83
|
+
editor.toolbarVisible,
|
|
84
|
+
editor.splitModeEnabled,
|
|
85
|
+
editor.splitMode,
|
|
76
86
|
onModeChange,
|
|
77
|
-
onShowPreviewChange,
|
|
78
|
-
onSplitModeChange,
|
|
79
|
-
onToolbarVisibilityChange,
|
|
80
87
|
showPreview,
|
|
88
|
+
onToolbarVisibilityChange,
|
|
89
|
+
onSplitModeChange,
|
|
90
|
+
stickyToolbar,
|
|
91
|
+
onShowPreviewChange,
|
|
92
|
+
canRenderPreview,
|
|
81
93
|
]);
|
|
82
94
|
return (React.createElement(ErrorBoundary, { onError: (e) => {
|
|
83
95
|
logger.error(e);
|
|
@@ -110,8 +122,8 @@ export const MarkdownEditorView = React.forwardRef((props, ref) => {
|
|
|
110
122
|
})),
|
|
111
123
|
settings)) : (React.createElement(React.Fragment, null,
|
|
112
124
|
editorMode === 'wysiwyg' && (React.createElement(WysiwygEditorView, { editor: editor, autofocus: autofocus, settingsVisible: settingsVisible, toolbarConfig: wysiwygToolbarConfig, toolbarVisible: editor.toolbarVisible, hiddenActionsConfig: wysiwygHiddenActionsConfig, className: b('editor', { mode: editorMode }), toolbarClassName: b('toolbar'), stickyToolbar: stickyToolbar }, editor.toolbarVisible && settingsVisible && settings)),
|
|
113
|
-
editorMode === 'markup' && (React.createElement(MarkupEditorView, { editor: editor, autofocus: autofocus, settingsVisible: settingsVisible, toolbarConfig: markupToolbarConfig, toolbarVisible: editor.toolbarVisible, splitMode: editor.splitMode, splitModeEnabled: editor.splitModeEnabled, hiddenActionsConfig: markupHiddenActionsConfig, className: b('editor', { mode: editorMode }), toolbarClassName: b('toolbar'), stickyToolbar: stickyToolbar }, editor.toolbarVisible &&
|
|
114
|
-
!editor.toolbarVisible &&
|
|
125
|
+
editorMode === 'markup' && (React.createElement(MarkupEditorView, { editor: editor, autofocus: autofocus, settingsVisible: settingsVisible, toolbarConfig: markupToolbarConfig, toolbarVisible: editor.toolbarVisible, splitMode: editor.splitMode, splitModeEnabled: editor.splitModeEnabled, hiddenActionsConfig: markupHiddenActionsConfig, className: b('editor', { mode: editorMode }), toolbarClassName: b('toolbar'), stickyToolbar: stickyToolbar }, editor.toolbarVisible && settings)),
|
|
126
|
+
!editor.toolbarVisible && settings))),
|
|
115
127
|
markupSplitMode && (React.createElement(React.Fragment, null,
|
|
116
128
|
editor.splitMode === 'horizontal' ? (React.createElement(HorizontalDrag, { editor: editor, isMounted: isMounted, leftElRef: editorWrapperRef, rightElRef: splitModeViewWrapperRef, wrapperRef: divRef })) : (React.createElement("div", { className: b('resizer') })),
|
|
117
129
|
React.createElement(SplitModeView, { editor: editor, ref: splitModeViewWrapperRef })))))));
|
|
@@ -121,13 +133,13 @@ const MarkupSearchAnchor = ({ mode }) => (React.createElement(React.Fragment, nu
|
|
|
121
133
|
function Settings(props) {
|
|
122
134
|
const wrapperRef = useRef(null);
|
|
123
135
|
const isSticky = useSticky(wrapperRef) && props.toolbarVisibility && props.stickyToolbar;
|
|
124
|
-
return (React.createElement("div", { className: b('settings-wrapper') },
|
|
136
|
+
return (React.createElement(React.Fragment, null, (props.renderPreviewButton || props.settingsVisible) && (React.createElement("div", { className: b('settings-wrapper') },
|
|
125
137
|
React.createElement("div", { ref: wrapperRef, className: stickyCn.settings({
|
|
126
138
|
withToolbar: props.toolbarVisibility,
|
|
127
139
|
stickyActive: isSticky,
|
|
128
140
|
}) },
|
|
129
141
|
React.createElement(EditorSettings, Object.assign({}, props)),
|
|
130
|
-
React.createElement(MarkupSearchAnchor, Object.assign({}, props)))));
|
|
142
|
+
React.createElement(MarkupSearchAnchor, Object.assign({}, props)))))));
|
|
131
143
|
}
|
|
132
144
|
function isPreviewKeyDown(e) {
|
|
133
145
|
const modKey = isMac() ? e.metaKey : e.ctrlKey;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
declare const namesObj: Record<"bold" | "link" | "italic" | "strike" | "underline" | "mark" | "quote" | "mono" | "paragraph" | "anchor" | "table" | "image" | "code_inline" | "code_block" | "file" | "checkbox" | "bulletList" | "orderedList" | "emoji" | "tabs" | "yfm_cut" | "heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "yfm_note" | "gpt" | "undo" | "redo" | "
|
|
1
|
+
declare const namesObj: Record<"bold" | "link" | "italic" | "strike" | "underline" | "mark" | "quote" | "mono" | "paragraph" | "anchor" | "table" | "image" | "code_inline" | "code_block" | "file" | "checkbox" | "bulletList" | "orderedList" | "emoji" | "tabs" | "yfm_cut" | "heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "yfm_note" | "gpt" | "undo" | "redo" | "liftListItem" | "sinkListItem" | "yfm_block" | "yfm_html_block" | "yfm_layout" | "horizontalrule" | "math_inline" | "math_block" | "mermaid", string>;
|
|
2
2
|
export declare const ActionName: Readonly<typeof namesObj>;
|
|
3
3
|
export {};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { headingType, pType } from '../../extensions';
|
|
2
|
-
|
|
3
|
-
import { gptHotKeys } from '../../extensions/yfm/GPT/constants';
|
|
2
|
+
import { gptHotKeys } from '../../extensions/additional/GPT/constants';
|
|
4
3
|
import { i18n as i18nHint } from '../../i18n/hints';
|
|
5
4
|
import { i18n } from '../../i18n/menubar';
|
|
6
5
|
import { Action as A, formatter as f } from '../../shortcuts';
|
|
@@ -4,6 +4,7 @@ import type { EditorMode, SplitMode } from '../Editor';
|
|
|
4
4
|
import './index.css';
|
|
5
5
|
export declare type EditorSettingsProps = Omit<SettingsContentProps, 'onClose'> & {
|
|
6
6
|
renderPreviewButton?: boolean;
|
|
7
|
+
settingsVisible?: boolean;
|
|
7
8
|
};
|
|
8
9
|
export declare const EditorSettings: React.NamedExoticComponent<EditorSettingsProps>;
|
|
9
10
|
declare type SettingsContentProps = ClassNameProps & {
|
|
@@ -17,7 +17,7 @@ const placement = ['bottom-end', 'top-end'];
|
|
|
17
17
|
const bSettings = cn('editor-settings');
|
|
18
18
|
const bContent = cn('settings-content');
|
|
19
19
|
export const EditorSettings = React.memo(function EditorSettings(props) {
|
|
20
|
-
const { className, onShowPreviewChange, showPreview, renderPreviewButton } = props;
|
|
20
|
+
const { className, onShowPreviewChange, showPreview, renderPreviewButton, settingsVisible } = props;
|
|
21
21
|
const chevronRef = React.useRef(null);
|
|
22
22
|
const [popupShown, , hidePopup, togglePopup] = useBooleanState(false);
|
|
23
23
|
return (React.createElement("div", { className: bSettings(null, [className]) },
|
|
@@ -25,11 +25,12 @@ export const EditorSettings = React.memo(function EditorSettings(props) {
|
|
|
25
25
|
React.createElement(ActionTooltip, { openDelay: ToolbarTooltipDelay.Open, closeDelay: ToolbarTooltipDelay.Close, title: i18n('preview_hint'), hotkey: "mod+shift+p" },
|
|
26
26
|
React.createElement(Button, { size: "m", view: "flat", pin: "round-round", className: bSettings('preview-button'), onClick: () => onShowPreviewChange === null || onShowPreviewChange === void 0 ? void 0 : onShowPreviewChange(!showPreview), selected: showPreview },
|
|
27
27
|
React.createElement(Icon, { data: Eye }))),
|
|
28
|
-
React.createElement("div", { className: bSettings('separator') }))),
|
|
29
|
-
React.createElement(
|
|
30
|
-
React.createElement(
|
|
31
|
-
|
|
32
|
-
React.createElement(
|
|
28
|
+
settingsVisible && React.createElement("div", { className: bSettings('separator') }))),
|
|
29
|
+
settingsVisible && (React.createElement(React.Fragment, null,
|
|
30
|
+
React.createElement(Button, { size: "m", view: "flat", ref: chevronRef, pin: "round-round", onClick: togglePopup, className: bSettings('dropdown-button') },
|
|
31
|
+
React.createElement(Icon, { data: Gear })),
|
|
32
|
+
React.createElement(Popup, { open: popupShown, anchorRef: chevronRef, placement: placement, onClose: hidePopup },
|
|
33
|
+
React.createElement(SettingsContent, Object.assign({}, props, { onClose: hidePopup, className: bSettings('content') })))))));
|
|
33
34
|
});
|
|
34
35
|
const mdHelpPlacement = ['bottom', 'bottom-end', 'right-start', 'right', 'left'];
|
|
35
36
|
const SettingsContent = function SettingsContent({ mode, onClose, onModeChange, toolbarVisibility, onToolbarVisibilityChange, onSplitModeChange, splitMode = false, splitModeEnabled, className, showPreview, }) {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { HideMarkupGptEffect, ShowMarkupGptEffect } from './effects';
|
|
2
|
+
export const showMarkupGpt = (view) => {
|
|
3
|
+
view.dispatch({ effects: [ShowMarkupGptEffect.of(null)] });
|
|
4
|
+
};
|
|
5
|
+
export const hideMarkupGpt = (view) => {
|
|
6
|
+
view.dispatch({ effects: [HideMarkupGptEffect.of(null)] });
|
|
7
|
+
};
|
|
8
|
+
export const runMarkupGpt = (view) => {
|
|
9
|
+
if (view)
|
|
10
|
+
showMarkupGpt(view);
|
|
11
|
+
return true;
|
|
12
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { keymap } from '@codemirror/view';
|
|
2
|
+
import { gptHotKeys } from '../constants';
|
|
3
|
+
import { runMarkupGpt } from './commands';
|
|
4
|
+
import { mGptPlugin } from './plugin';
|
|
5
|
+
export { mGptToolbarItem } from './toolbar';
|
|
6
|
+
export { showMarkupGpt, hideMarkupGpt } from './commands';
|
|
7
|
+
export function mGptExtension(props) {
|
|
8
|
+
return [
|
|
9
|
+
mGptPlugin(props).extension,
|
|
10
|
+
keymap.of([
|
|
11
|
+
{
|
|
12
|
+
key: gptHotKeys.openGptKey,
|
|
13
|
+
run: runMarkupGpt,
|
|
14
|
+
},
|
|
15
|
+
]),
|
|
16
|
+
];
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { GptWidgetOptions } from '../../..';
|
|
2
|
+
import { type DecorationSet, type EditorView, ViewPlugin, type ViewUpdate } from '../../../../cm/view';
|
|
3
|
+
export declare function mGptPlugin(gptProps: GptWidgetOptions): ViewPlugin<{
|
|
4
|
+
readonly _view: EditorView;
|
|
5
|
+
readonly _renderItem: import("../../..").RendererItem;
|
|
6
|
+
_anchor: Element | null;
|
|
7
|
+
decos: DecorationSet;
|
|
8
|
+
disablePromptPresets: boolean;
|
|
9
|
+
markup: string | null;
|
|
10
|
+
selectedPosition: {
|
|
11
|
+
from: number;
|
|
12
|
+
to: number;
|
|
13
|
+
};
|
|
14
|
+
update(update: ViewUpdate): void;
|
|
15
|
+
docViewUpdate(): void;
|
|
16
|
+
destroy(): void;
|
|
17
|
+
renderPopup(): JSX.Element | null;
|
|
18
|
+
_getDecorationText(update: ViewUpdate, from: number, to: number): string;
|
|
19
|
+
_clearSelectedText(): void;
|
|
20
|
+
_setSelectedText(str: string): void;
|
|
21
|
+
_onApplyResult(changedMarkup: string): void;
|
|
22
|
+
}>;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { WidgetType } from '@codemirror/view';
|
|
2
|
+
import { Decoration, ViewPlugin, } from '../../../../cm/view';
|
|
3
|
+
import { ReactRendererFacet } from '../../../../markup';
|
|
4
|
+
import { WIDGET_DECO_CLASS_NAME } from '../constants';
|
|
5
|
+
import { isEmptyGptPrompts } from '../utils';
|
|
6
|
+
import { hideMarkupGpt } from './commands';
|
|
7
|
+
import { HideMarkupGptEffect, ShowMarkupGptEffect } from './effects';
|
|
8
|
+
import { renderPopup } from './popup';
|
|
9
|
+
class SpanWidget extends WidgetType {
|
|
10
|
+
constructor(className, textContent) {
|
|
11
|
+
super();
|
|
12
|
+
this.className = '';
|
|
13
|
+
this.textContent = '';
|
|
14
|
+
this.className = className;
|
|
15
|
+
this.textContent = textContent;
|
|
16
|
+
}
|
|
17
|
+
toDOM() {
|
|
18
|
+
const spanElem = document.createElement('span');
|
|
19
|
+
spanElem.className = this.className;
|
|
20
|
+
spanElem.textContent = this.textContent;
|
|
21
|
+
return spanElem;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function mGptPlugin(gptProps) {
|
|
25
|
+
return ViewPlugin.fromClass(class {
|
|
26
|
+
constructor(view) {
|
|
27
|
+
this._anchor = null;
|
|
28
|
+
this.decos = Decoration.none;
|
|
29
|
+
this.disablePromptPresets = true;
|
|
30
|
+
this.markup = null;
|
|
31
|
+
this.selectedPosition = {
|
|
32
|
+
from: 0,
|
|
33
|
+
to: 0,
|
|
34
|
+
};
|
|
35
|
+
this._view = view;
|
|
36
|
+
this._renderItem = view.state
|
|
37
|
+
.facet(ReactRendererFacet)
|
|
38
|
+
.createItem('gpt-in-markup-mode', () => this.renderPopup());
|
|
39
|
+
}
|
|
40
|
+
update(update) {
|
|
41
|
+
if (update.docChanged || update.selectionSet) {
|
|
42
|
+
this.decos = Decoration.none;
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
this.decos = this.decos.map(update.changes);
|
|
46
|
+
const { from, to } = update.state.selection.main;
|
|
47
|
+
this.selectedPosition.from = from;
|
|
48
|
+
this.selectedPosition.to = to;
|
|
49
|
+
for (const tr of update.transactions) {
|
|
50
|
+
for (const eff of tr.effects) {
|
|
51
|
+
if (eff.is(ShowMarkupGptEffect)) {
|
|
52
|
+
this._setSelectedText(this._getDecorationText(update, from, to));
|
|
53
|
+
if (from === to) {
|
|
54
|
+
this.disablePromptPresets = true;
|
|
55
|
+
if (isEmptyGptPrompts(gptProps, true))
|
|
56
|
+
return;
|
|
57
|
+
const decorationWidget = Decoration.widget({
|
|
58
|
+
widget: new SpanWidget(WIDGET_DECO_CLASS_NAME, ' '),
|
|
59
|
+
});
|
|
60
|
+
this.decos = Decoration.set([decorationWidget.range(from)]);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
this.disablePromptPresets = false;
|
|
64
|
+
if (isEmptyGptPrompts(gptProps, false))
|
|
65
|
+
return;
|
|
66
|
+
this.decos = Decoration.set([
|
|
67
|
+
{
|
|
68
|
+
from,
|
|
69
|
+
to,
|
|
70
|
+
value: Decoration.mark({ class: WIDGET_DECO_CLASS_NAME }),
|
|
71
|
+
},
|
|
72
|
+
]);
|
|
73
|
+
}
|
|
74
|
+
if (eff.is(HideMarkupGptEffect)) {
|
|
75
|
+
this.decos = Decoration.none;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
docViewUpdate() {
|
|
81
|
+
this._anchor = this._view.dom
|
|
82
|
+
.getElementsByClassName(WIDGET_DECO_CLASS_NAME)
|
|
83
|
+
.item(0);
|
|
84
|
+
this._renderItem.rerender();
|
|
85
|
+
}
|
|
86
|
+
destroy() {
|
|
87
|
+
this._clearSelectedText();
|
|
88
|
+
this._renderItem.remove();
|
|
89
|
+
}
|
|
90
|
+
renderPopup() {
|
|
91
|
+
if (!this._anchor || this.markup === null) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
return renderPopup(this._anchor, Object.assign(Object.assign({}, gptProps), { disablePromptPresets: this.disablePromptPresets, onClose: () => hideMarkupGpt(this._view), markup: this.markup, onApplyResult: (changedMarkup) => this._onApplyResult(changedMarkup) }));
|
|
95
|
+
}
|
|
96
|
+
_getDecorationText(update, from, to) {
|
|
97
|
+
return update.state.doc.sliceString(from, to);
|
|
98
|
+
}
|
|
99
|
+
_clearSelectedText() {
|
|
100
|
+
this.markup = null;
|
|
101
|
+
}
|
|
102
|
+
_setSelectedText(str) {
|
|
103
|
+
this.markup = str;
|
|
104
|
+
}
|
|
105
|
+
_onApplyResult(changedMarkup) {
|
|
106
|
+
const { from, to } = this.selectedPosition;
|
|
107
|
+
const changes = [{ from: from, to: to, insert: changedMarkup }];
|
|
108
|
+
const transaction = this._view.state.update({
|
|
109
|
+
changes: changes,
|
|
110
|
+
effects: [HideMarkupGptEffect.of(null)],
|
|
111
|
+
});
|
|
112
|
+
this._view.dispatch(transaction);
|
|
113
|
+
}
|
|
114
|
+
}, {
|
|
115
|
+
decorations: (value) => value.decos,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { PopupProps } from '@gravity-ui/uikit';
|
|
3
|
+
import { GptDialogProps } from '../GptDialog/GptDialog';
|
|
4
|
+
declare type Props = {
|
|
5
|
+
onClose: () => void;
|
|
6
|
+
markup: string;
|
|
7
|
+
onConfirmOk?: () => void;
|
|
8
|
+
onConfirmCancel?: () => void;
|
|
9
|
+
} & GptDialogProps & Pick<PopupProps, 'anchorRef' | 'container'>;
|
|
10
|
+
export declare function renderPopup(anchor: HTMLElement, props: Props): JSX.Element;
|
|
11
|
+
export {};
|