@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.
@@ -508,9 +508,12 @@ var W = (e) => {
508
508
  top: "-45px"
509
509
  },
510
510
  "& .toolbarRight": { right: 0 },
511
- "& .fullWidth": { width: "100%" },
511
+ "& .fullWidth": {
512
+ width: "fit-content",
513
+ minWidth: "100%"
514
+ },
512
515
  "& .hidden": { visibility: "hidden" },
513
- "& .autoWidth": { width: "auto" },
516
+ "& .autoWidth": { width: "fit-content" },
514
517
  "& .focused": {
515
518
  opacity: 1,
516
519
  pointerEvents: "auto"
@@ -16,6 +16,7 @@
16
16
  */
17
17
  declare class InsertImageHandler {
18
18
  constructor(editor: any, nodeInfo: any, onFinish: any, isPasted?: boolean);
19
+ resolveNodePos(): any;
19
20
  cancel(): void;
20
21
  updateNode(newAttrs: any): void;
21
22
  deleteNode(): void;
@@ -1,11 +1,16 @@
1
- import e from "debug";
1
+ import e from "./findImageNode.js";
2
+ import t from "debug";
2
3
  //#region src/components/image/InsertImageHandler.ts
3
- var t = e("@pie-lib:editable-html:image:insert-image-handler"), n = class {
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
- t("insert cancelled");
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 { state: t, view: n } = this.editor, { tr: r } = t, i = t.doc.nodeAt(this.nodePos);
17
- if (i) {
18
- let t = r.setNodeMarkup(this.nodePos, void 0, {
19
- ...i.attrs,
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
- n.dispatch(t);
32
+ i.dispatch(n);
23
33
  }
24
34
  }
25
35
  deleteNode() {
26
- let { state: e, view: t } = this.editor, { tr: n } = e, r = n.delete(this.nodePos, this.nodePos + this.node.nodeSize);
27
- t.dispatch(r);
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, n) {
30
- t("done: err:", e), e ? (console.log(e), this.onFinish(!1)) : (this.updateNode({
41
+ done(e, t) {
42
+ n("done: err:", e), e ? (console.log(e), this.onFinish(!1)) : (this.updateNode({
31
43
  loaded: !0,
32
- src: n,
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, t("[fileChosen] file: ", e);
39
- let n = new FileReader();
40
- n.onload = () => {
41
- let e = n.result;
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
- }, n.readAsDataURL(e);
55
+ }, t.readAsDataURL(e);
44
56
  }
45
- progress(e, n, r) {
46
- t("progress: ", e, n, r), this.updateNode({ percent: e });
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 { n as default };
65
+ export { r as default };
@@ -0,0 +1,3 @@
1
+ export declare const findImageNodeByKey: (editor: any, nodeKey: any) => null;
2
+ export declare const newImageNodeKey: () => string;
3
+ export default findImageNodeByKey;
@@ -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/InsertImageHandler.js";
3
- import { ImageToolbar as n } from "../components/image/ImageToolbar.js";
4
- import { useCallback as r, useEffect as i, useMemo as a, useRef as o, useState as s } from "react";
5
- import { isEqual as c } from "@pie-element/shared-lodash";
6
- import { NodeViewWrapper as l } from "@tiptap/react";
7
- import { styled as u } from "@mui/material/styles";
8
- import d from "react-dom";
9
- import f from "prop-types";
10
- import { jsx as p, jsxs as m } from "react/jsx-runtime";
11
- import h from "debug";
12
- import g from "@mui/material/LinearProgress";
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
- h("@pie-lib:editable-html:plugins:image:component");
15
- var _ = u(g, { shouldForwardProp: (e) => e !== "hideProgress" })(({ hideProgress: e }) => ({
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
- })), v = u("div", { shouldForwardProp: (e) => ![
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
- })), y = u("div")(({ theme: e }) => ({
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
- })), b = u("img", { shouldForwardProp: (e) => e !== "active" })(({ theme: e, active: t }) => ({ border: t ? `solid 1px ${e.palette.primary.main}` : "solid 1px transparent" })), x = u("div")(({ theme: e }) => ({
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
- })), S = (e) => e ? `${e}px` : "calc(20px)";
48
- function C(u) {
49
- let { node: f, editor: h, attributes: g, onFocus: C, getPos: w, selected: T, options: E, maxImageWidth: D = 700, maxImageHeight: O = 900 } = u, { alt: k } = f.attrs, A = w(), j = h.state.selection.from, M = h.state.selection.to, N = a(() => j + f.nodeSize === M, [
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
- f.nodeSize
53
- ]), [P, F] = s(!1), I = o(f), L = o(null), R = o(null), z = o(null), B = r((e) => {
54
- let t = e / L.current.naturalWidth * 4;
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
- }, []), V = r(() => {
57
- let e = I.current.attrs.nodeKey, t = null;
58
- return h.state.doc.descendants((n, r) => {
59
- if (t !== null) return !1;
60
- if (n.type.name === "imageUploadNode" && n.attrs.nodeKey === e) return t = r, !1;
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 = h.state.doc.nodeAt(t);
66
- n && h.view.dispatch(h.state.tr.setNodeMarkup(t, void 0, {
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
- }, [h, V]), U = r(() => {
71
- if (!f.attrs.width || !L.current || !L.current.naturalWidth) return;
72
- let e = B(f.attrs.width);
73
- f.attrs.resizePercent !== e && H({ resizePercent: e });
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
- f.attrs.width,
76
- f.attrs.resizePercent,
77
- B,
78
- H
73
+ p.attrs.width,
74
+ p.attrs.resizePercent,
75
+ V,
76
+ U
79
77
  ]);
80
- i(() => {
81
- I.current = {
82
- ...f,
83
- pos: A
78
+ a(() => {
79
+ L.current = {
80
+ ...p,
81
+ pos: j
84
82
  };
85
- }, [f, A]), i(() => {
86
- T ? N && h.isEditable && (!String(f.attrs?.src ?? "").trim() && E.imageHandling?.insertImageRequested && E.imageHandling.insertImageRequested(h, [f, A], (e) => new t(h, [f, A], e)), F(T)) : F(T);
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
- N,
89
- T,
90
- h.isEditable
91
- ]), i(() => {
92
- U();
93
- let e = R?.current;
94
- return e && h.isEditable && e.addEventListener("mousedown", Y, !1), () => {
95
- e && e.removeEventListener("mousedown", Y, !1);
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
- }, []), i(() => {
98
- U();
95
+ }, []), a(() => {
96
+ W();
99
97
  });
100
- let W = r(() => {
101
- let e = L.current;
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, D), n = Math.min(e.naturalHeight, O);
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
- c(r, {
110
- width: f.attrs.width,
111
- height: f.attrs.height
112
- }) || H(r);
107
+ l(r, {
108
+ width: p.attrs.width,
109
+ height: p.attrs.height
110
+ }) || U(r);
113
111
  }
114
112
  }, [
115
- f.attrs.width,
116
- f.attrs.height,
117
- D,
113
+ p.attrs.width,
114
+ p.attrs.height,
118
115
  O,
119
- H
120
- ]), G = (e, t, n = !0, r) => {
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
- }, K = r((e) => {
133
- let t = L.current;
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 = G(r, {
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`, H({
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
- }, [h, H]), q = r((e) => {
147
- H(e);
148
- }, [h, H]), J = r(() => {
149
- window.removeEventListener("mousemove", K), window.removeEventListener("mouseup", J);
150
- }, [K]), Y = r(() => {
151
- window.addEventListener("mousemove", K), window.addEventListener("mouseup", J);
152
- }, [K, J]), X = {
153
- width: S(f.attrs.width),
154
- height: S(f.attrs.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
- }, Z = {
154
+ }, Q = {
157
155
  left: "flex-start",
158
156
  center: "center",
159
157
  right: "flex-end"
160
- }[f.attrs.alignment] || "flex-start";
161
- return /* @__PURE__ */ m(l, { children: [/* @__PURE__ */ m(v, {
162
- onFocus: C,
163
- loading: !f.attrs.loaded,
164
- pendingDelete: f.attrs.deleteStatus === "pending",
165
- style: { justifyContent: Z },
166
- children: [/* @__PURE__ */ p(_, {
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: f.attrs.percent || 0,
169
- hideProgress: f.attrs.loaded
170
- }), /* @__PURE__ */ m(y, {
166
+ value: p.attrs.percent || 0,
167
+ hideProgress: p.attrs.loaded
168
+ }), /* @__PURE__ */ h(b, {
171
169
  onDragStart: (e) => e.preventDefault(),
172
- children: [/* @__PURE__ */ p(b, {
173
- ...g,
174
- active: T && f.attrs.loaded,
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: h.isEditable ? void 0 : "none" }
182
+ style: { display: g.isEditable ? void 0 : "none" }
185
183
  })]
186
184
  })]
187
- }), P && h._tiptapContainerEl && d.createPortal(/* @__PURE__ */ p("div", {
188
- ref: z,
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__ */ p(e, {
193
+ children: /* @__PURE__ */ m(e, {
196
194
  showDone: !0,
197
195
  deletable: !0,
198
- toolbarOpts: E.toolbarOpts || {},
196
+ toolbarOpts: D.toolbarOpts || {},
199
197
  onDelete: () => {
200
- let e = V();
201
- e !== null && (E.imageHandling?.onDelete?.(I.current), h.view.dispatch(h.state.tr.delete(e, e + h.state.doc.nodeAt(e).nodeSize)), F(!1), h.commands.focus());
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
- F(!1), E.imageHandling?.onDone?.(h), h.commands.focus("end");
202
+ I(!1), D.imageHandling?.onDone?.(g), g.commands.focus("end");
205
203
  },
206
- children: /* @__PURE__ */ p(n, {
207
- disableImageAlignmentButtons: E.imageHandling?.disableImageAlignmentButtons,
208
- alt: f.attrs.alt,
209
- imageLoaded: f.attrs.loaded,
210
- alignment: f.attrs.alignment || "left",
211
- onChange: q
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
- }), h._tiptapContainerEl)] });
212
+ }), g._tiptapContainerEl)] });
215
213
  }
216
- C.propTypes = {
217
- node: f.object.isRequired,
218
- editor: f.object.isRequired,
219
- attributes: f.object,
220
- onFocus: f.func,
221
- maxImageWidth: f.number,
222
- maxImageHeight: f.number
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 { C as default };
223
+ export { w as default };
@@ -1,11 +1,13 @@
1
- import e from "./image-component.js";
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 t } from "@tiptap/react";
4
- import { Node as n, mergeAttributes as r } from "@tiptap/core";
5
- import { Plugin as i } from "@tiptap/pm/state";
6
- import { jsx as a } from "react/jsx-runtime";
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 o = n.create({
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", r(e, { "data-type": "image-upload-node" })];
33
+ return ["img", o(e, { "data-type": "image-upload-node" })];
32
34
  },
33
35
  addNodeView() {
34
- return t((t) => /* @__PURE__ */ a(e, {
35
- ...t,
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: `img-${Date.now()}-${Math.random().toString(36).slice(2)}` }
44
+ attrs: { nodeKey: t() }
43
45
  }) };
44
46
  },
45
47
  addProseMirrorPlugins() {
46
- let e = this.editor;
47
- return [new i({ props: { handlePaste(t, n) {
48
- let r = Array.from(n.clipboardData?.items || []).find((e) => e.kind === "file" && e.type.startsWith("image/"));
49
- if (!r) return !1;
50
- let i = r.getAsFile();
51
- if (!i) return !1;
52
- let a = new FileReader();
53
- return a.onload = () => {
54
- let t = a.result;
55
- typeof t == "string" && e.commands.insertContent({
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: !0,
60
- nodeKey: `img-${Date.now()}-${Math.random().toString(36).slice(2)}`
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
- }, a.readAsDataURL(i), !0;
72
+ }, d.readAsDataURL(c), !0;
64
73
  } } })];
65
74
  }
66
75
  });
67
76
  //#endregion
68
- export { o as ImageUploadNode };
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.35",
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.41",
17
- "@pie-lib/math-input": "9.0.0-next.6",
18
- "@pie-lib/math-toolbar": "4.0.0-next.41",
19
- "@pie-lib/render-ui": "6.2.0-next.41",
20
- "@tiptap/core": "3.20.0",
21
- "@tiptap/extension-character-count": "3.20.0",
22
- "@tiptap/extension-color": "3.20.0",
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.20.0",
25
- "@tiptap/extension-placeholder": "3.20.0",
26
- "@tiptap/extension-subscript": "3.20.0",
27
- "@tiptap/extension-superscript": "3.20.0",
28
- "@tiptap/extension-table": "3.20.0",
29
- "@tiptap/extension-table-cell": "3.20.0",
30
- "@tiptap/extension-table-header": "3.30.5",
31
- "@tiptap/extension-table-row": "3.30.1",
32
- "@tiptap/extension-text-align": "3.20.0",
33
- "@tiptap/extension-text-style": "3.20.0",
34
- "@tiptap/pm": "3.30.2",
35
- "@tiptap/react": "3.20.0",
36
- "@tiptap/starter-kit": "3.20.0",
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": "^3.31.3",
52
- "@tiptap/extension-list": "^3.20.0",
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
  },