@pie-lib/editable-html-tip-tap 0.1.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/dist/components/CharacterPicker.d.ts +31 -0
- package/dist/components/CharacterPicker.d.ts.map +1 -0
- package/dist/components/CharacterPicker.js +129 -0
- package/dist/components/EditableHtml.d.ts +11 -0
- package/dist/components/EditableHtml.d.ts.map +1 -0
- package/dist/components/EditableHtml.js +270 -0
- package/dist/components/MenuBar.d.ts +11 -0
- package/dist/components/MenuBar.d.ts.map +1 -0
- package/dist/components/MenuBar.js +460 -0
- package/dist/components/TiptapContainer.d.ts +11 -0
- package/dist/components/TiptapContainer.d.ts.map +1 -0
- package/dist/components/TiptapContainer.js +157 -0
- package/dist/components/characters/characterUtils.d.ts +36 -0
- package/dist/components/characters/characterUtils.d.ts.map +1 -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.d.ts.map +1 -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.d.ts.map +1 -0
- package/dist/components/common/done-button.js +26 -0
- package/dist/components/common/toolbar-buttons.d.ts +39 -0
- package/dist/components/common/toolbar-buttons.d.ts.map +1 -0
- package/dist/components/common/toolbar-buttons.js +91 -0
- package/dist/components/icons/CssIcon.d.ts +11 -0
- package/dist/components/icons/CssIcon.d.ts.map +1 -0
- package/dist/components/icons/CssIcon.js +14 -0
- package/dist/components/icons/RespArea.d.ts +26 -0
- package/dist/components/icons/RespArea.d.ts.map +1 -0
- package/dist/components/icons/RespArea.js +42 -0
- package/dist/components/icons/TableIcons.d.ts +14 -0
- package/dist/components/icons/TableIcons.d.ts.map +1 -0
- package/dist/components/icons/TableIcons.js +32 -0
- package/dist/components/icons/TextAlign.d.ts +18 -0
- package/dist/components/icons/TextAlign.d.ts.map +1 -0
- package/dist/components/icons/TextAlign.js +134 -0
- package/dist/components/image/AltDialog.d.ts +23 -0
- package/dist/components/image/AltDialog.d.ts.map +1 -0
- package/dist/components/image/AltDialog.js +61 -0
- package/dist/components/image/ImageToolbar.d.ts +25 -0
- package/dist/components/image/ImageToolbar.d.ts.map +1 -0
- package/dist/components/image/ImageToolbar.js +80 -0
- package/dist/components/image/InsertImageHandler.d.ts +33 -0
- package/dist/components/image/InsertImageHandler.d.ts.map +1 -0
- package/dist/components/image/InsertImageHandler.js +55 -0
- package/dist/components/media/MediaDialog.d.ts +44 -0
- package/dist/components/media/MediaDialog.d.ts.map +1 -0
- package/dist/components/media/MediaDialog.js +389 -0
- package/dist/components/media/MediaToolbar.d.ts +20 -0
- package/dist/components/media/MediaToolbar.d.ts.map +1 -0
- package/dist/components/media/MediaToolbar.js +41 -0
- package/dist/components/media/MediaWrapper.d.ts +20 -0
- package/dist/components/media/MediaWrapper.d.ts.map +1 -0
- package/dist/components/respArea/DragInTheBlank/DragInTheBlank.d.ts +23 -0
- package/dist/components/respArea/DragInTheBlank/DragInTheBlank.d.ts.map +1 -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.d.ts.map +1 -0
- package/dist/components/respArea/DragInTheBlank/choice.js +156 -0
- package/dist/components/respArea/ExplicitConstructedResponse.d.ts +20 -0
- package/dist/components/respArea/ExplicitConstructedResponse.d.ts.map +1 -0
- package/dist/components/respArea/ExplicitConstructedResponse.js +67 -0
- package/dist/components/respArea/InlineDropdown.d.ts +18 -0
- package/dist/components/respArea/InlineDropdown.d.ts.map +1 -0
- package/dist/components/respArea/InlineDropdown.js +91 -0
- package/dist/components/respArea/MathTemplated.d.ts +19 -0
- package/dist/components/respArea/MathTemplated.d.ts.map +1 -0
- package/dist/components/respArea/MathTemplated.js +97 -0
- package/dist/components/respArea/ToolbarIcon.d.ts +14 -0
- package/dist/components/respArea/ToolbarIcon.d.ts.map +1 -0
- package/dist/components/respArea/ToolbarIcon.js +17 -0
- package/dist/constants.d.ts +14 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +4 -0
- package/dist/extensions/css.d.ts +12 -0
- package/dist/extensions/css.d.ts.map +1 -0
- package/dist/extensions/css.js +115 -0
- package/dist/extensions/custom-toolbar-wrapper.d.ts +11 -0
- package/dist/extensions/custom-toolbar-wrapper.d.ts.map +1 -0
- package/dist/extensions/custom-toolbar-wrapper.js +58 -0
- package/dist/extensions/div-node.d.ts +11 -0
- package/dist/extensions/div-node.d.ts.map +1 -0
- package/dist/extensions/div-node.js +25 -0
- package/dist/extensions/extended-table.d.ts +11 -0
- package/dist/extensions/extended-table.d.ts.map +1 -0
- package/dist/extensions/extended-table.js +15 -0
- package/dist/extensions/image-component.d.ts +22 -0
- package/dist/extensions/image-component.d.ts.map +1 -0
- package/dist/extensions/image-component.js +200 -0
- package/dist/extensions/image.d.ts +11 -0
- package/dist/extensions/image.d.ts.map +1 -0
- package/dist/extensions/image.js +42 -0
- package/dist/extensions/index.d.ts +17 -0
- package/dist/extensions/index.d.ts.map +1 -0
- package/dist/extensions/index.js +65 -0
- package/dist/extensions/math.d.ts +15 -0
- package/dist/extensions/math.d.ts.map +1 -0
- package/dist/extensions/math.js +150 -0
- package/dist/extensions/media.d.ts +19 -0
- package/dist/extensions/media.d.ts.map +1 -0
- package/dist/extensions/media.js +147 -0
- package/dist/extensions/responseArea.d.ts +28 -0
- package/dist/extensions/responseArea.d.ts.map +1 -0
- package/dist/extensions/responseArea.js +259 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/styles/editorContainerStyles.d.ts +135 -0
- package/dist/styles/editorContainerStyles.d.ts.map +1 -0
- package/dist/theme.d.ts +10 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/utils/helper.d.ts +10 -0
- package/dist/utils/helper.d.ts.map +1 -0
- package/dist/utils/helper.js +7 -0
- package/dist/utils/size.d.ts +10 -0
- package/dist/utils/size.d.ts.map +1 -0
- package/dist/utils/size.js +14 -0
- package/package.json +71 -0
- package/src/components/CharacterPicker.tsx +210 -0
- package/src/components/EditableHtml.tsx +416 -0
- package/src/components/MenuBar.tsx +558 -0
- package/src/components/TiptapContainer.tsx +228 -0
- package/src/components/characters/characterUtils.ts +457 -0
- package/src/components/characters/custom-popper.tsx +48 -0
- package/src/components/common/done-button.tsx +37 -0
- package/src/components/common/toolbar-buttons.tsx +132 -0
- package/src/components/icons/CssIcon.tsx +25 -0
- package/src/components/icons/RespArea.tsx +81 -0
- package/src/components/icons/TableIcons.tsx +62 -0
- package/src/components/icons/TextAlign.tsx +124 -0
- package/src/components/image/AltDialog.tsx +92 -0
- package/src/components/image/ImageToolbar.tsx +109 -0
- package/src/components/image/InsertImageHandler.ts +121 -0
- package/src/components/media/MediaDialog.tsx +606 -0
- package/src/components/media/MediaToolbar.tsx +59 -0
- package/src/components/media/MediaWrapper.tsx +49 -0
- package/src/components/respArea/DragInTheBlank/DragInTheBlank.tsx +86 -0
- package/src/components/respArea/DragInTheBlank/choice.tsx +266 -0
- package/src/components/respArea/ExplicitConstructedResponse.tsx +122 -0
- package/src/components/respArea/InlineDropdown.tsx +152 -0
- package/src/components/respArea/MathTemplated.tsx +134 -0
- package/src/components/respArea/ToolbarIcon.tsx +76 -0
- package/src/constants.ts +15 -0
- package/src/extensions/css.tsx +230 -0
- package/src/extensions/custom-toolbar-wrapper.tsx +88 -0
- package/src/extensions/div-node.tsx +46 -0
- package/src/extensions/extended-table.ts +34 -0
- package/src/extensions/image-component.tsx +303 -0
- package/src/extensions/image.tsx +64 -0
- package/src/extensions/index.tsx +91 -0
- package/src/extensions/math.tsx +285 -0
- package/src/extensions/media.tsx +198 -0
- package/src/extensions/responseArea.tsx +404 -0
- package/src/index.tsx +15 -0
- package/src/styles/editorContainerStyles.ts +155 -0
- package/src/theme.ts +11 -0
- package/src/utils/helper.tsx +27 -0
- package/src/utils/size.ts +42 -0
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-lib/packages/editable-html-tip-tap/src/extensions/image-component.jsx
|
|
4
|
+
* @auto-generated
|
|
5
|
+
*
|
|
6
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
+
* Manual edits will be overwritten on next sync.
|
|
8
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
12
|
+
import PropTypes from 'prop-types';
|
|
13
|
+
import isEqual from 'lodash-es/isEqual.js';
|
|
14
|
+
import debug from 'debug';
|
|
15
|
+
import LinearProgress from '@mui/material/LinearProgress';
|
|
16
|
+
import { styled } from '@mui/material/styles';
|
|
17
|
+
import { NodeViewWrapper } from '@tiptap/react';
|
|
18
|
+
import InsertImageHandler from '../components/image/InsertImageHandler.js';
|
|
19
|
+
import ImageToolbar from '../components/image/ImageToolbar.js';
|
|
20
|
+
import CustomToolbarWrapper from './custom-toolbar-wrapper.js';
|
|
21
|
+
|
|
22
|
+
const log = debug('@pie-lib:editable-html:plugins:image:component');
|
|
23
|
+
|
|
24
|
+
const StyledProgress: any = styled(LinearProgress, {
|
|
25
|
+
shouldForwardProp: (prop) => prop !== 'hideProgress',
|
|
26
|
+
})(({ hideProgress }) => ({
|
|
27
|
+
position: 'absolute',
|
|
28
|
+
left: '0',
|
|
29
|
+
width: 'fit-content',
|
|
30
|
+
top: '0%',
|
|
31
|
+
transition: 'opacity 200ms linear',
|
|
32
|
+
...(hideProgress && {
|
|
33
|
+
opacity: 0,
|
|
34
|
+
}),
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
const StyledRoot: any = styled('div', {
|
|
38
|
+
shouldForwardProp: (prop) => !['active', 'loading', 'pendingDelete'].includes(prop),
|
|
39
|
+
})(({ theme, active, loading, pendingDelete }) => ({
|
|
40
|
+
position: 'relative',
|
|
41
|
+
border: active ? `solid 1px ${theme.palette.primary.main}` : `solid 1px ${theme.palette.common.white}`,
|
|
42
|
+
display: 'flex',
|
|
43
|
+
transition: 'opacity 200ms linear',
|
|
44
|
+
...(loading && {
|
|
45
|
+
opacity: 0.3,
|
|
46
|
+
}),
|
|
47
|
+
...(pendingDelete && {
|
|
48
|
+
opacity: 0.3,
|
|
49
|
+
}),
|
|
50
|
+
}));
|
|
51
|
+
|
|
52
|
+
const StyledImageContainer: any = styled('div')(({ theme }) => ({
|
|
53
|
+
position: 'relative',
|
|
54
|
+
width: 'fit-content',
|
|
55
|
+
display: 'flex',
|
|
56
|
+
alignItems: 'center',
|
|
57
|
+
'&&:hover > .resize': {
|
|
58
|
+
display: 'block',
|
|
59
|
+
},
|
|
60
|
+
}));
|
|
61
|
+
|
|
62
|
+
const StyledResize: any = styled('div')(({ theme }) => ({
|
|
63
|
+
backgroundColor: theme.palette.primary.main,
|
|
64
|
+
cursor: 'col-resize',
|
|
65
|
+
height: '35px',
|
|
66
|
+
width: '5px',
|
|
67
|
+
borderRadius: 8,
|
|
68
|
+
marginLeft: '5px',
|
|
69
|
+
marginRight: '10px',
|
|
70
|
+
display: 'none',
|
|
71
|
+
}));
|
|
72
|
+
|
|
73
|
+
const sizePx = (s) => (s ? `${s}px` : 'calc(20px)');
|
|
74
|
+
|
|
75
|
+
function ImageComponent(props) {
|
|
76
|
+
const {
|
|
77
|
+
node,
|
|
78
|
+
editor,
|
|
79
|
+
attributes,
|
|
80
|
+
onFocus,
|
|
81
|
+
selected,
|
|
82
|
+
options,
|
|
83
|
+
maxImageWidth = 700,
|
|
84
|
+
maxImageHeight = 900,
|
|
85
|
+
latex,
|
|
86
|
+
handleChange,
|
|
87
|
+
handleDone,
|
|
88
|
+
} = props;
|
|
89
|
+
const { alt } = node.attrs;
|
|
90
|
+
|
|
91
|
+
const [showToolbar, setShowToolbar] = useState(false);
|
|
92
|
+
|
|
93
|
+
const latestNodeRef = useRef(node);
|
|
94
|
+
const imgRef = useRef(null);
|
|
95
|
+
const resizeRef = useRef(null);
|
|
96
|
+
const toolbarRef = useRef(null);
|
|
97
|
+
|
|
98
|
+
const getPercentFromWidth = useCallback((width) => {
|
|
99
|
+
const floored = (width / imgRef.current.naturalWidth) * 4;
|
|
100
|
+
return parseInt(floored.toFixed(0) * 25, 10);
|
|
101
|
+
}, []);
|
|
102
|
+
|
|
103
|
+
const applySizeData = useCallback(() => {
|
|
104
|
+
if (!node.attrs.width || !imgRef.current) return;
|
|
105
|
+
|
|
106
|
+
const update = {
|
|
107
|
+
...node.attrs,
|
|
108
|
+
resizePercent: getPercentFromWidth(node.attrs.width),
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
if (!isEqual(update, node.attrs)) {
|
|
112
|
+
editor.commands.updateAttributes('imageUploadNode', update);
|
|
113
|
+
}
|
|
114
|
+
}, [editor, node.attrs, getPercentFromWidth]);
|
|
115
|
+
|
|
116
|
+
// keep ref in sync with latest node
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
latestNodeRef.current = node;
|
|
119
|
+
}, [node]);
|
|
120
|
+
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
const { selection } = editor.state;
|
|
123
|
+
const onlyThisNodeSelected = selection.from + node.nodeSize === selection.to;
|
|
124
|
+
|
|
125
|
+
if (selected) {
|
|
126
|
+
if (onlyThisNodeSelected) {
|
|
127
|
+
setShowToolbar(selected);
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
130
|
+
setShowToolbar(selected);
|
|
131
|
+
}
|
|
132
|
+
}, [editor, node, selected]);
|
|
133
|
+
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
options.imageHandling.insertImageRequested(node, (finish) => new InsertImageHandler(editor, node, finish));
|
|
136
|
+
applySizeData();
|
|
137
|
+
|
|
138
|
+
const resizeHandle = resizeRef.current;
|
|
139
|
+
if (resizeHandle) {
|
|
140
|
+
resizeHandle.addEventListener('mousedown', initResize, false);
|
|
141
|
+
}
|
|
142
|
+
return () => {
|
|
143
|
+
if (resizeHandle) {
|
|
144
|
+
resizeHandle.removeEventListener('mousedown', initResize, false);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
options.imageHandling.onDelete(latestNodeRef.current);
|
|
148
|
+
};
|
|
149
|
+
}, []);
|
|
150
|
+
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
applySizeData();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
const loadImage = useCallback(() => {
|
|
156
|
+
const box = imgRef.current;
|
|
157
|
+
if (!box) return;
|
|
158
|
+
|
|
159
|
+
if (!box.style.width || box.style.width === 'calc(20px)') {
|
|
160
|
+
const w = Math.min(box.naturalWidth, maxImageWidth);
|
|
161
|
+
const h = Math.min(box.naturalHeight, maxImageHeight);
|
|
162
|
+
|
|
163
|
+
box.style.width = `${w}px`;
|
|
164
|
+
box.style.height = `${h}px`;
|
|
165
|
+
|
|
166
|
+
const update = { width: w, height: h };
|
|
167
|
+
if (!isEqual(update, node.attrs)) {
|
|
168
|
+
editor.commands.updateAttributes('imageUploadNode', update);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}, [editor, node.attrs, maxImageWidth, maxImageHeight]);
|
|
172
|
+
|
|
173
|
+
const updateAspect = (initial, next, keepAspect = true, resizeType) => {
|
|
174
|
+
if (keepAspect) {
|
|
175
|
+
const ratio = initial.width / initial.height;
|
|
176
|
+
if (resizeType === 'height') return { width: next.height * ratio, height: next.height };
|
|
177
|
+
return { width: next.width, height: next.width / ratio };
|
|
178
|
+
}
|
|
179
|
+
return next;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const startResize = useCallback(
|
|
183
|
+
(e) => {
|
|
184
|
+
const box = imgRef.current;
|
|
185
|
+
if (!box) return;
|
|
186
|
+
|
|
187
|
+
const bounds = e.target.getBoundingClientRect();
|
|
188
|
+
const initial = { width: box.naturalWidth, height: box.naturalHeight };
|
|
189
|
+
|
|
190
|
+
const next = updateAspect(initial, {
|
|
191
|
+
width: e.clientX - bounds.left,
|
|
192
|
+
height: e.clientY - bounds.top,
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
if (next.width > 50 && next.height > 50 && next.width <= 700 && next.height <= 900) {
|
|
196
|
+
box.style.width = `${next.width}px`;
|
|
197
|
+
box.style.height = `${next.height}px`;
|
|
198
|
+
|
|
199
|
+
const update = { width: next.width, height: next.height };
|
|
200
|
+
if (!isEqual(update, node.attrs)) {
|
|
201
|
+
editor.commands.updateAttributes('imageUploadNode', update);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
[editor, node.attrs],
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
const onChange = useCallback(
|
|
209
|
+
(newValues) => {
|
|
210
|
+
editor.commands.updateAttributes('imageUploadNode', newValues);
|
|
211
|
+
},
|
|
212
|
+
[editor],
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
const stopResize = useCallback(() => {
|
|
216
|
+
window.removeEventListener('mousemove', startResize);
|
|
217
|
+
window.removeEventListener('mouseup', stopResize);
|
|
218
|
+
}, [startResize]);
|
|
219
|
+
|
|
220
|
+
const initResize = useCallback(() => {
|
|
221
|
+
window.addEventListener('mousemove', startResize);
|
|
222
|
+
window.addEventListener('mouseup', stopResize);
|
|
223
|
+
}, [startResize, stopResize]);
|
|
224
|
+
|
|
225
|
+
const style = {
|
|
226
|
+
width: sizePx(node.attrs.width),
|
|
227
|
+
height: sizePx(node.attrs.height),
|
|
228
|
+
objectFit: 'contain',
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
const flexAlign = { left: 'flex-start', center: 'center', right: 'flex-end' }[node.attrs.alignment] || 'flex-start';
|
|
232
|
+
|
|
233
|
+
return (
|
|
234
|
+
<NodeViewWrapper>
|
|
235
|
+
<StyledRoot
|
|
236
|
+
onFocus={onFocus}
|
|
237
|
+
active={selected}
|
|
238
|
+
loading={!node.attrs.loaded}
|
|
239
|
+
pendingDelete={node.attrs.deleteStatus === 'pending'}
|
|
240
|
+
style={{ justifyContent: flexAlign }}
|
|
241
|
+
>
|
|
242
|
+
<StyledProgress mode="determinate" value={node.attrs.percent || 0} hideProgress={node.attrs.loaded} />
|
|
243
|
+
|
|
244
|
+
<StyledImageContainer>
|
|
245
|
+
<img
|
|
246
|
+
{...attributes}
|
|
247
|
+
ref={imgRef}
|
|
248
|
+
src={node.attrs.src}
|
|
249
|
+
style={style}
|
|
250
|
+
onLoad={loadImage}
|
|
251
|
+
alt={node.attrs.alt}
|
|
252
|
+
/>
|
|
253
|
+
<StyledResize ref={resizeRef} className="resize" />
|
|
254
|
+
</StyledImageContainer>
|
|
255
|
+
</StyledRoot>
|
|
256
|
+
|
|
257
|
+
{showToolbar && (
|
|
258
|
+
<div
|
|
259
|
+
ref={toolbarRef}
|
|
260
|
+
style={{
|
|
261
|
+
position: 'absolute',
|
|
262
|
+
top: '100%',
|
|
263
|
+
left: 0,
|
|
264
|
+
zIndex: 20,
|
|
265
|
+
background: 'var(--editable-html-toolbar-bg, #efefef)',
|
|
266
|
+
boxShadow:
|
|
267
|
+
'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)',
|
|
268
|
+
width: '100%',
|
|
269
|
+
}}
|
|
270
|
+
>
|
|
271
|
+
<CustomToolbarWrapper
|
|
272
|
+
showDone
|
|
273
|
+
{...options}
|
|
274
|
+
onDone={() => {
|
|
275
|
+
setShowToolbar(false);
|
|
276
|
+
props.imageHandling?.onDone();
|
|
277
|
+
props.editor.commands.focus('end');
|
|
278
|
+
}}
|
|
279
|
+
>
|
|
280
|
+
<ImageToolbar
|
|
281
|
+
disableImageAlignmentButtons={options.disableImageAlignmentButtons}
|
|
282
|
+
alt={node.attrs.alt}
|
|
283
|
+
imageLoaded={node.attrs.loaded}
|
|
284
|
+
alignment={node.attrs.alignment || 'left'}
|
|
285
|
+
onChange={onChange}
|
|
286
|
+
/>
|
|
287
|
+
</CustomToolbarWrapper>
|
|
288
|
+
</div>
|
|
289
|
+
)}
|
|
290
|
+
</NodeViewWrapper>
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
ImageComponent.propTypes = {
|
|
295
|
+
node: PropTypes.object.isRequired,
|
|
296
|
+
editor: PropTypes.object.isRequired,
|
|
297
|
+
attributes: PropTypes.object,
|
|
298
|
+
onFocus: PropTypes.func,
|
|
299
|
+
maxImageWidth: PropTypes.number,
|
|
300
|
+
maxImageHeight: PropTypes.number,
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
export default ImageComponent;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-lib/packages/editable-html-tip-tap/src/extensions/image.js
|
|
4
|
+
* @auto-generated
|
|
5
|
+
*
|
|
6
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
+
* Manual edits will be overwritten on next sync.
|
|
8
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { mergeAttributes, Node } from '@tiptap/core';
|
|
12
|
+
import { ReactNodeViewRenderer } from '@tiptap/react';
|
|
13
|
+
import React from 'react';
|
|
14
|
+
import ImageComponent from './image-component.js';
|
|
15
|
+
|
|
16
|
+
export const ImageUploadNode = Node.create({
|
|
17
|
+
name: 'imageUploadNode',
|
|
18
|
+
|
|
19
|
+
group: 'block',
|
|
20
|
+
atom: true, // ✅ prevents content holes
|
|
21
|
+
selectable: true, // optional
|
|
22
|
+
draggable: true, // optional
|
|
23
|
+
|
|
24
|
+
addAttributes() {
|
|
25
|
+
return {
|
|
26
|
+
loaded: { default: false },
|
|
27
|
+
deleteStatus: { default: null },
|
|
28
|
+
alignment: { default: null },
|
|
29
|
+
percent: { default: null },
|
|
30
|
+
width: { default: null },
|
|
31
|
+
height: { default: null },
|
|
32
|
+
src: { default: null },
|
|
33
|
+
alt: { default: null },
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
parseHTML() {
|
|
38
|
+
return [
|
|
39
|
+
{
|
|
40
|
+
tag: 'div[data-type="image-upload-node"]',
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
renderHTML({ HTMLAttributes }) {
|
|
46
|
+
return ['img', mergeAttributes(HTMLAttributes, { 'data-type': 'image-upload-node' })];
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
addNodeView() {
|
|
50
|
+
return ReactNodeViewRenderer((props) => <ImageComponent {...{ ...props, options: this.options }} />);
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
addCommands() {
|
|
54
|
+
return {
|
|
55
|
+
setImageUploadNode:
|
|
56
|
+
() =>
|
|
57
|
+
({ commands }) => {
|
|
58
|
+
return commands.insertContent({
|
|
59
|
+
type: this.name,
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-lib/packages/editable-html-tip-tap/src/extensions/index.js
|
|
4
|
+
* @auto-generated
|
|
5
|
+
*
|
|
6
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
+
* Manual edits will be overwritten on next sync.
|
|
8
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import compact from 'lodash-es/compact.js';
|
|
12
|
+
import isEmpty from 'lodash-es/isEmpty.js';
|
|
13
|
+
import debug from 'debug';
|
|
14
|
+
|
|
15
|
+
const log = debug('@pie-lib:editable-html:plugins');
|
|
16
|
+
export const ALL_PLUGINS = [
|
|
17
|
+
'bold',
|
|
18
|
+
// 'code',
|
|
19
|
+
'html',
|
|
20
|
+
'extraCSSRules',
|
|
21
|
+
'italic',
|
|
22
|
+
'underline',
|
|
23
|
+
'strikethrough',
|
|
24
|
+
'bulleted-list',
|
|
25
|
+
'numbered-list',
|
|
26
|
+
'image',
|
|
27
|
+
'math',
|
|
28
|
+
'languageCharacters',
|
|
29
|
+
'text-align',
|
|
30
|
+
'blockquote',
|
|
31
|
+
'h3',
|
|
32
|
+
'table',
|
|
33
|
+
'video',
|
|
34
|
+
'audio',
|
|
35
|
+
'responseArea',
|
|
36
|
+
'redo',
|
|
37
|
+
'undo',
|
|
38
|
+
'superscript',
|
|
39
|
+
'subscript',
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
export const PLUGINS_MAP = {
|
|
43
|
+
'text-align': 'textAlign',
|
|
44
|
+
'bulleted-list': 'ul_list',
|
|
45
|
+
'numbered-list': 'ol_list',
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const DEFAULT_PLUGINS = ALL_PLUGINS.filter((plug) => !['responseArea', 'h3', 'blockquote'].includes(plug));
|
|
49
|
+
|
|
50
|
+
export const buildExtensions = (activeExtensions, customExtensions, opts) => {
|
|
51
|
+
log('[buildPlugins] opts: ', opts);
|
|
52
|
+
|
|
53
|
+
activeExtensions = activeExtensions || DEFAULT_PLUGINS;
|
|
54
|
+
|
|
55
|
+
const addIf = (key, shouldAdd = true) => activeExtensions.includes(key) && shouldAdd && key;
|
|
56
|
+
|
|
57
|
+
const imagePlugin = opts.image && opts.image.delete;
|
|
58
|
+
const mathPlugin = opts.math;
|
|
59
|
+
const respAreaPlugin = opts.responseArea && opts.responseArea.type;
|
|
60
|
+
const cssPlugin = !isEmpty(opts.extraCSSRules);
|
|
61
|
+
|
|
62
|
+
const languageCharactersPlugins = opts?.languageCharacters || [];
|
|
63
|
+
|
|
64
|
+
return compact([
|
|
65
|
+
addIf('table'),
|
|
66
|
+
addIf('bold'),
|
|
67
|
+
// addIf('code', MarkHotkey({ key: '`', type: 'code', icon: <Code /> })),
|
|
68
|
+
addIf('italic'),
|
|
69
|
+
addIf('strikethrough'),
|
|
70
|
+
addIf('underline'),
|
|
71
|
+
// icon should be modifies accordingly
|
|
72
|
+
addIf('superscript'),
|
|
73
|
+
// icon should be modifies accordingly
|
|
74
|
+
addIf('subscript'),
|
|
75
|
+
addIf('image', !!imagePlugin),
|
|
76
|
+
addIf('video'),
|
|
77
|
+
addIf('audio'),
|
|
78
|
+
addIf('math', !!mathPlugin),
|
|
79
|
+
...languageCharactersPlugins.map((plugin) => addIf('languageCharacters', plugin)),
|
|
80
|
+
addIf('text-align'),
|
|
81
|
+
addIf('blockquote'),
|
|
82
|
+
addIf('h3'),
|
|
83
|
+
addIf('bulleted-list'),
|
|
84
|
+
addIf('numbered-list'),
|
|
85
|
+
addIf('undo'),
|
|
86
|
+
addIf('redo'),
|
|
87
|
+
addIf('responseArea', !!respAreaPlugin),
|
|
88
|
+
addIf('css', !!cssPlugin),
|
|
89
|
+
addIf('html', !!opts.html),
|
|
90
|
+
]);
|
|
91
|
+
};
|