|
1 | | -import {CircleInfo, TrashBin} from '@gravity-ui/icons'; |
2 | | -import type {Node, Schema} from 'prosemirror-model'; |
3 | | -import {Plugin, type Transaction} from 'prosemirror-state'; |
4 | | -import type {EditorView} from 'prosemirror-view'; |
| 1 | +import {Plugin} from 'prosemirror-state'; |
5 | 2 |
|
6 | | -import type {ExtensionDeps} from '../../../../../core'; |
7 | | -import {i18n} from '../../../../../i18n/yfm-note'; |
8 | | -import {BaseTooltipPluginView} from '../../../../../plugins/BaseTooltip'; |
9 | | -import {Toolbar, ToolbarDataType} from '../../../../../toolbar'; |
10 | | -import {removeNode} from '../../../../../utils/remove-node'; |
11 | | -import {noteType} from '../../../index'; |
| 3 | +import type {ExtensionDeps} from '#core'; |
| 4 | +import {BaseTooltipPluginView} from 'src/plugins/BaseTooltip'; |
12 | 5 |
|
13 | | -import './index.scss'; |
| 6 | +import {noteType} from '../../utils'; |
14 | 7 |
|
15 | | -enum YfmNoteType { |
16 | | - tip = 'tip', |
17 | | - info = 'info', |
18 | | - warning = 'warning', |
19 | | - alert = 'alert', |
20 | | -} |
| 8 | +import {YfmNoteToolbar} from './YfmNoteToolbar'; |
21 | 9 |
|
22 | | -const isEnable = () => true; |
23 | | -const isActive = () => false; |
24 | | - |
25 | | -const changeType: ( |
26 | | - type: YfmNoteType, |
27 | | -) => (params: { |
28 | | - schema: Schema; |
29 | | - node: Node; |
30 | | - pos: number; |
31 | | - dispatch: EditorView['dispatch']; |
32 | | - tr: Transaction; |
33 | | -}) => void = |
34 | | - (type) => |
35 | | - ({node, pos, dispatch, tr}) => { |
36 | | - dispatch( |
37 | | - tr.setNodeMarkup(pos, null, { |
38 | | - ...node.attrs, |
39 | | - class: `yfm-note yfm-accent-${type}`, |
40 | | - 'note-type': type, |
41 | | - }), |
42 | | - ); |
43 | | - }; |
44 | | - |
45 | | -export const yfmNoteTooltipPlugin = ({actions, schema}: ExtensionDeps) => |
| 10 | +export const yfmNoteTooltipPlugin = (_deps: ExtensionDeps) => |
46 | 11 | new Plugin({ |
47 | 12 | view(view) { |
48 | 13 | return new BaseTooltipPluginView(view, { |
49 | 14 | idPrefix: 'yfm-note-tooltip', |
50 | 15 | nodeType: noteType(view.state.schema), |
51 | 16 | popupPlacement: ['bottom', 'top'], |
52 | 17 | content: (view, {node, pos}) => ( |
53 | | - <Toolbar |
54 | | - editor={actions} |
55 | | - focus={() => view.focus()} |
56 | | - // the yfm class allows to access css variables |
57 | | - // https://github.com/diplodoc-platform/transform/blob/master/src/scss/_common.scss#L17 |
58 | | - className="yfm g-md-yfm-note-toolbar" |
59 | | - qa="g-md-toolbar-yfm-note" |
60 | | - data={[ |
61 | | - [ |
62 | | - YfmNoteType.info, |
63 | | - YfmNoteType.tip, |
64 | | - YfmNoteType.warning, |
65 | | - YfmNoteType.alert, |
66 | | - ].map((type) => ({ |
67 | | - id: `note-type-${type}`, |
68 | | - icon: {data: CircleInfo}, |
69 | | - title: i18n(type), |
70 | | - type: ToolbarDataType.SingleButton, |
71 | | - isActive, |
72 | | - isEnable, |
73 | | - exec: () => |
74 | | - changeType(type)({ |
75 | | - schema, |
76 | | - pos: pos, |
77 | | - node: node, |
78 | | - tr: view.state.tr, |
79 | | - dispatch: view.dispatch.bind(view), |
80 | | - }), |
81 | | - })), |
82 | | - [ |
83 | | - { |
84 | | - id: 'note-remove', |
85 | | - icon: {data: TrashBin}, |
86 | | - title: i18n('remove'), |
87 | | - type: ToolbarDataType.SingleButton, |
88 | | - isActive, |
89 | | - isEnable, |
90 | | - exec: () => |
91 | | - removeNode({ |
92 | | - pos: pos, |
93 | | - node: node, |
94 | | - tr: view.state.tr, |
95 | | - dispatch: view.dispatch.bind(view), |
96 | | - }), |
97 | | - }, |
98 | | - ], |
99 | | - ]} |
100 | | - /> |
| 18 | + <YfmNoteToolbar node={node} pos={pos} editorView={view} /> |
101 | 19 | ), |
102 | 20 | }); |
103 | 21 | }, |
|
0 commit comments