@pie-lib/editable-html-tip-tap 2.2.0-beta.8 → 3.0.0-next.20261002094057
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/dist/components/CharacterPicker.d.ts +31 -0
- package/dist/components/CharacterPicker.js +141 -0
- package/dist/components/EditableHtml.d.ts +11 -0
- package/dist/components/EditableHtml.js +331 -0
- package/dist/components/MenuBar.d.ts +11 -0
- package/dist/components/MenuBar.js +531 -0
- package/dist/components/TiptapContainer.d.ts +11 -0
- package/dist/components/TiptapContainer.js +167 -0
- package/dist/components/characters/characterUtils.d.ts +35 -0
- package/dist/components/characters/characterUtils.js +465 -0
- package/dist/components/characters/custom-popper.d.ts +14 -0
- package/dist/components/characters/custom-popper.js +32 -0
- package/dist/components/common/done-button.d.ts +30 -0
- package/dist/components/common/done-button.js +26 -0
- package/dist/components/common/toolbar-buttons.d.ts +38 -0
- package/dist/components/common/toolbar-buttons.js +96 -0
- package/dist/components/icons/CssIcon.d.ts +11 -0
- package/dist/components/icons/CssIcon.js +14 -0
- package/dist/components/icons/RespArea.d.ts +26 -0
- package/dist/components/icons/RespArea.js +42 -0
- package/dist/components/icons/TableIcons.d.ts +14 -0
- package/dist/components/icons/TableIcons.js +34 -0
- package/dist/components/icons/TextAlign.d.ts +18 -0
- package/dist/components/icons/TextAlign.js +143 -0
- package/dist/components/image/AltDialog.d.ts +22 -0
- package/dist/components/image/AltDialog.js +61 -0
- package/dist/components/image/ImageToolbar.d.ts +24 -0
- package/dist/components/image/ImageToolbar.js +80 -0
- package/dist/components/image/InsertImageHandler.d.ts +33 -0
- package/dist/components/image/InsertImageHandler.js +65 -0
- package/dist/components/image/findImageNode.d.ts +3 -0
- package/dist/components/image/findImageNode.js +11 -0
- package/dist/components/media/MediaDialog.d.ts +43 -0
- package/dist/components/media/MediaDialog.js +389 -0
- package/dist/components/media/MediaToolbar.d.ts +19 -0
- package/dist/components/media/MediaToolbar.js +41 -0
- package/dist/components/respArea/DragInTheBlank/DragInTheBlank.d.ts +23 -0
- package/dist/components/respArea/DragInTheBlank/DragInTheBlank.js +58 -0
- package/dist/components/respArea/DragInTheBlank/choice.d.ts +56 -0
- package/dist/components/respArea/DragInTheBlank/choice.js +157 -0
- package/dist/components/respArea/ExplicitConstructedResponse.d.ts +20 -0
- package/dist/components/respArea/ExplicitConstructedResponse.js +84 -0
- package/dist/components/respArea/InlineDropdown.d.ts +18 -0
- package/dist/components/respArea/InlineDropdown.js +126 -0
- package/dist/components/respArea/MathTemplated.d.ts +19 -0
- package/dist/components/respArea/MathTemplated.js +98 -0
- package/dist/components/respArea/ToolbarIcon.d.ts +14 -0
- package/dist/components/respArea/ToolbarIcon.js +17 -0
- package/dist/components/respArea/inlineDropdownUtils.d.ts +15 -0
- package/dist/components/respArea/inlineDropdownUtils.js +15 -0
- package/dist/constants.d.ts +13 -0
- package/dist/constants.js +4 -0
- package/dist/extensions/css.d.ts +11 -0
- package/dist/extensions/css.js +120 -0
- package/dist/extensions/custom-toolbar-wrapper.d.ts +11 -0
- package/dist/extensions/custom-toolbar-wrapper.js +61 -0
- package/dist/extensions/div-node.d.ts +10 -0
- package/dist/extensions/div-node.js +42 -0
- package/dist/extensions/ensure-empty-root-div.d.ts +14 -0
- package/dist/extensions/ensure-empty-root-div.js +24 -0
- package/dist/extensions/ensure-list-item-content-is-div.d.ts +15 -0
- package/dist/extensions/ensure-list-item-content-is-div.js +31 -0
- package/dist/extensions/extended-list-item.d.ts +13 -0
- package/dist/extensions/extended-list-item.js +5 -0
- package/dist/extensions/extended-table-cell.d.ts +10 -0
- package/dist/extensions/extended-table-cell.js +6 -0
- package/dist/extensions/extended-table.d.ts +17 -0
- package/dist/extensions/extended-table.js +34 -0
- package/dist/extensions/heading-paragraph.d.ts +17 -0
- package/dist/extensions/heading-paragraph.js +30 -0
- package/dist/extensions/image-component.d.ts +22 -0
- package/dist/extensions/image-component.js +223 -0
- package/dist/extensions/image.d.ts +10 -0
- package/dist/extensions/image.js +77 -0
- package/dist/extensions/index.d.ts +16 -0
- package/dist/extensions/index.js +64 -0
- package/dist/extensions/math.d.ts +15 -0
- package/dist/extensions/math.js +214 -0
- package/dist/extensions/media.d.ts +19 -0
- package/dist/extensions/media.js +149 -0
- package/dist/extensions/responseArea.d.ts +27 -0
- package/dist/extensions/responseArea.js +255 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +7 -0
- package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +16 -0
- package/dist/utils/helper.d.ts +9 -0
- package/dist/utils/helper.js +27 -0
- package/dist/utils/size.d.ts +9 -0
- package/dist/utils/size.js +14 -0
- package/dist/utils/toolbar.d.ts +10 -0
- package/dist/utils/toolbar.js +7 -0
- package/package.json +59 -43
- package/CHANGELOG.json +0 -32
- package/CHANGELOG.md +0 -2532
- package/lib/components/CharacterPicker.js +0 -226
- package/lib/components/CharacterPicker.js.map +0 -1
- package/lib/components/EditableHtml.js +0 -388
- package/lib/components/EditableHtml.js.map +0 -1
- package/lib/components/MenuBar.js +0 -702
- package/lib/components/MenuBar.js.map +0 -1
- package/lib/components/TiptapContainer.js +0 -242
- package/lib/components/TiptapContainer.js.map +0 -1
- package/lib/components/characters/characterUtils.js +0 -378
- package/lib/components/characters/characterUtils.js.map +0 -1
- package/lib/components/characters/custom-popper.js +0 -44
- package/lib/components/characters/custom-popper.js.map +0 -1
- package/lib/components/common/done-button.js +0 -34
- package/lib/components/common/done-button.js.map +0 -1
- package/lib/components/common/toolbar-buttons.js +0 -149
- package/lib/components/common/toolbar-buttons.js.map +0 -1
- package/lib/components/icons/CssIcon.js +0 -25
- package/lib/components/icons/CssIcon.js.map +0 -1
- package/lib/components/icons/RespArea.js +0 -72
- package/lib/components/icons/RespArea.js.map +0 -1
- package/lib/components/icons/TableIcons.js +0 -53
- package/lib/components/icons/TableIcons.js.map +0 -1
- package/lib/components/icons/TextAlign.js +0 -157
- package/lib/components/icons/TextAlign.js.map +0 -1
- package/lib/components/image/AltDialog.js +0 -98
- package/lib/components/image/AltDialog.js.map +0 -1
- package/lib/components/image/ImageToolbar.js +0 -137
- package/lib/components/image/ImageToolbar.js.map +0 -1
- package/lib/components/image/InsertImageHandler.js +0 -135
- package/lib/components/image/InsertImageHandler.js.map +0 -1
- package/lib/components/media/MediaDialog.js +0 -594
- package/lib/components/media/MediaDialog.js.map +0 -1
- package/lib/components/media/MediaToolbar.js +0 -74
- package/lib/components/media/MediaToolbar.js.map +0 -1
- package/lib/components/media/MediaWrapper.js +0 -67
- package/lib/components/media/MediaWrapper.js.map +0 -1
- package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js +0 -84
- package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js.map +0 -1
- package/lib/components/respArea/DragInTheBlank/choice.js +0 -253
- package/lib/components/respArea/DragInTheBlank/choice.js.map +0 -1
- package/lib/components/respArea/ExplicitConstructedResponse.js +0 -137
- package/lib/components/respArea/ExplicitConstructedResponse.js.map +0 -1
- package/lib/components/respArea/InlineDropdown.js +0 -223
- package/lib/components/respArea/InlineDropdown.js.map +0 -1
- package/lib/components/respArea/MathTemplated.js +0 -130
- package/lib/components/respArea/MathTemplated.js.map +0 -1
- package/lib/components/respArea/ToolbarIcon.js +0 -81
- package/lib/components/respArea/ToolbarIcon.js.map +0 -1
- package/lib/components/respArea/inlineDropdownUtils.js +0 -67
- package/lib/components/respArea/inlineDropdownUtils.js.map +0 -1
- package/lib/constants.js +0 -11
- package/lib/constants.js.map +0 -1
- package/lib/extensions/css.js +0 -227
- package/lib/extensions/css.js.map +0 -1
- package/lib/extensions/custom-toolbar-wrapper.js +0 -92
- package/lib/extensions/custom-toolbar-wrapper.js.map +0 -1
- package/lib/extensions/div-node.js +0 -83
- package/lib/extensions/div-node.js.map +0 -1
- package/lib/extensions/ensure-empty-root-div.js +0 -48
- package/lib/extensions/ensure-empty-root-div.js.map +0 -1
- package/lib/extensions/ensure-list-item-content-is-div.js +0 -64
- package/lib/extensions/ensure-list-item-content-is-div.js.map +0 -1
- package/lib/extensions/extended-list-item.js +0 -15
- package/lib/extensions/extended-list-item.js.map +0 -1
- package/lib/extensions/extended-table-cell.js +0 -22
- package/lib/extensions/extended-table-cell.js.map +0 -1
- package/lib/extensions/extended-table.js +0 -75
- package/lib/extensions/extended-table.js.map +0 -1
- package/lib/extensions/heading-paragraph.js +0 -61
- package/lib/extensions/heading-paragraph.js.map +0 -1
- package/lib/extensions/image-component.js +0 -351
- package/lib/extensions/image-component.js.map +0 -1
- package/lib/extensions/image.js +0 -134
- package/lib/extensions/image.js.map +0 -1
- package/lib/extensions/index.js +0 -46
- package/lib/extensions/index.js.map +0 -1
- package/lib/extensions/math.js +0 -469
- package/lib/extensions/math.js.map +0 -1
- package/lib/extensions/media.js +0 -243
- package/lib/extensions/media.js.map +0 -1
- package/lib/extensions/responseArea.js +0 -452
- package/lib/extensions/responseArea.js.map +0 -1
- package/lib/index.js +0 -37
- package/lib/index.js.map +0 -1
- package/lib/styles/editorContainerStyles.js +0 -137
- package/lib/styles/editorContainerStyles.js.map +0 -1
- package/lib/theme.js +0 -8
- package/lib/theme.js.map +0 -1
- package/lib/utils/helper.js +0 -73
- package/lib/utils/helper.js.map +0 -1
- package/lib/utils/size.js +0 -26
- package/lib/utils/size.js.map +0 -1
- package/lib/utils/toolbar.js +0 -19
- package/lib/utils/toolbar.js.map +0 -1
- package/src/__tests__/EditableHtml.test.jsx +0 -588
- package/src/__tests__/constants.test.js +0 -19
- package/src/__tests__/div-to-paragraph-conversion.test.jsx +0 -125
- package/src/__tests__/extensions.test.js +0 -208
- package/src/__tests__/index.test.jsx +0 -154
- package/src/__tests__/size-utils.test.js +0 -64
- package/src/__tests__/theme.test.js +0 -17
- package/src/components/CharacterPicker.jsx +0 -237
- package/src/components/EditableHtml.jsx +0 -458
- package/src/components/MenuBar.jsx +0 -561
- package/src/components/TiptapContainer.jsx +0 -235
- package/src/components/__tests__/AltDialog.test.jsx +0 -147
- package/src/components/__tests__/CharacterPicker.test.jsx +0 -270
- package/src/components/__tests__/CssIcon.test.jsx +0 -46
- package/src/components/__tests__/DragInTheBlank.test.jsx +0 -255
- package/src/components/__tests__/ExplicitConstructedResponse.test.jsx +0 -209
- package/src/components/__tests__/ImageToolbar.test.jsx +0 -128
- package/src/components/__tests__/InlineDropdown.test.jsx +0 -557
- package/src/components/__tests__/InsertImageHandler.test.js +0 -161
- package/src/components/__tests__/MediaDialog.test.jsx +0 -293
- package/src/components/__tests__/MediaToolbar.test.jsx +0 -74
- package/src/components/__tests__/MediaWrapper.test.jsx +0 -81
- package/src/components/__tests__/MenuBar.test.jsx +0 -250
- package/src/components/__tests__/RespArea.test.jsx +0 -122
- package/src/components/__tests__/TableIcons.test.jsx +0 -149
- package/src/components/__tests__/TextAlign.test.jsx +0 -167
- package/src/components/__tests__/TiptapContainer.test.jsx +0 -138
- package/src/components/__tests__/characterUtils.test.js +0 -166
- package/src/components/__tests__/choice.test.jsx +0 -171
- package/src/components/__tests__/custom-popper.test.jsx +0 -82
- package/src/components/__tests__/done-button.test.jsx +0 -54
- package/src/components/__tests__/toolbar-buttons.test.jsx +0 -234
- package/src/components/characters/characterUtils.js +0 -447
- package/src/components/characters/custom-popper.js +0 -38
- package/src/components/common/done-button.jsx +0 -27
- package/src/components/common/toolbar-buttons.jsx +0 -127
- package/src/components/icons/CssIcon.jsx +0 -15
- package/src/components/icons/RespArea.jsx +0 -71
- package/src/components/icons/TableIcons.jsx +0 -52
- package/src/components/icons/TextAlign.jsx +0 -114
- package/src/components/image/AltDialog.jsx +0 -82
- package/src/components/image/ImageToolbar.jsx +0 -99
- package/src/components/image/InsertImageHandler.js +0 -107
- package/src/components/media/MediaDialog.jsx +0 -596
- package/src/components/media/MediaToolbar.jsx +0 -49
- package/src/components/media/MediaWrapper.jsx +0 -39
- package/src/components/respArea/DragInTheBlank/DragInTheBlank.jsx +0 -76
- package/src/components/respArea/DragInTheBlank/__tests__/choice.test.jsx +0 -72
- package/src/components/respArea/DragInTheBlank/choice.jsx +0 -259
- package/src/components/respArea/ExplicitConstructedResponse.jsx +0 -136
- package/src/components/respArea/InlineDropdown.jsx +0 -240
- package/src/components/respArea/MathTemplated.jsx +0 -124
- package/src/components/respArea/ToolbarIcon.jsx +0 -66
- package/src/components/respArea/__tests__/MathTemplated.test.jsx +0 -210
- package/src/components/respArea/inlineDropdownUtils.js +0 -79
- package/src/constants.js +0 -5
- package/src/extensions/__tests__/css.test.js +0 -196
- package/src/extensions/__tests__/custom-toolbar-wrapper.test.jsx +0 -180
- package/src/extensions/__tests__/divNode.test.js +0 -87
- package/src/extensions/__tests__/ensure-empty-root-div.test.js +0 -57
- package/src/extensions/__tests__/ensure-list-item-content-is-div.test.js +0 -44
- package/src/extensions/__tests__/extended-list-item.test.js +0 -13
- package/src/extensions/__tests__/extended-table-cell.test.js +0 -22
- package/src/extensions/__tests__/extended-table.test.js +0 -183
- package/src/extensions/__tests__/image-component.test.jsx +0 -346
- package/src/extensions/__tests__/image.test.js +0 -237
- package/src/extensions/__tests__/math.test.js +0 -900
- package/src/extensions/__tests__/media-node-view.test.jsx +0 -298
- package/src/extensions/__tests__/media.test.js +0 -271
- package/src/extensions/__tests__/responseArea.test.js +0 -655
- package/src/extensions/css.js +0 -233
- package/src/extensions/custom-toolbar-wrapper.jsx +0 -78
- package/src/extensions/div-node.js +0 -86
- package/src/extensions/ensure-empty-root-div.js +0 -47
- package/src/extensions/ensure-list-item-content-is-div.js +0 -62
- package/src/extensions/extended-list-item.js +0 -10
- package/src/extensions/extended-table-cell.js +0 -19
- package/src/extensions/extended-table.js +0 -60
- package/src/extensions/heading-paragraph.js +0 -53
- package/src/extensions/image-component.jsx +0 -340
- package/src/extensions/image.js +0 -109
- package/src/extensions/index.js +0 -81
- package/src/extensions/math.js +0 -454
- package/src/extensions/media.js +0 -188
- package/src/extensions/responseArea.js +0 -407
- package/src/index.jsx +0 -5
- package/src/styles/editorContainerStyles.js +0 -145
- package/src/theme.js +0 -1
- package/src/utils/__tests__/helper.test.js +0 -126
- package/src/utils/__tests__/toolbar.test.js +0 -43
- package/src/utils/helper.js +0 -69
- package/src/utils/size.js +0 -32
- package/src/utils/toolbar.js +0 -15
package/src/extensions/math.js
DELETED
|
@@ -1,454 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
-
import ReactDOM from 'react-dom';
|
|
3
|
-
import { Node } from '@tiptap/core';
|
|
4
|
-
import { NodeViewWrapper, ReactNodeViewRenderer } from '@tiptap/react';
|
|
5
|
-
import { NodeSelection, Plugin, PluginKey, TextSelection } from 'prosemirror-state';
|
|
6
|
-
import { styled } from '@mui/material/styles';
|
|
7
|
-
import { MathPreview, MathToolbar } from '@pie-lib/math-toolbar';
|
|
8
|
-
import { wrapMath } from '@pie-lib/math-rendering';
|
|
9
|
-
import { setToolbarOpened } from '../utils/toolbar';
|
|
10
|
-
|
|
11
|
-
const ensureTextAfterMathPluginKey = new PluginKey('ensureTextAfterMath');
|
|
12
|
-
|
|
13
|
-
const generateAdditionalKeys = (keyData = []) => {
|
|
14
|
-
return keyData.map((key) => ({
|
|
15
|
-
name: key,
|
|
16
|
-
latex: key,
|
|
17
|
-
write: key,
|
|
18
|
-
label: key,
|
|
19
|
-
}));
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export const EnsureTextAfterMathPlugin = (mathNodeName) =>
|
|
23
|
-
new Plugin({
|
|
24
|
-
key: ensureTextAfterMathPluginKey,
|
|
25
|
-
appendTransaction: (transactions, oldState, newState) => {
|
|
26
|
-
// Only act when the doc actually changed
|
|
27
|
-
if (!transactions.some((tr) => tr.docChanged)) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const tr = newState.tr;
|
|
32
|
-
let changed = false;
|
|
33
|
-
|
|
34
|
-
newState.doc.descendants((node, pos) => {
|
|
35
|
-
if (node.type.name === mathNodeName) {
|
|
36
|
-
const nextPos = pos + node.nodeSize;
|
|
37
|
-
const nextNode = newState.doc.nodeAt(nextPos);
|
|
38
|
-
|
|
39
|
-
// If there's no node after, or the next node isn't text, insert a space
|
|
40
|
-
if (!nextNode || nextNode.type.name !== 'text') {
|
|
41
|
-
tr.insert(nextPos, newState.schema.text('\u200b'));
|
|
42
|
-
changed = true;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
return changed ? tr : null;
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
const nodeBeforeZeroWidthSpace = (doc, from) => {
|
|
52
|
-
let i;
|
|
53
|
-
|
|
54
|
-
// finding if previous to the cursor there's a zero-width space
|
|
55
|
-
// and a non-text element, and deleting everything until the space
|
|
56
|
-
for (i = from; i > 0; i--) {
|
|
57
|
-
const currentDoc = doc.nodeAt(i);
|
|
58
|
-
|
|
59
|
-
if (currentDoc?.type?.name === 'text' && currentDoc.textContent !== '\u200b') {
|
|
60
|
-
return -1;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (currentDoc && currentDoc?.type?.name !== 'text') {
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return i;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export const ZeroWidthSpaceHandlingPlugin = new Plugin({
|
|
72
|
-
key: new PluginKey('zeroWidthSpaceHandling'),
|
|
73
|
-
props: {
|
|
74
|
-
handleKeyDown(view, event) {
|
|
75
|
-
const { state, dispatch } = view;
|
|
76
|
-
const { selection, doc } = state;
|
|
77
|
-
const { from, empty } = selection;
|
|
78
|
-
|
|
79
|
-
if (empty && event.key === 'Backspace' && from > 0) {
|
|
80
|
-
const start = nodeBeforeZeroWidthSpace(doc, from);
|
|
81
|
-
|
|
82
|
-
if (start === -1) {
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const tr = state.tr.delete(start, from);
|
|
87
|
-
dispatch(tr);
|
|
88
|
-
return true; // handled
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (empty && event.key === 'ArrowLeft' && from > 0) {
|
|
92
|
-
const start = nodeBeforeZeroWidthSpace(doc, from);
|
|
93
|
-
|
|
94
|
-
if (start === -1) {
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const resolved = state.doc.resolve(start);
|
|
99
|
-
const maybeNode = resolved.nodeAfter || resolved.nodeBefore;
|
|
100
|
-
|
|
101
|
-
// Check if there's an inline selectable node (e.g., your math node)
|
|
102
|
-
if (maybeNode) {
|
|
103
|
-
const nodeResolved = state.doc.resolve(start);
|
|
104
|
-
const tr = state.tr.setSelection(NodeSelection.create(state.doc, nodeResolved.pos));
|
|
105
|
-
dispatch(tr);
|
|
106
|
-
return true;
|
|
107
|
-
} else {
|
|
108
|
-
// Just move the text cursor before the zwsp
|
|
109
|
-
const tr = state.tr.setSelection(TextSelection.create(state.doc, from - 2));
|
|
110
|
-
dispatch(tr);
|
|
111
|
-
return true;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return false;
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
const StyledMathNodeWrapper = styled(NodeViewWrapper, {
|
|
121
|
-
shouldForwardProp: (prop) => prop !== 'selected',
|
|
122
|
-
})(({ theme, selected }) => ({
|
|
123
|
-
display: 'inline-flex',
|
|
124
|
-
cursor: 'pointer',
|
|
125
|
-
margin: '0 4px',
|
|
126
|
-
'&:not(:has(.ML__latex))': {
|
|
127
|
-
border: 'solid 1px lightgrey',
|
|
128
|
-
padding: '5px',
|
|
129
|
-
},
|
|
130
|
-
...(selected && {
|
|
131
|
-
border: `solid 1px ${theme.palette.primary.main}`,
|
|
132
|
-
}),
|
|
133
|
-
}));
|
|
134
|
-
|
|
135
|
-
export const MathNode = Node.create({
|
|
136
|
-
name: 'math',
|
|
137
|
-
group: 'inline',
|
|
138
|
-
inline: true,
|
|
139
|
-
atom: true,
|
|
140
|
-
|
|
141
|
-
addAttributes() {
|
|
142
|
-
return {
|
|
143
|
-
latex: { default: '' },
|
|
144
|
-
wrapper: { default: null },
|
|
145
|
-
html: { default: null },
|
|
146
|
-
};
|
|
147
|
-
},
|
|
148
|
-
|
|
149
|
-
addProseMirrorPlugins() {
|
|
150
|
-
return [EnsureTextAfterMathPlugin(this.name), ZeroWidthSpaceHandlingPlugin];
|
|
151
|
-
},
|
|
152
|
-
|
|
153
|
-
parseHTML() {
|
|
154
|
-
return [
|
|
155
|
-
{
|
|
156
|
-
tag: 'span[data-latex]',
|
|
157
|
-
getAttrs: (el) => ({
|
|
158
|
-
latex: el.getAttribute('data-raw') || el.textContent,
|
|
159
|
-
}),
|
|
160
|
-
},
|
|
161
|
-
{
|
|
162
|
-
tag: 'span[data-type="mathml"]',
|
|
163
|
-
getAttrs: (el) => ({
|
|
164
|
-
html: el.innerHTML,
|
|
165
|
-
}),
|
|
166
|
-
},
|
|
167
|
-
];
|
|
168
|
-
},
|
|
169
|
-
|
|
170
|
-
addCommands() {
|
|
171
|
-
return {
|
|
172
|
-
insertMath:
|
|
173
|
-
(latex = '') =>
|
|
174
|
-
({ tr, editor, dispatch }) => {
|
|
175
|
-
const { state } = editor.view;
|
|
176
|
-
const node = state.schema.nodes.math.create({
|
|
177
|
-
latex,
|
|
178
|
-
});
|
|
179
|
-
const { selection } = state;
|
|
180
|
-
|
|
181
|
-
// The inserted node is typically just before the cursor
|
|
182
|
-
const pos = selection.$from.pos;
|
|
183
|
-
|
|
184
|
-
tr.insert(pos, node);
|
|
185
|
-
|
|
186
|
-
if (node?.type?.name === this.name) {
|
|
187
|
-
// Create a NodeSelection from the current doc
|
|
188
|
-
const sel = NodeSelection.create(tr.doc, selection.$from.pos);
|
|
189
|
-
|
|
190
|
-
// Build a fresh transaction from the current state and set the selection
|
|
191
|
-
tr.setSelection(sel);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
dispatch(tr);
|
|
195
|
-
|
|
196
|
-
setToolbarOpened(editor, true);
|
|
197
|
-
return true;
|
|
198
|
-
},
|
|
199
|
-
};
|
|
200
|
-
},
|
|
201
|
-
|
|
202
|
-
renderHTML({ HTMLAttributes }) {
|
|
203
|
-
if (HTMLAttributes.html) {
|
|
204
|
-
return ['span', { 'data-type': 'mathml', dangerouslySetInnerHTML: { __html: HTMLAttributes.html } }];
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
return [
|
|
208
|
-
'span',
|
|
209
|
-
{ 'data-latex': '', 'data-raw': HTMLAttributes.latex },
|
|
210
|
-
wrapMath(HTMLAttributes.latex, HTMLAttributes.wrapper),
|
|
211
|
-
];
|
|
212
|
-
},
|
|
213
|
-
|
|
214
|
-
addNodeView() {
|
|
215
|
-
return ReactNodeViewRenderer((props) => <MathNodeView {...{ ...props, options: this.options }} />);
|
|
216
|
-
},
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
export const MathNodeView = (props) => {
|
|
220
|
-
const { node, updateAttributes, editor, selected, options, getPos } = props;
|
|
221
|
-
const [showToolbar, setShowToolbar] = useState(selected);
|
|
222
|
-
const toolbarRef = useRef(null);
|
|
223
|
-
const nodeRef = useRef(null);
|
|
224
|
-
const timestamp = useRef(Date.now());
|
|
225
|
-
const [position, setPosition] = useState({ top: 0, left: 0 });
|
|
226
|
-
const { math: mathOptions = {} } = options || {};
|
|
227
|
-
const {
|
|
228
|
-
keypadMode,
|
|
229
|
-
controlledKeypadMode = true,
|
|
230
|
-
customKeys = [],
|
|
231
|
-
keyPadCharacterRef,
|
|
232
|
-
setKeypadInteraction,
|
|
233
|
-
} = mathOptions;
|
|
234
|
-
|
|
235
|
-
const latex = node.attrs.latex || '';
|
|
236
|
-
|
|
237
|
-
const handleChange = (newLatex) => {
|
|
238
|
-
updateAttributes({ latex: newLatex });
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
// moveCursorAfterNode is set explicitly by the caller (not inferred from
|
|
242
|
-
// editor.state.selection: every keystroke while editing already calls
|
|
243
|
-
// updateAttributes, which replaces this node's content and — per a
|
|
244
|
-
// ProseMirror mapping quirk — collapses any NodeSelection on it into a
|
|
245
|
-
// plain TextSelection right away, so the live selection can't be trusted
|
|
246
|
-
// to still describe this node by the time handleDone runs).
|
|
247
|
-
//
|
|
248
|
-
// - Check icon: always move the cursor to just after this node.
|
|
249
|
-
// - Clicking elsewhere in the editable content while the toolbar was
|
|
250
|
-
// open (see handleClickOutside): leave the cursor where the user
|
|
251
|
-
// actually clicked instead of overriding it.
|
|
252
|
-
const handleDone = (newLatex, { moveCursorAfterNode = true } = {}) => {
|
|
253
|
-
updateAttributes({ latex: newLatex });
|
|
254
|
-
setShowToolbar(false);
|
|
255
|
-
|
|
256
|
-
if (moveCursorAfterNode && typeof getPos === 'function') {
|
|
257
|
-
const pos = getPos();
|
|
258
|
-
const { doc } = editor.state;
|
|
259
|
-
const sel = TextSelection.create(doc, pos + node.nodeSize);
|
|
260
|
-
const tr = editor.state.tr.setSelection(sel);
|
|
261
|
-
editor.view.dispatch(tr);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
editor.commands.focus();
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
// Only open the toolbar when this node is *explicitly* selected
|
|
268
|
-
// via a NodeSelection — not when it's merely included in a broader
|
|
269
|
-
// TextSelection or AllSelection (e.g. click-drag across math, or Cmd+A).
|
|
270
|
-
useEffect(() => {
|
|
271
|
-
if (!selected) return;
|
|
272
|
-
|
|
273
|
-
const { selection } = editor.state;
|
|
274
|
-
const isNodeSelected = selection.node?.type?.name === 'math';
|
|
275
|
-
|
|
276
|
-
if (isNodeSelected) {
|
|
277
|
-
setShowToolbar(true);
|
|
278
|
-
}
|
|
279
|
-
}, [selected, editor]);
|
|
280
|
-
|
|
281
|
-
useEffect(() => {
|
|
282
|
-
setToolbarOpened(editor, selected || showToolbar);
|
|
283
|
-
}, [editor, showToolbar, selected]);
|
|
284
|
-
|
|
285
|
-
useEffect(() => {
|
|
286
|
-
if (!editor || !showToolbar) {
|
|
287
|
-
setPosition({ top: 0, left: 0 });
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
// Clamp in viewport coordinates, then convert to portal-container-relative values
|
|
292
|
-
// for position: absolute (toolbar is portaled into _tiptapContainerEl or document.body).
|
|
293
|
-
const updatePosition = () => {
|
|
294
|
-
if (!toolbarRef.current) {
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
const { from } = editor.state.selection;
|
|
299
|
-
const start = editor.view.coordsAtPos(from);
|
|
300
|
-
const nodeRect = nodeRef.current?.getBoundingClientRect?.();
|
|
301
|
-
|
|
302
|
-
// Anchor to the math node element when available; fall back to selection coords.
|
|
303
|
-
const anchorTop = nodeRect?.height ? nodeRect.top : start.top;
|
|
304
|
-
const anchorLeft = nodeRect?.width ? nodeRect.left : start.left;
|
|
305
|
-
const anchorBottom = nodeRect?.height ? nodeRect.bottom : (start.bottom ?? start.top);
|
|
306
|
-
|
|
307
|
-
const toolbarHeight = toolbarRef.current.offsetHeight;
|
|
308
|
-
const toolbarWidth = toolbarRef.current.offsetWidth;
|
|
309
|
-
|
|
310
|
-
const gap = 0;
|
|
311
|
-
const spaceBelow = window.innerHeight - (anchorBottom + gap);
|
|
312
|
-
|
|
313
|
-
// Place the toolbar's top-left corner directly below the anchor; flip above when needed.
|
|
314
|
-
let top = spaceBelow >= toolbarHeight ? anchorBottom + gap : anchorTop - toolbarHeight - gap;
|
|
315
|
-
let left = anchorLeft;
|
|
316
|
-
|
|
317
|
-
const margin = 8;
|
|
318
|
-
top = Math.max(margin, Math.min(top, window.innerHeight - toolbarHeight - margin));
|
|
319
|
-
left = Math.max(margin, Math.min(left, window.innerWidth - toolbarWidth - margin));
|
|
320
|
-
|
|
321
|
-
const portalEl = editor._tiptapContainerEl || document.body;
|
|
322
|
-
const containerRect = portalEl.getBoundingClientRect();
|
|
323
|
-
|
|
324
|
-
setPosition({
|
|
325
|
-
top: top - containerRect.top,
|
|
326
|
-
left: left - containerRect.left,
|
|
327
|
-
});
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
updatePosition();
|
|
331
|
-
|
|
332
|
-
let frame = null;
|
|
333
|
-
const scheduleUpdate = () => {
|
|
334
|
-
if (frame !== null) {
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
frame = requestAnimationFrame(() => {
|
|
339
|
-
frame = null;
|
|
340
|
-
updatePosition();
|
|
341
|
-
});
|
|
342
|
-
};
|
|
343
|
-
|
|
344
|
-
frame = requestAnimationFrame(() => {
|
|
345
|
-
frame = null;
|
|
346
|
-
updatePosition();
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
window.addEventListener('scroll', scheduleUpdate, true);
|
|
350
|
-
window.addEventListener('resize', scheduleUpdate);
|
|
351
|
-
|
|
352
|
-
return () => {
|
|
353
|
-
if (frame !== null) {
|
|
354
|
-
cancelAnimationFrame(frame);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
window.removeEventListener('scroll', scheduleUpdate, true);
|
|
358
|
-
window.removeEventListener('resize', scheduleUpdate);
|
|
359
|
-
};
|
|
360
|
-
}, [editor, showToolbar]);
|
|
361
|
-
|
|
362
|
-
useEffect(() => {
|
|
363
|
-
const handleClickOutside = (event) => {
|
|
364
|
-
const target = event?.target;
|
|
365
|
-
|
|
366
|
-
// MUI's `Select` renders its dropdown options in a portal attached to `document.body`.
|
|
367
|
-
// Those clicks should not dismiss the math toolbar.
|
|
368
|
-
const equationEditorListboxes =
|
|
369
|
-
document.querySelectorAll?.(
|
|
370
|
-
'[id^="equation-editor-select"][id*="listbox"], [aria-labelledby="equation-editor-label"][role="listbox"]',
|
|
371
|
-
) || [];
|
|
372
|
-
|
|
373
|
-
const equationEditorPopoverOpen = equationEditorListboxes.length > 0;
|
|
374
|
-
const clickedEquationEditorSelect =
|
|
375
|
-
!!(target?.id && target.id.includes('equation-editor-select')) ||
|
|
376
|
-
!!target?.closest?.('[id*="equation-editor-select"]');
|
|
377
|
-
|
|
378
|
-
// If the click originated from the math node preview itself (the element
|
|
379
|
-
// that opens the toolbar), ignore it here — the node's own onClick handler
|
|
380
|
-
// will keep/re-open the toolbar. Without this guard, closing and then
|
|
381
|
-
// immediately clicking the math node would fire this listener in the same
|
|
382
|
-
// event cycle and close the toolbar before it could open.
|
|
383
|
-
const clickedMathNode = !!target?.closest?.(`.math-node-${timestamp.current}`);
|
|
384
|
-
|
|
385
|
-
if (
|
|
386
|
-
toolbarRef.current &&
|
|
387
|
-
!toolbarRef.current.contains(target) &&
|
|
388
|
-
!target?.closest?.('[data-inline-node]') &&
|
|
389
|
-
!equationEditorPopoverOpen &&
|
|
390
|
-
!clickedEquationEditorSelect &&
|
|
391
|
-
!clickedMathNode
|
|
392
|
-
) {
|
|
393
|
-
setShowToolbar(false);
|
|
394
|
-
|
|
395
|
-
// If the click landed inside the editable content itself, respect
|
|
396
|
-
// it and leave the cursor where the user clicked. If it landed
|
|
397
|
-
// fully outside the editor (e.g. on other page UI), there's no
|
|
398
|
-
// click position to preserve — falling back to "leave selection
|
|
399
|
-
// untouched" there renders the browser's native NodeSelection
|
|
400
|
-
// fallback caret at the start of the node, so explicitly move the
|
|
401
|
-
// cursor after it instead, same as the check-icon path.
|
|
402
|
-
const clickedInsideEditableContent = !!editor?.view?.dom?.contains(target);
|
|
403
|
-
handleDone(node.attrs.latex, { moveCursorAfterNode: !clickedInsideEditableContent });
|
|
404
|
-
}
|
|
405
|
-
};
|
|
406
|
-
|
|
407
|
-
if (showToolbar) {
|
|
408
|
-
// Use `click` (not `mousedown`) so interacting with browser UI like the scrollbar
|
|
409
|
-
// doesn't automatically dismiss the math toolbar.
|
|
410
|
-
document.addEventListener('click', handleClickOutside);
|
|
411
|
-
} else {
|
|
412
|
-
document.removeEventListener('click', handleClickOutside);
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
return () => document.removeEventListener('click', handleClickOutside);
|
|
416
|
-
}, [editor, showToolbar, node]);
|
|
417
|
-
|
|
418
|
-
return (
|
|
419
|
-
<StyledMathNodeWrapper className={`math-node-${timestamp.current}`} selected={selected} data-selected={selected}>
|
|
420
|
-
<div ref={nodeRef} onClick={() => setShowToolbar(true)} contentEditable={false}>
|
|
421
|
-
<MathPreview latex={latex} isSelected={selected} outlineOnWrapper />
|
|
422
|
-
</div>
|
|
423
|
-
{showToolbar &&
|
|
424
|
-
ReactDOM.createPortal(
|
|
425
|
-
<div
|
|
426
|
-
ref={toolbarRef}
|
|
427
|
-
data-toolbar-for={editor.instanceId}
|
|
428
|
-
style={{
|
|
429
|
-
position: 'absolute',
|
|
430
|
-
top: `${position.top}px`,
|
|
431
|
-
left: `${position.left}px`,
|
|
432
|
-
zIndex: 1000,
|
|
433
|
-
background: 'var(--editable-html-toolbar-bg, #efefef)',
|
|
434
|
-
boxShadow:
|
|
435
|
-
'0px 1px 5px 0px rgba(0, 0, 0, 0.2), 0px 2px 2px 0px rgba(0, 0, 0, 0.14), 0px 3px 1px -2px rgba(0, 0, 0, 0.12)',
|
|
436
|
-
}}
|
|
437
|
-
>
|
|
438
|
-
<MathToolbar
|
|
439
|
-
latex={latex}
|
|
440
|
-
autoFocus
|
|
441
|
-
onChange={handleChange}
|
|
442
|
-
onDone={handleDone}
|
|
443
|
-
keypadMode={keypadMode}
|
|
444
|
-
controlledKeypadMode={controlledKeypadMode}
|
|
445
|
-
additionalKeys={generateAdditionalKeys(customKeys)}
|
|
446
|
-
keyPadCharacterRef={keyPadCharacterRef}
|
|
447
|
-
setKeypadInteraction={setKeypadInteraction}
|
|
448
|
-
/>
|
|
449
|
-
</div>,
|
|
450
|
-
editor?._tiptapContainerEl || document.body,
|
|
451
|
-
)}
|
|
452
|
-
</StyledMathNodeWrapper>
|
|
453
|
-
);
|
|
454
|
-
};
|
package/src/extensions/media.js
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import React, { useEffect } from 'react';
|
|
2
|
-
import ReactDOM from 'react-dom';
|
|
3
|
-
import { mergeAttributes, Node } from '@tiptap/core';
|
|
4
|
-
import { NodeViewWrapper, ReactNodeViewRenderer } from '@tiptap/react';
|
|
5
|
-
import MediaDialog from '../components/media/MediaDialog';
|
|
6
|
-
import MediaToolbar from '../components/media/MediaToolbar';
|
|
7
|
-
|
|
8
|
-
export const Media = Node.create({
|
|
9
|
-
name: 'media',
|
|
10
|
-
group: 'inline',
|
|
11
|
-
inline: true,
|
|
12
|
-
atom: true,
|
|
13
|
-
|
|
14
|
-
addAttributes() {
|
|
15
|
-
return {
|
|
16
|
-
type: { default: 'video' },
|
|
17
|
-
src: { default: null },
|
|
18
|
-
width: { default: null },
|
|
19
|
-
height: { default: null },
|
|
20
|
-
title: { default: null },
|
|
21
|
-
starts: { default: null },
|
|
22
|
-
ends: { default: null },
|
|
23
|
-
editing: { default: false },
|
|
24
|
-
tag: { default: 'iframe' }, // 'iframe' or 'audio'
|
|
25
|
-
url: { default: null },
|
|
26
|
-
};
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
parseHTML() {
|
|
30
|
-
return [
|
|
31
|
-
{
|
|
32
|
-
tag: 'iframe[data-type="video"]',
|
|
33
|
-
getAttrs: (el) => ({
|
|
34
|
-
type: 'video',
|
|
35
|
-
tag: 'iframe',
|
|
36
|
-
src: el.getAttribute('src'),
|
|
37
|
-
width: el.getAttribute('width'),
|
|
38
|
-
height: el.getAttribute('height'),
|
|
39
|
-
title: el.dataset.title,
|
|
40
|
-
starts: el.dataset.starts,
|
|
41
|
-
ends: el.dataset.ends,
|
|
42
|
-
url: el.dataset.url,
|
|
43
|
-
}),
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
tag: 'audio',
|
|
47
|
-
getAttrs: (el) => ({
|
|
48
|
-
type: 'audio',
|
|
49
|
-
tag: 'audio',
|
|
50
|
-
src: el.querySelector('source')?.getAttribute('src'),
|
|
51
|
-
}),
|
|
52
|
-
},
|
|
53
|
-
];
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
renderHTML({ HTMLAttributes }) {
|
|
57
|
-
const { tag, src, width, height } = HTMLAttributes;
|
|
58
|
-
|
|
59
|
-
if (tag === 'audio') {
|
|
60
|
-
return ['audio', { controls: 'controls', controlsList: 'nodownload' }, ['source', { src, type: 'audio/mp3' }]];
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return [
|
|
64
|
-
'iframe',
|
|
65
|
-
mergeAttributes(
|
|
66
|
-
{
|
|
67
|
-
'data-type': 'video',
|
|
68
|
-
frameborder: '0',
|
|
69
|
-
allow: 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture',
|
|
70
|
-
allowfullscreen: '',
|
|
71
|
-
src,
|
|
72
|
-
},
|
|
73
|
-
width ? { width } : {},
|
|
74
|
-
height ? { height } : {},
|
|
75
|
-
),
|
|
76
|
-
];
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
addCommands() {
|
|
80
|
-
return {
|
|
81
|
-
insertMedia:
|
|
82
|
-
(attrs) =>
|
|
83
|
-
({ commands }) => {
|
|
84
|
-
return commands.insertContent({ type: this.name, attrs });
|
|
85
|
-
},
|
|
86
|
-
updateMedia:
|
|
87
|
-
(attrs) =>
|
|
88
|
-
({ commands }) => {
|
|
89
|
-
return commands.updateAttributes(this.name, attrs);
|
|
90
|
-
},
|
|
91
|
-
};
|
|
92
|
-
},
|
|
93
|
-
|
|
94
|
-
addNodeView() {
|
|
95
|
-
return ReactNodeViewRenderer((props) => <MediaNodeView {...{ ...props, options: this.options }} />);
|
|
96
|
-
},
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
const removeDialogs = () => {
|
|
100
|
-
const prevDialogs = document.querySelectorAll('.insert-media-dialog');
|
|
101
|
-
|
|
102
|
-
prevDialogs.forEach((s) => s.remove());
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
export const insertDialog = (props) => {
|
|
106
|
-
const newEl = document.createElement('div');
|
|
107
|
-
const { type, callback, options, ...rest } = props;
|
|
108
|
-
const initialBodyOverflow = document.body.style.overflow;
|
|
109
|
-
|
|
110
|
-
removeDialogs();
|
|
111
|
-
|
|
112
|
-
newEl.className = 'insert-media-dialog';
|
|
113
|
-
document.body.style.overflow = 'hidden';
|
|
114
|
-
|
|
115
|
-
const handleClose = (val, data) => {
|
|
116
|
-
callback(val, data);
|
|
117
|
-
newEl.remove();
|
|
118
|
-
document.body.style.overflow = initialBodyOverflow;
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
const el = (
|
|
122
|
-
<MediaDialog
|
|
123
|
-
{...rest}
|
|
124
|
-
uploadSoundSupport={options.uploadSoundSupport}
|
|
125
|
-
type={type}
|
|
126
|
-
disablePortal={true}
|
|
127
|
-
open={true}
|
|
128
|
-
handleClose={handleClose}
|
|
129
|
-
/>
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
ReactDOM.render(el, newEl);
|
|
133
|
-
|
|
134
|
-
document.body.appendChild(newEl);
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
export default function MediaNodeView({ editor, node, updateAttributes, deleteNode, options }) {
|
|
138
|
-
const { type, src, width, height, tag } = node.attrs;
|
|
139
|
-
|
|
140
|
-
const handleEdit = () => {
|
|
141
|
-
insertDialog({
|
|
142
|
-
...node.attrs,
|
|
143
|
-
options: options,
|
|
144
|
-
edit: true,
|
|
145
|
-
callback: (val, data) => {
|
|
146
|
-
if (val) {
|
|
147
|
-
updateAttributes(data);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
editor.chain().focus().run();
|
|
151
|
-
},
|
|
152
|
-
});
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
useEffect(() => {
|
|
156
|
-
// Only open dialog for newly inserted media without a src
|
|
157
|
-
if (!src) {
|
|
158
|
-
insertDialog({
|
|
159
|
-
...node.attrs,
|
|
160
|
-
options: options,
|
|
161
|
-
edit: true,
|
|
162
|
-
callback: (val, data) => {
|
|
163
|
-
if (val) {
|
|
164
|
-
updateAttributes(data);
|
|
165
|
-
} else {
|
|
166
|
-
deleteNode();
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
editor.chain().focus().run();
|
|
170
|
-
},
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
}, []);
|
|
174
|
-
|
|
175
|
-
return (
|
|
176
|
-
<NodeViewWrapper data-type={type} style={{ width, height }}>
|
|
177
|
-
{tag === 'audio' ? (
|
|
178
|
-
<audio controls controlsList="nodownload">
|
|
179
|
-
<source type="audio/mp3" src={src} />
|
|
180
|
-
</audio>
|
|
181
|
-
) : (
|
|
182
|
-
<iframe src={src} allowFullScreen frameBorder="0" width={width} height={height} />
|
|
183
|
-
)}
|
|
184
|
-
|
|
185
|
-
<MediaToolbar onEdit={handleEdit} onRemove={deleteNode} />
|
|
186
|
-
</NodeViewWrapper>
|
|
187
|
-
);
|
|
188
|
-
}
|