@pie-lib/editable-html-tip-tap 3.0.0-next.35 → 3.0.0-next.36
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/MenuBar.js +5 -2
- package/dist/components/image/InsertImageHandler.d.ts +1 -0
- package/dist/components/image/InsertImageHandler.js +34 -22
- package/dist/components/image/findImageNode.d.ts +3 -0
- package/dist/components/image/findImageNode.js +11 -0
- package/dist/extensions/image-component.js +123 -125
- package/dist/extensions/image.js +33 -24
- package/package.json +23 -23
|
@@ -508,9 +508,12 @@ var W = (e) => {
|
|
|
508
508
|
top: "-45px"
|
|
509
509
|
},
|
|
510
510
|
"& .toolbarRight": { right: 0 },
|
|
511
|
-
"& .fullWidth": {
|
|
511
|
+
"& .fullWidth": {
|
|
512
|
+
width: "fit-content",
|
|
513
|
+
minWidth: "100%"
|
|
514
|
+
},
|
|
512
515
|
"& .hidden": { visibility: "hidden" },
|
|
513
|
-
"& .autoWidth": { width: "
|
|
516
|
+
"& .autoWidth": { width: "fit-content" },
|
|
514
517
|
"& .focused": {
|
|
515
518
|
opacity: 1,
|
|
516
519
|
pointerEvents: "auto"
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import e from "
|
|
1
|
+
import e from "./findImageNode.js";
|
|
2
|
+
import t from "debug";
|
|
2
3
|
//#region src/components/image/InsertImageHandler.ts
|
|
3
|
-
var
|
|
4
|
+
var n = t("@pie-lib:editable-html:image:insert-image-handler"), r = class {
|
|
4
5
|
constructor(e, t, n, r = !1) {
|
|
5
|
-
this.editor = e, this.nodeInfo = t, this.node = t[0], this.nodePos = t[1], this.onFinish = n, this.isPasted = r, this.chosenFile = null;
|
|
6
|
+
this.editor = e, this.nodeInfo = t, this.node = t[0], this.nodePos = t[1], this.onFinish = n, this.isPasted = r, this.chosenFile = null, this.nodeKey = this.node?.attrs?.nodeKey || null;
|
|
7
|
+
}
|
|
8
|
+
resolveNodePos() {
|
|
9
|
+
let t = e(this.editor, this.nodeKey);
|
|
10
|
+
return t ? t[1] : this.nodeKey ? null : this.nodePos;
|
|
6
11
|
}
|
|
7
12
|
cancel() {
|
|
8
|
-
|
|
13
|
+
n("insert cancelled");
|
|
9
14
|
try {
|
|
10
15
|
this.deleteNode(), this.onFinish(!1);
|
|
11
16
|
} catch {} finally {
|
|
@@ -13,41 +18,48 @@ var t = e("@pie-lib:editable-html:image:insert-image-handler"), n = class {
|
|
|
13
18
|
}
|
|
14
19
|
}
|
|
15
20
|
updateNode(e) {
|
|
16
|
-
let
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
let t = this.resolveNodePos();
|
|
22
|
+
if (t === null) {
|
|
23
|
+
n("[updateNode] node is gone, dropping update: ", e);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
let { state: r, view: i } = this.editor, { tr: a } = r, o = r.doc.nodeAt(t);
|
|
27
|
+
if (o) {
|
|
28
|
+
let n = a.setNodeMarkup(t, void 0, {
|
|
29
|
+
...o.attrs,
|
|
20
30
|
...e
|
|
21
31
|
});
|
|
22
|
-
|
|
32
|
+
i.dispatch(n);
|
|
23
33
|
}
|
|
24
34
|
}
|
|
25
35
|
deleteNode() {
|
|
26
|
-
let
|
|
27
|
-
|
|
36
|
+
let e = this.resolveNodePos();
|
|
37
|
+
if (e === null) return;
|
|
38
|
+
let { state: t, view: n } = this.editor, { tr: r } = t, i = t.doc.nodeAt(e) || this.node, a = r.delete(e, e + i.nodeSize);
|
|
39
|
+
n.dispatch(a);
|
|
28
40
|
}
|
|
29
|
-
done(e,
|
|
30
|
-
|
|
41
|
+
done(e, t) {
|
|
42
|
+
n("done: err:", e), e ? (console.log(e), this.onFinish(!1)) : (this.updateNode({
|
|
31
43
|
loaded: !0,
|
|
32
|
-
src:
|
|
44
|
+
src: t,
|
|
33
45
|
percent: 100
|
|
34
46
|
}), this.onFinish(!0)), this.editor._insertingImage = !1;
|
|
35
47
|
}
|
|
36
48
|
fileChosen(e) {
|
|
37
49
|
if (!e) return;
|
|
38
|
-
this.chosenFile = e, this.editor._insertingImage = !1,
|
|
39
|
-
let
|
|
40
|
-
|
|
41
|
-
let e =
|
|
50
|
+
this.chosenFile = e, this.editor._insertingImage = !1, n("[fileChosen] file: ", e);
|
|
51
|
+
let t = new FileReader();
|
|
52
|
+
t.onload = () => {
|
|
53
|
+
let e = t.result;
|
|
42
54
|
this.updateNode({ src: e });
|
|
43
|
-
},
|
|
55
|
+
}, t.readAsDataURL(e);
|
|
44
56
|
}
|
|
45
|
-
progress(e,
|
|
46
|
-
|
|
57
|
+
progress(e, t, r) {
|
|
58
|
+
n("progress: ", e, t, r), this.updateNode({ percent: e });
|
|
47
59
|
}
|
|
48
60
|
getChosenFile() {
|
|
49
61
|
return this.chosenFile;
|
|
50
62
|
}
|
|
51
63
|
};
|
|
52
64
|
//#endregion
|
|
53
|
-
export {
|
|
65
|
+
export { r as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/components/image/findImageNode.ts
|
|
2
|
+
var e = (e, t) => {
|
|
3
|
+
if (!e || !t) return null;
|
|
4
|
+
let n = null;
|
|
5
|
+
return e.state.doc.descendants((e, r) => {
|
|
6
|
+
if (n !== null) return !1;
|
|
7
|
+
if (e.type.name === "imageUploadNode" && e.attrs.nodeKey === t) return n = [e, r], !1;
|
|
8
|
+
}), n;
|
|
9
|
+
}, t = () => `img-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { e as default, e as findImageNodeByKey, t as newImageNodeKey };
|
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import e from "./custom-toolbar-wrapper.js";
|
|
2
|
-
import t from "../components/image/
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import d from "
|
|
9
|
-
import f from "
|
|
10
|
-
import
|
|
11
|
-
import h from "
|
|
12
|
-
import g from "
|
|
2
|
+
import t from "../components/image/findImageNode.js";
|
|
3
|
+
import n from "../components/image/InsertImageHandler.js";
|
|
4
|
+
import { ImageToolbar as r } from "../components/image/ImageToolbar.js";
|
|
5
|
+
import { useCallback as i, useEffect as a, useMemo as o, useRef as s, useState as c } from "react";
|
|
6
|
+
import { isEqual as l } from "@pie-element/shared-lodash";
|
|
7
|
+
import { NodeViewWrapper as u } from "@tiptap/react";
|
|
8
|
+
import { styled as d } from "@mui/material/styles";
|
|
9
|
+
import f from "react-dom";
|
|
10
|
+
import p from "prop-types";
|
|
11
|
+
import { jsx as m, jsxs as h } from "react/jsx-runtime";
|
|
12
|
+
import g from "debug";
|
|
13
|
+
import _ from "@mui/material/LinearProgress";
|
|
13
14
|
//#region src/extensions/image-component.tsx
|
|
14
|
-
|
|
15
|
-
var
|
|
15
|
+
g("@pie-lib:editable-html:plugins:image:component");
|
|
16
|
+
var v = d(_, { shouldForwardProp: (e) => e !== "hideProgress" })(({ hideProgress: e }) => ({
|
|
16
17
|
position: "absolute",
|
|
17
18
|
left: "0",
|
|
18
19
|
width: "fit-content",
|
|
19
20
|
top: "0%",
|
|
20
21
|
transition: "opacity 200ms linear",
|
|
21
22
|
...e && { opacity: 0 }
|
|
22
|
-
})),
|
|
23
|
+
})), y = d("div", { shouldForwardProp: (e) => ![
|
|
23
24
|
"active",
|
|
24
25
|
"loading",
|
|
25
26
|
"pendingDelete"
|
|
@@ -29,13 +30,13 @@ var _ = u(g, { shouldForwardProp: (e) => e !== "hideProgress" })(({ hideProgress
|
|
|
29
30
|
transition: "opacity 200ms linear",
|
|
30
31
|
...e && { opacity: .3 },
|
|
31
32
|
...t && { opacity: .3 }
|
|
32
|
-
})),
|
|
33
|
+
})), b = d("div")(({ theme: e }) => ({
|
|
33
34
|
position: "relative",
|
|
34
35
|
width: "fit-content",
|
|
35
36
|
display: "flex",
|
|
36
37
|
alignItems: "center",
|
|
37
38
|
"&&:hover > .resize": { display: "block" }
|
|
38
|
-
})),
|
|
39
|
+
})), x = d("img", { shouldForwardProp: (e) => e !== "active" })(({ theme: e, active: t }) => ({ border: t ? `solid 1px ${e.palette.primary.main}` : "solid 1px transparent" })), S = d("div")(({ theme: e }) => ({
|
|
39
40
|
backgroundColor: e.palette.primary.main,
|
|
40
41
|
cursor: "col-resize",
|
|
41
42
|
height: "35px",
|
|
@@ -44,80 +45,77 @@ var _ = u(g, { shouldForwardProp: (e) => e !== "hideProgress" })(({ hideProgress
|
|
|
44
45
|
marginLeft: "5px",
|
|
45
46
|
marginRight: "10px",
|
|
46
47
|
display: "none"
|
|
47
|
-
})),
|
|
48
|
-
function
|
|
49
|
-
let { node:
|
|
50
|
-
j,
|
|
48
|
+
})), C = (e) => e ? `${e}px` : "calc(20px)";
|
|
49
|
+
function w(d) {
|
|
50
|
+
let { node: p, editor: g, attributes: _, onFocus: w, getPos: T, selected: E, options: D, maxImageWidth: O = 700, maxImageHeight: k = 900 } = d, { alt: A } = p.attrs, j = T(), M = g.state.selection.from, N = g.state.selection.to, P = o(() => M + p.nodeSize === N, [
|
|
51
51
|
M,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
N,
|
|
53
|
+
p.nodeSize
|
|
54
|
+
]), [F, I] = c(!1), L = s(p), R = s(null), z = s(null), B = s(null), V = i((e) => {
|
|
55
|
+
let t = e / R.current.naturalWidth * 4;
|
|
55
56
|
return parseInt(t.toFixed(0) * 25, 10);
|
|
56
|
-
}, []),
|
|
57
|
-
let e =
|
|
58
|
-
return
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}), t;
|
|
62
|
-
}, [h]), H = r((e) => {
|
|
63
|
-
let t = V();
|
|
57
|
+
}, []), H = i(() => {
|
|
58
|
+
let e = t(g, L.current.attrs.nodeKey);
|
|
59
|
+
return e ? e[1] : null;
|
|
60
|
+
}, [g]), U = i((e) => {
|
|
61
|
+
let t = H();
|
|
64
62
|
if (t === null) return;
|
|
65
|
-
let n =
|
|
66
|
-
n &&
|
|
63
|
+
let n = g.state.doc.nodeAt(t);
|
|
64
|
+
n && g.view.dispatch(g.state.tr.setNodeMarkup(t, void 0, {
|
|
67
65
|
...n.attrs,
|
|
68
66
|
...e
|
|
69
67
|
}));
|
|
70
|
-
}, [
|
|
71
|
-
if (!
|
|
72
|
-
let e =
|
|
73
|
-
|
|
68
|
+
}, [g, H]), W = i(() => {
|
|
69
|
+
if (!p.attrs.width || !R.current || !R.current.naturalWidth) return;
|
|
70
|
+
let e = V(p.attrs.width);
|
|
71
|
+
p.attrs.resizePercent !== e && U({ resizePercent: e });
|
|
74
72
|
}, [
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
73
|
+
p.attrs.width,
|
|
74
|
+
p.attrs.resizePercent,
|
|
75
|
+
V,
|
|
76
|
+
U
|
|
79
77
|
]);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
...
|
|
83
|
-
pos:
|
|
78
|
+
a(() => {
|
|
79
|
+
L.current = {
|
|
80
|
+
...p,
|
|
81
|
+
pos: j
|
|
84
82
|
};
|
|
85
|
-
}, [
|
|
86
|
-
|
|
83
|
+
}, [p, j]), a(() => {
|
|
84
|
+
E ? P && g.isEditable && (!String(p.attrs?.src ?? "").trim() && D.imageHandling?.insertImageRequested && D.imageHandling.insertImageRequested(g, [p, j], (e) => new n(g, [p, j], e)), I(E)) : I(E);
|
|
87
85
|
}, [
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
]),
|
|
92
|
-
|
|
93
|
-
let e =
|
|
94
|
-
return e &&
|
|
95
|
-
e && e.removeEventListener("mousedown",
|
|
86
|
+
P,
|
|
87
|
+
E,
|
|
88
|
+
g.isEditable
|
|
89
|
+
]), a(() => {
|
|
90
|
+
W();
|
|
91
|
+
let e = z?.current;
|
|
92
|
+
return e && g.isEditable && e.addEventListener("mousedown", X, !1), () => {
|
|
93
|
+
e && e.removeEventListener("mousedown", X, !1);
|
|
96
94
|
};
|
|
97
|
-
}, []),
|
|
98
|
-
|
|
95
|
+
}, []), a(() => {
|
|
96
|
+
W();
|
|
99
97
|
});
|
|
100
|
-
let
|
|
101
|
-
let e =
|
|
98
|
+
let G = i(() => {
|
|
99
|
+
let e = R.current;
|
|
102
100
|
if (e && (!e.style.width || e.style.width === "calc(20px)")) {
|
|
103
|
-
let t = Math.min(e.naturalWidth,
|
|
101
|
+
let t = Math.min(e.naturalWidth, O), n = Math.min(e.naturalHeight, k);
|
|
104
102
|
e.style.width = `${t}px`, e.style.height = `${n}px`;
|
|
105
103
|
let r = {
|
|
106
104
|
width: t,
|
|
107
105
|
height: n
|
|
108
106
|
};
|
|
109
|
-
|
|
110
|
-
width:
|
|
111
|
-
height:
|
|
112
|
-
}) ||
|
|
107
|
+
l(r, {
|
|
108
|
+
width: p.attrs.width,
|
|
109
|
+
height: p.attrs.height
|
|
110
|
+
}) || U(r);
|
|
113
111
|
}
|
|
114
112
|
}, [
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
D,
|
|
113
|
+
p.attrs.width,
|
|
114
|
+
p.attrs.height,
|
|
118
115
|
O,
|
|
119
|
-
|
|
120
|
-
|
|
116
|
+
k,
|
|
117
|
+
U
|
|
118
|
+
]), K = (e, t, n = !0, r) => {
|
|
121
119
|
if (n) {
|
|
122
120
|
let n = e.width / e.height;
|
|
123
121
|
return r === "height" ? {
|
|
@@ -129,97 +127,97 @@ function C(u) {
|
|
|
129
127
|
};
|
|
130
128
|
}
|
|
131
129
|
return t;
|
|
132
|
-
},
|
|
133
|
-
let t =
|
|
130
|
+
}, q = i((e) => {
|
|
131
|
+
let t = R.current;
|
|
134
132
|
if (!t) return;
|
|
135
133
|
let n = e.target.getBoundingClientRect(), r = {
|
|
136
134
|
width: t.naturalWidth,
|
|
137
135
|
height: t.naturalHeight
|
|
138
|
-
}, i =
|
|
136
|
+
}, i = K(r, {
|
|
139
137
|
width: e.clientX - n.left,
|
|
140
138
|
height: e.clientY - n.top
|
|
141
139
|
});
|
|
142
|
-
i.width > 50 && i.height > 50 && i.width <= 700 && i.height <= 900 && (t.style.width = `${i.width}px`, t.style.height = `${i.height}px`,
|
|
140
|
+
i.width > 50 && i.height > 50 && i.width <= 700 && i.height <= 900 && (t.style.width = `${i.width}px`, t.style.height = `${i.height}px`, U({
|
|
143
141
|
width: i.width,
|
|
144
142
|
height: i.height
|
|
145
143
|
}));
|
|
146
|
-
}, [
|
|
147
|
-
|
|
148
|
-
}, [
|
|
149
|
-
window.removeEventListener("mousemove",
|
|
150
|
-
}, [
|
|
151
|
-
window.addEventListener("mousemove",
|
|
152
|
-
}, [
|
|
153
|
-
width:
|
|
154
|
-
height:
|
|
144
|
+
}, [g, U]), J = i((e) => {
|
|
145
|
+
U(e);
|
|
146
|
+
}, [g, U]), Y = i(() => {
|
|
147
|
+
window.removeEventListener("mousemove", q), window.removeEventListener("mouseup", Y);
|
|
148
|
+
}, [q]), X = i(() => {
|
|
149
|
+
window.addEventListener("mousemove", q), window.addEventListener("mouseup", Y);
|
|
150
|
+
}, [q, Y]), Z = {
|
|
151
|
+
width: C(p.attrs.width),
|
|
152
|
+
height: C(p.attrs.height),
|
|
155
153
|
objectFit: "contain"
|
|
156
|
-
},
|
|
154
|
+
}, Q = {
|
|
157
155
|
left: "flex-start",
|
|
158
156
|
center: "center",
|
|
159
157
|
right: "flex-end"
|
|
160
|
-
}[
|
|
161
|
-
return /* @__PURE__ */
|
|
162
|
-
onFocus:
|
|
163
|
-
loading: !
|
|
164
|
-
pendingDelete:
|
|
165
|
-
style: { justifyContent:
|
|
166
|
-
children: [/* @__PURE__ */
|
|
158
|
+
}[p.attrs.alignment] || "flex-start";
|
|
159
|
+
return /* @__PURE__ */ h(u, { children: [/* @__PURE__ */ h(y, {
|
|
160
|
+
onFocus: w,
|
|
161
|
+
loading: !p.attrs.loaded,
|
|
162
|
+
pendingDelete: p.attrs.deleteStatus === "pending",
|
|
163
|
+
style: { justifyContent: Q },
|
|
164
|
+
children: [/* @__PURE__ */ m(v, {
|
|
167
165
|
mode: "determinate",
|
|
168
|
-
value:
|
|
169
|
-
hideProgress:
|
|
170
|
-
}), /* @__PURE__ */
|
|
166
|
+
value: p.attrs.percent || 0,
|
|
167
|
+
hideProgress: p.attrs.loaded
|
|
168
|
+
}), /* @__PURE__ */ h(b, {
|
|
171
169
|
onDragStart: (e) => e.preventDefault(),
|
|
172
|
-
children: [/* @__PURE__ */
|
|
173
|
-
...
|
|
174
|
-
active:
|
|
170
|
+
children: [/* @__PURE__ */ m(x, {
|
|
171
|
+
..._,
|
|
172
|
+
active: E && p.attrs.loaded,
|
|
175
173
|
draggable: !1,
|
|
176
|
-
ref: L,
|
|
177
|
-
src: f.attrs.src,
|
|
178
|
-
style: X,
|
|
179
|
-
onLoad: W,
|
|
180
|
-
alt: f.attrs.alt
|
|
181
|
-
}), /* @__PURE__ */ p(x, {
|
|
182
174
|
ref: R,
|
|
175
|
+
src: p.attrs.src,
|
|
176
|
+
style: Z,
|
|
177
|
+
onLoad: G,
|
|
178
|
+
alt: p.attrs.alt
|
|
179
|
+
}), /* @__PURE__ */ m(S, {
|
|
180
|
+
ref: z,
|
|
183
181
|
className: "resize",
|
|
184
|
-
style: { display:
|
|
182
|
+
style: { display: g.isEditable ? void 0 : "none" }
|
|
185
183
|
})]
|
|
186
184
|
})]
|
|
187
|
-
}),
|
|
188
|
-
ref:
|
|
185
|
+
}), F && g._tiptapContainerEl && f.createPortal(/* @__PURE__ */ m("div", {
|
|
186
|
+
ref: B,
|
|
189
187
|
style: {
|
|
190
188
|
zIndex: 20,
|
|
191
189
|
background: "var(--editable-html-toolbar-bg, #efefef)",
|
|
192
190
|
boxShadow: "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)",
|
|
193
191
|
width: "100%"
|
|
194
192
|
},
|
|
195
|
-
children: /* @__PURE__ */
|
|
193
|
+
children: /* @__PURE__ */ m(e, {
|
|
196
194
|
showDone: !0,
|
|
197
195
|
deletable: !0,
|
|
198
|
-
toolbarOpts:
|
|
196
|
+
toolbarOpts: D.toolbarOpts || {},
|
|
199
197
|
onDelete: () => {
|
|
200
|
-
let e =
|
|
201
|
-
e !== null && (
|
|
198
|
+
let e = H();
|
|
199
|
+
e !== null && (D.imageHandling?.onDelete?.(L.current), g.view.dispatch(g.state.tr.delete(e, e + g.state.doc.nodeAt(e).nodeSize)), I(!1), g.commands.focus());
|
|
202
200
|
},
|
|
203
201
|
onDone: () => {
|
|
204
|
-
|
|
202
|
+
I(!1), D.imageHandling?.onDone?.(g), g.commands.focus("end");
|
|
205
203
|
},
|
|
206
|
-
children: /* @__PURE__ */
|
|
207
|
-
disableImageAlignmentButtons:
|
|
208
|
-
alt:
|
|
209
|
-
imageLoaded:
|
|
210
|
-
alignment:
|
|
211
|
-
onChange:
|
|
204
|
+
children: /* @__PURE__ */ m(r, {
|
|
205
|
+
disableImageAlignmentButtons: D.imageHandling?.disableImageAlignmentButtons,
|
|
206
|
+
alt: p.attrs.alt,
|
|
207
|
+
imageLoaded: p.attrs.loaded,
|
|
208
|
+
alignment: p.attrs.alignment || "left",
|
|
209
|
+
onChange: J
|
|
212
210
|
})
|
|
213
211
|
})
|
|
214
|
-
}),
|
|
212
|
+
}), g._tiptapContainerEl)] });
|
|
215
213
|
}
|
|
216
|
-
|
|
217
|
-
node:
|
|
218
|
-
editor:
|
|
219
|
-
attributes:
|
|
220
|
-
onFocus:
|
|
221
|
-
maxImageWidth:
|
|
222
|
-
maxImageHeight:
|
|
214
|
+
w.propTypes = {
|
|
215
|
+
node: p.object.isRequired,
|
|
216
|
+
editor: p.object.isRequired,
|
|
217
|
+
attributes: p.object,
|
|
218
|
+
onFocus: p.func,
|
|
219
|
+
maxImageWidth: p.number,
|
|
220
|
+
maxImageHeight: p.number
|
|
223
221
|
};
|
|
224
222
|
//#endregion
|
|
225
|
-
export {
|
|
223
|
+
export { w as default };
|
package/dist/extensions/image.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import e from "
|
|
1
|
+
import e, { newImageNodeKey as t } from "../components/image/findImageNode.js";
|
|
2
|
+
import n from "../components/image/InsertImageHandler.js";
|
|
3
|
+
import r from "./image-component.js";
|
|
2
4
|
import "react";
|
|
3
|
-
import { ReactNodeViewRenderer as
|
|
4
|
-
import { Node as
|
|
5
|
-
import { Plugin as
|
|
6
|
-
import { jsx as
|
|
5
|
+
import { ReactNodeViewRenderer as i } from "@tiptap/react";
|
|
6
|
+
import { Node as a, mergeAttributes as o } from "@tiptap/core";
|
|
7
|
+
import { Plugin as s } from "@tiptap/pm/state";
|
|
8
|
+
import { jsx as c } from "react/jsx-runtime";
|
|
7
9
|
//#region src/extensions/image.tsx
|
|
8
|
-
var
|
|
10
|
+
var l = a.create({
|
|
9
11
|
name: "imageUploadNode",
|
|
10
12
|
group: "block",
|
|
11
13
|
atom: !0,
|
|
@@ -28,41 +30,48 @@ var o = n.create({
|
|
|
28
30
|
return [{ tag: "img[data-type=\"image-upload-node\"]" }];
|
|
29
31
|
},
|
|
30
32
|
renderHTML({ HTMLAttributes: e }) {
|
|
31
|
-
return ["img",
|
|
33
|
+
return ["img", o(e, { "data-type": "image-upload-node" })];
|
|
32
34
|
},
|
|
33
35
|
addNodeView() {
|
|
34
|
-
return
|
|
35
|
-
...
|
|
36
|
+
return i((e) => /* @__PURE__ */ c(r, {
|
|
37
|
+
...e,
|
|
36
38
|
options: this.options
|
|
37
39
|
}));
|
|
38
40
|
},
|
|
39
41
|
addCommands() {
|
|
40
42
|
return { setImageUploadNode: () => ({ commands: e }) => e.insertContent({
|
|
41
43
|
type: this.name,
|
|
42
|
-
attrs: { nodeKey:
|
|
44
|
+
attrs: { nodeKey: t() }
|
|
43
45
|
}) };
|
|
44
46
|
},
|
|
45
47
|
addProseMirrorPlugins() {
|
|
46
|
-
let
|
|
47
|
-
return [new
|
|
48
|
-
let
|
|
49
|
-
if (!
|
|
50
|
-
let
|
|
51
|
-
if (!
|
|
52
|
-
let
|
|
53
|
-
return
|
|
54
|
-
let t =
|
|
55
|
-
typeof t
|
|
48
|
+
let r = this.editor, i = this.options;
|
|
49
|
+
return [new s({ props: { handlePaste(a, o) {
|
|
50
|
+
let s = Array.from(o.clipboardData?.items || []).find((e) => e.kind === "file" && e.type.startsWith("image/"));
|
|
51
|
+
if (!s) return !1;
|
|
52
|
+
let c = s.getAsFile();
|
|
53
|
+
if (!c) return !1;
|
|
54
|
+
let l = i?.imageHandling?.insertImageRequested, u = t(), d = new FileReader();
|
|
55
|
+
return d.onload = () => {
|
|
56
|
+
let t = d.result;
|
|
57
|
+
if (typeof t != "string" || (r.commands.insertContent({
|
|
56
58
|
type: "imageUploadNode",
|
|
57
59
|
attrs: {
|
|
58
60
|
src: t,
|
|
59
|
-
loaded: !
|
|
60
|
-
nodeKey:
|
|
61
|
+
loaded: !l,
|
|
62
|
+
nodeKey: u
|
|
61
63
|
}
|
|
64
|
+
}), !l)) return;
|
|
65
|
+
let i = e(r, u);
|
|
66
|
+
i && l(r, i, (e) => {
|
|
67
|
+
let t;
|
|
68
|
+
return t = new n(r, i, (n) => {
|
|
69
|
+
n || t?.updateNode({ loaded: !0 }), e(n);
|
|
70
|
+
}, !0), t.fileChosen(c), t;
|
|
62
71
|
});
|
|
63
|
-
},
|
|
72
|
+
}, d.readAsDataURL(c), !0;
|
|
64
73
|
} } })];
|
|
65
74
|
}
|
|
66
75
|
});
|
|
67
76
|
//#endregion
|
|
68
|
-
export {
|
|
77
|
+
export { l as ImageUploadNode };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/editable-html-tip-tap",
|
|
3
|
-
"version": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.36",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,27 +13,27 @@
|
|
|
13
13
|
"@dnd-kit/utilities": "3.2.2",
|
|
14
14
|
"@mui/icons-material": "^7.3.4",
|
|
15
15
|
"@mui/material": "^7.3.4",
|
|
16
|
-
"@pie-lib/drag": "4.1.0-next.
|
|
17
|
-
"@pie-lib/math-input": "9.0.0-next.
|
|
18
|
-
"@pie-lib/math-toolbar": "4.0.0-next.
|
|
19
|
-
"@pie-lib/render-ui": "6.2.0-next.
|
|
20
|
-
"@tiptap/core": "3.
|
|
21
|
-
"@tiptap/extension-character-count": "3.
|
|
22
|
-
"@tiptap/extension-color": "3.
|
|
16
|
+
"@pie-lib/drag": "4.1.0-next.42",
|
|
17
|
+
"@pie-lib/math-input": "9.0.0-next.7",
|
|
18
|
+
"@pie-lib/math-toolbar": "4.0.0-next.42",
|
|
19
|
+
"@pie-lib/render-ui": "6.2.0-next.42",
|
|
20
|
+
"@tiptap/core": "3.31.3",
|
|
21
|
+
"@tiptap/extension-character-count": "3.31.3",
|
|
22
|
+
"@tiptap/extension-color": "3.31.3",
|
|
23
23
|
"@tiptap/extension-image": "3.31.3",
|
|
24
|
-
"@tiptap/extension-list-item": "3.
|
|
25
|
-
"@tiptap/extension-placeholder": "3.
|
|
26
|
-
"@tiptap/extension-subscript": "3.
|
|
27
|
-
"@tiptap/extension-superscript": "3.
|
|
28
|
-
"@tiptap/extension-table": "3.
|
|
29
|
-
"@tiptap/extension-table-cell": "3.
|
|
30
|
-
"@tiptap/extension-table-header": "3.
|
|
31
|
-
"@tiptap/extension-table-row": "3.
|
|
32
|
-
"@tiptap/extension-text-align": "3.
|
|
33
|
-
"@tiptap/extension-text-style": "3.
|
|
34
|
-
"@tiptap/pm": "3.
|
|
35
|
-
"@tiptap/react": "3.
|
|
36
|
-
"@tiptap/starter-kit": "3.
|
|
24
|
+
"@tiptap/extension-list-item": "3.31.3",
|
|
25
|
+
"@tiptap/extension-placeholder": "3.31.3",
|
|
26
|
+
"@tiptap/extension-subscript": "3.31.3",
|
|
27
|
+
"@tiptap/extension-superscript": "3.31.3",
|
|
28
|
+
"@tiptap/extension-table": "3.31.3",
|
|
29
|
+
"@tiptap/extension-table-cell": "3.31.3",
|
|
30
|
+
"@tiptap/extension-table-header": "3.31.3",
|
|
31
|
+
"@tiptap/extension-table-row": "3.31.3",
|
|
32
|
+
"@tiptap/extension-text-align": "3.31.3",
|
|
33
|
+
"@tiptap/extension-text-style": "3.31.3",
|
|
34
|
+
"@tiptap/pm": "3.31.3",
|
|
35
|
+
"@tiptap/react": "3.31.3",
|
|
36
|
+
"@tiptap/starter-kit": "3.31.3",
|
|
37
37
|
"change-case": "^3.0.2",
|
|
38
38
|
"debug": "^4.1.1",
|
|
39
39
|
"immutable": "^4.0.0-rc.12",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"clsx": "^2.1.1",
|
|
49
49
|
"prosemirror-state": "^1.4.4",
|
|
50
50
|
"@pie-element/shared-math-rendering-mathjax": "0.1.1-next.0",
|
|
51
|
-
"@tiptap/extensions": "
|
|
52
|
-
"@tiptap/extension-list": "
|
|
51
|
+
"@tiptap/extensions": "3.31.3",
|
|
52
|
+
"@tiptap/extension-list": "3.31.3",
|
|
53
53
|
"@types/react": "^18.2.0",
|
|
54
54
|
"@types/react-dom": "^18.2.0"
|
|
55
55
|
},
|