@pie-lib/editable-html-tip-tap 3.1.2-next.20261019223635 → 3.1.2-next.20261020155912

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.
@@ -6,11 +6,11 @@ import { ExtendedTableCell as i, ExtendedTableHeader as a } from "../extensions/
6
6
  import { DivNode as o } from "../extensions/div-node.js";
7
7
  import { EnsureEmptyRootIsDiv as ee } from "../extensions/ensure-empty-root-div.js";
8
8
  import { EnsureListItemContentIsDiv as s } from "../extensions/ensure-list-item-content-is-div.js";
9
- import { DragInTheBlankNode as c, ExplicitConstructedResponseNode as te, InlineDropdownNode as l, MathTemplatedNode as ne, ResponseAreaExtension as re } from "../extensions/responseArea.js";
10
- import { MathNode as ie } from "../extensions/math.js";
11
- import { ImageUploadNode as ae, uploadPastedImage as oe } from "../extensions/image.js";
12
- import { Media as se } from "../extensions/media.js";
13
- import { CSSMark as u } from "../extensions/css.js";
9
+ import { DragInTheBlankNode as c, ExplicitConstructedResponseNode as l, InlineDropdownNode as u, MathTemplatedNode as te, ResponseAreaExtension as ne } from "../extensions/responseArea.js";
10
+ import { MathNode as re } from "../extensions/math.js";
11
+ import { ImageUploadNode as ie, uploadPastedImage as ae } from "../extensions/image.js";
12
+ import { Media as oe } from "../extensions/media.js";
13
+ import { CSSMark as se } from "../extensions/css.js";
14
14
  import { ExtendedListItem as ce } from "../extensions/extended-list-item.js";
15
15
  import { HeadingParagraph as le } from "../extensions/heading-paragraph.js";
16
16
  import { valueToSize as d } from "../utils/size.js";
@@ -26,22 +26,21 @@ import { CharacterCount as ge } from "@tiptap/extension-character-count";
26
26
  import _e from "@tiptap/extension-superscript";
27
27
  import ve from "@tiptap/extension-subscript";
28
28
  import ye from "@tiptap/extension-text-align";
29
- import be from "@tiptap/extension-image";
30
- import xe from "@tiptap/extension-placeholder";
31
- import { TableRow as x } from "@tiptap/extension-table-row";
32
- import { jsx as S } from "react/jsx-runtime";
29
+ import be from "@tiptap/extension-placeholder";
30
+ import { TableRow as xe } from "@tiptap/extension-table-row";
31
+ import { jsx as x } from "react/jsx-runtime";
33
32
  //#region src/components/EditableHtml.tsx
34
- var C = {
33
+ var S = {
35
34
  position: "bottom",
36
35
  alignment: "left",
37
36
  alwaysVisible: !1,
38
37
  showDone: !0,
39
38
  doneOn: "blur"
40
- }, w = {
39
+ }, C = {
41
40
  options: {},
42
41
  respAreaToolbar: () => {},
43
42
  onHandleAreaChange: () => {}
44
- }, T = [
43
+ }, w = [
45
44
  "bold",
46
45
  "italic",
47
46
  "underline",
@@ -63,7 +62,7 @@ var C = {
63
62
  "h3",
64
63
  "undo",
65
64
  "redo"
66
- ], E = {
65
+ ], T = {
67
66
  bold: "bold",
68
67
  italic: "italic",
69
68
  underline: "underline",
@@ -74,7 +73,7 @@ var C = {
74
73
  "numbered-list": "orderedList",
75
74
  table: "table",
76
75
  image: "image"
77
- }, D = {
76
+ }, E = {
78
77
  "--white": "#fff",
79
78
  "--black": "#2e2b29",
80
79
  "--black-contrast": "#110f0e",
@@ -93,7 +92,7 @@ var C = {
93
92
  "--red": "#ff5c33",
94
93
  "--red-light": "#ffebe5",
95
94
  "--shadow": "0px 12px 33px 0px rgba(0, 0, 0, .06),\n 0px 3.618px 9.949px 0px rgba(0, 0, 0, .04)"
96
- }, O = (e, t, n) => ({
95
+ }, D = (e, t, n) => ({
97
96
  role: "textbox",
98
97
  "data-pie-editor": "true",
99
98
  class: "mathjax_ignore",
@@ -102,50 +101,50 @@ var C = {
102
101
  autocapitalize: e ? "on" : "off",
103
102
  ...t && { "aria-label": t },
104
103
  ...n && { "aria-labelledby": n }
105
- }), k = ["aria-label", "aria-labelledby"], A = (e) => e._insertingImage || e._toolbarOpened || e.isActive("inline_dropdown") || e.isActive("explicit_constructed_response"), j = (y) => {
106
- let { showParagraphs: b, separateParagraphs: j } = y.pluginProps || {}, [Se, N] = _([]), [Ce, we] = _(!1), { toolbarOpts: Te } = y, P = p((e) => {
107
- N((t) => {
104
+ }), O = ["aria-label", "aria-labelledby"], k = (e) => e._insertingImage || e._toolbarOpened || e.isActive("inline_dropdown") || e.isActive("explicit_constructed_response"), A = (y) => {
105
+ let { showParagraphs: b, separateParagraphs: A } = y.pluginProps || {}, [Se, M] = _([]), [Ce, we] = _(!1), { toolbarOpts: Te } = y, N = p((e) => {
106
+ M((t) => {
108
107
  let n = t.filter((t) => t.pos !== e);
109
108
  return n.length === 0 && we(!1), n;
110
109
  });
111
- }, [N]), F = {
112
- ...C,
110
+ }, [M]), P = {
111
+ ...S,
113
112
  ...Te
114
- }, I = g([]), L = (e) => {
115
- I.current = [...I.current.slice(-4), e], y.onChange?.(e);
116
- }, R = g(L);
117
- R.current = L;
118
- let z = p((e) => {
113
+ }, F = g([]), I = (e) => {
114
+ F.current = [...F.current.slice(-4), e], y.onChange?.(e);
115
+ }, L = g(I);
116
+ L.current = I;
117
+ let R = p((e) => {
119
118
  let t = e.getHTML();
120
- y.markup !== t && R.current(t), F.doneOn === "blur" && y.onDone?.(t);
119
+ y.markup !== t && L.current(t), P.doneOn === "blur" && y.onDone?.(t);
121
120
  }, [
122
121
  y.markup,
123
122
  y.onChange,
124
123
  y.onDone,
125
- F.doneOn
126
- ]), B = g(z);
127
- B.current = z;
128
- let { idleSaveDelay: V } = y, H = g(!1), U = h(() => V > 0 ? v((e) => {
129
- e.isDestroyed || (!H.current && (e.view.composing || A(e)) ? W.current?.(e) : B.current(e));
130
- }, V) : null, [V]), W = g(U);
131
- W.current = U;
132
- let G = p((e) => {
133
- H.current = !0;
124
+ P.doneOn
125
+ ]), z = g(R);
126
+ z.current = R;
127
+ let { idleSaveDelay: B } = y, V = g(!1), H = h(() => B > 0 ? v((e) => {
128
+ e.isDestroyed || (!V.current && (e.view.composing || k(e)) ? U.current?.(e) : z.current(e));
129
+ }, B) : null, [B]), U = g(H);
130
+ U.current = H;
131
+ let W = p((e) => {
132
+ V.current = !0;
134
133
  try {
135
134
  e?.flush();
136
135
  } finally {
137
- H.current = !1;
136
+ V.current = !1;
138
137
  }
139
138
  }, []);
140
- m(() => () => G(U), [U, G]);
141
- let Ee = p(() => G(W.current), [G]), K = h(() => ({
142
- ...w,
139
+ m(() => () => W(H), [H, W]);
140
+ let G = p(() => W(U.current), [W]), K = h(() => ({
141
+ ...C,
143
142
  ...y.responseAreaProps,
144
- onInlineDropdownToolbarClose: z
145
- }), [y.responseAreaProps, z]), q = h(() => {
143
+ onInlineDropdownToolbarClose: R
144
+ }), [y.responseAreaProps, R]), q = h(() => {
146
145
  let { customPlugins: e, ...t } = y.pluginProps || {};
147
146
  e ||= [];
148
- let n = (y.activePlugins || T)?.filter((e) => {
147
+ let n = (y.activePlugins || w)?.filter((e) => {
149
148
  let n = de[e] || e, r = t[n] || {};
150
149
  return !r || !r.disabled;
151
150
  });
@@ -166,9 +165,9 @@ var C = {
166
165
  }, [y, K.type]), J = g(null);
167
166
  J.current = {
168
167
  plainText: y.pluginProps?.pasteFormatting?.disabled === !0,
169
- formatting: q.map((e) => E[e]).filter(Boolean)
168
+ formatting: q.map((e) => T[e]).filter(Boolean)
170
169
  };
171
- let De = [
170
+ let Ee = [
172
171
  ye.configure({
173
172
  types: [
174
173
  "heading",
@@ -194,7 +193,7 @@ var C = {
194
193
  he,
195
194
  e.configure({
196
195
  settings: () => J.current,
197
- uploadImage: y.imageSupport && oe
196
+ uploadImage: y.imageSupport && ae
198
197
  }),
199
198
  ge.configure({ limit: y.charactersLimit || 1e6 }),
200
199
  me.configure({
@@ -212,47 +211,46 @@ var C = {
212
211
  le,
213
212
  ee,
214
213
  s,
215
- xe.configure({
214
+ be.configure({
216
215
  placeholder: y.placeholder,
217
216
  showOnlyWhenEditable: !0,
218
217
  showOnlyCurrent: !1,
219
218
  includeChildren: !0
220
219
  }),
221
220
  r,
222
- x,
221
+ xe,
223
222
  a,
224
223
  i,
225
- re.configure(K),
226
- te.configure(K),
227
- c.configure(K),
228
- l.configure(K),
229
224
  ne.configure(K),
230
- ie.configure({
231
- toolbarOpts: F,
225
+ l.configure(K),
226
+ c.configure(K),
227
+ u.configure(K),
228
+ te.configure(K),
229
+ re.configure({
230
+ toolbarOpts: P,
232
231
  math: y.pluginProps?.math || {}
233
232
  }),
234
233
  ve,
235
234
  _e,
236
- be,
237
- ae.configure({
238
- toolbarOpts: F,
235
+ ie.configure({
236
+ toolbarOpts: P,
239
237
  imageHandling: {
240
238
  disableImageAlignmentButtons: y.disableImageAlignmentButtons,
241
239
  onDone: (e) => y.onDone?.(e.getHTML()),
242
240
  onDelete: y.imageSupport && y.imageSupport.delete && ((e) => {
243
241
  let { src: t } = e.attrs;
244
242
  y.imageSupport.delete(t, (t) => {
245
- P(e.pos);
243
+ N(e.pos);
246
244
  });
247
245
  }),
248
246
  insertImageRequested: y.imageSupport && ((e, t, n) => {
249
247
  let [r, i] = t, a = (t) => {
250
248
  let n;
251
- Ce && t && (n = R.current), P(i), n?.(e.getHTML());
249
+ Ce && t && (n = L.current), N(i), n?.(e.getHTML());
252
250
  };
253
- e._insertingImage = !0, N((e) => [...e, r]), (() => {
251
+ e._insertingImage = !0, M((e) => [...e, r]), (() => {
254
252
  let t = n(a), r = v(() => {
255
- e._insertingImage &&= (P(i), !1), window.removeEventListener("focus", r);
253
+ e._insertingImage &&= (N(i), !1), window.removeEventListener("focus", r);
256
254
  }, 500);
257
255
  window.addEventListener("focus", r), y.imageSupport.add(t);
258
256
  })();
@@ -262,13 +260,13 @@ var C = {
262
260
  },
263
261
  limit: 3
264
262
  }),
265
- se.configure({ uploadSoundSupport: y.uploadSoundSupport }),
266
- u.configure({ extraCSSRules: y.extraCSSRules })
263
+ oe.configure({ uploadSoundSupport: y.uploadSoundSupport }),
264
+ se.configure({ extraCSSRules: y.extraCSSRules })
267
265
  ], Y = y.spellCheck !== !1, { ariaLabel: X, ariaLabelledBy: Z } = y, Q = fe({
268
- extensions: De,
266
+ extensions: Ee,
269
267
  immediatelyRender: !1,
270
268
  editorProps: {
271
- attributes: O(Y, X, Z),
269
+ attributes: D(Y, X, Z),
272
270
  handleKeyDown(e, t) {
273
271
  return y.onKeyDown ? y.onKeyDown(t) : !1;
274
272
  }
@@ -276,10 +274,10 @@ var C = {
276
274
  editable: !y.disabled,
277
275
  content: t(y.markup),
278
276
  onUpdate: ({ editor: e, transaction: t }) => {
279
- t.isDone && R.current(e.getHTML()), t.docChanged && W.current && (W.current(e), n(e.view.dom, Ee));
277
+ t.isDone && L.current(e.getHTML()), t.docChanged && U.current && (U.current(e), n(e.view.dom, G));
280
278
  },
281
279
  onBlur: ({ editor: e }) => {
282
- !A(e) && e.schema && (W.current?.cancel(), z(e));
280
+ !k(e) && e.schema && (U.current?.cancel(), R(e));
283
281
  }
284
282
  }, [y.charactersLimit]);
285
283
  m(() => {
@@ -287,12 +285,12 @@ var C = {
287
285
  }, [y.editorRef, Q]), m(() => {
288
286
  Q?.setEditable(!y.disabled);
289
287
  }, [y.disabled, Q]), m(() => {
290
- Q?.on("destroy", () => G(W.current));
291
- }, [Q, G]), m(() => {
288
+ Q?.on("destroy", () => W(U.current));
289
+ }, [Q, W]), m(() => {
292
290
  if (!Q) return;
293
- let e = Q.options?.editorProps, t = e?.attributes || {}, n = O(Y, X, Z);
294
- if (["spellcheck", ...k].every((e) => t[e] === n[e])) return;
295
- let r = Object.fromEntries(Object.entries(t).filter(([e]) => !k.includes(e)));
291
+ let e = Q.options?.editorProps, t = e?.attributes || {}, n = D(Y, X, Z);
292
+ if (["spellcheck", ...O].every((e) => t[e] === n[e])) return;
293
+ let r = Object.fromEntries(Object.entries(t).filter(([e]) => !O.includes(e)));
296
294
  Q.setOptions({ editorProps: {
297
295
  ...e,
298
296
  attributes: {
@@ -306,16 +304,16 @@ var C = {
306
304
  Z,
307
305
  Q
308
306
  ]), m(() => {
309
- if (!Q || I.current.includes(y.markup)) return;
310
- I.current = [];
307
+ if (!Q || F.current.includes(y.markup)) return;
308
+ F.current = [];
311
309
  let e = t(y.markup);
312
310
  e !== Q.getHTML() && Q.commands.setContent(e, { emitUpdate: !1 });
313
311
  }, [y.markup, Q]), m(() => {
314
- Object.entries(D).forEach(([e, t]) => {
312
+ Object.entries(E).forEach(([e, t]) => {
315
313
  document.documentElement.style.setProperty(e, t);
316
314
  });
317
315
  }, []);
318
- let Oe = pe({
316
+ let De = pe({
319
317
  editor: Q,
320
318
  selector: (e) => ({ isFocused: e.editor?.isFocused })
321
319
  }), $ = h(() => {
@@ -329,24 +327,24 @@ var C = {
329
327
  maxHeight: d(a)
330
328
  };
331
329
  }, [y]);
332
- return /* @__PURE__ */ S(ue, {
330
+ return /* @__PURE__ */ x(ue, {
333
331
  ...y,
334
332
  activePlugins: q,
335
- toolbarOpts: F,
336
- editorState: Oe,
333
+ toolbarOpts: P,
334
+ editorState: De,
337
335
  editor: Q,
338
- children: Q && /* @__PURE__ */ S(M, {
336
+ children: Q && /* @__PURE__ */ x(j, {
339
337
  style: {
340
338
  minHeight: $.minHeight,
341
339
  height: $.height,
342
340
  maxHeight: $.maxHeight
343
341
  },
344
342
  showParagraph: b && !b.disabled,
345
- separateParagraph: j && !j.disabled,
343
+ separateParagraph: A && !A.disabled,
346
344
  editor: Q
347
345
  })
348
346
  });
349
- }, M = b(y, { shouldForwardProp: (e) => !["showParagraph", "separateParagraph"].includes(e) })(({ showParagraph: e, separateParagraph: t }) => ({
347
+ }, j = b(y, { shouldForwardProp: (e) => !["showParagraph", "separateParagraph"].includes(e) })(({ showParagraph: e, separateParagraph: t }) => ({
350
348
  display: "flex",
351
349
  outline: "none !important",
352
350
  "& .ProseMirror": {
@@ -376,4 +374,4 @@ var C = {
376
374
  }
377
375
  }));
378
376
  //#endregion
379
- export { j as EditableHtml, j as default };
377
+ export { A as EditableHtml, A as default };
@@ -1,3 +1,2 @@
1
1
  import { Mark } from '@tiptap/core';
2
- export declare const removeDialogs: () => void;
3
2
  export declare const CSSMark: Mark<any, any>;
@@ -6,28 +6,31 @@ import { createRoot as a } from "react-dom/client";
6
6
  import o from "@mui/material/List";
7
7
  import s from "@mui/material/ListItem";
8
8
  //#region src/extensions/css.tsx
9
- var c = () => {
10
- document.querySelectorAll(".insert-css-dialog").forEach((e) => e.remove());
11
- }, l = ({ editor: e, callback: t, opts: l, selectedText: u, parentNode: d }) => {
9
+ var c = null, l = ({ editor: e, callback: t, opts: l, selectedText: u, parentNode: d }) => {
10
+ c?.();
12
11
  let f = e.options.element, p = document.createElement("div"), { selection: m } = e.state;
13
- c(), p.className = "insert-css-dialog";
12
+ p.className = "insert-css-dialog";
14
13
  let h = a(p), g, _ = !1, v = (e) => {
15
14
  if (_) {
16
15
  let t = p.contains(e.target) || g, n = f.contains(e.target);
17
- t || n || y();
16
+ t || n || b();
18
17
  } else _ = !0;
19
18
  }, y = () => {
20
- t(void 0, !0), h.unmount(), p.remove(), document.body.removeEventListener("click", v);
21
- }, b = (e) => {
22
- t(e, !0), h.unmount(), p.remove(), document.body.removeEventListener("click", v);
23
- }, x = d?.attrs.class, S = (e) => {
19
+ h.unmount(), p.remove(), document.body.removeEventListener("click", v), c === y && (c = null);
20
+ };
21
+ c = y;
22
+ let b = () => {
23
+ t(void 0, !0), y();
24
+ }, x = (e) => {
25
+ t(e, !0), y();
26
+ }, S = d?.attrs.class, C = (e) => {
24
27
  let t = `<span class="${e}">${u}</span>`;
25
28
  if (d) {
26
29
  let e = "span";
27
- d?.object === "inline" && (e = "span"), d?.object === "block" && (e = "div"), t = `<${e} class="${x}">${d.text.slice(0, m.$anchor.textOffset)}${t}${d.text.slice(m.$head.textOffset)}</${e}>`;
30
+ d?.object === "inline" && (e = "span"), d?.object === "block" && (e = "div"), t = `<${e} class="${S}">${d.text.slice(0, m.$anchor.textOffset)}${t}${d.text.slice(m.$head.textOffset)}</${e}>`;
28
31
  }
29
32
  return t;
30
- }, C = /* @__PURE__ */ i("div", {
33
+ }, w = /* @__PURE__ */ i("div", {
31
34
  style: {
32
35
  background: "white",
33
36
  height: 500,
@@ -38,22 +41,22 @@ var c = () => {
38
41
  },
39
42
  children: [
40
43
  /* @__PURE__ */ r("h2", { children: "Please choose a css class" }),
41
- x && /* @__PURE__ */ i("div", { children: ["The current parent has this class ", x] }),
44
+ S && /* @__PURE__ */ i("div", { children: ["The current parent has this class ", S] }),
42
45
  /* @__PURE__ */ r(o, {
43
46
  component: "nav",
44
47
  style: { overflow: "scroll" },
45
48
  children: l.names.map((e, t) => /* @__PURE__ */ i(s, {
46
49
  button: !0,
47
- onClick: () => b(e),
50
+ onClick: () => x(e),
48
51
  children: [/* @__PURE__ */ r("div", {
49
52
  style: { marginRight: 20 },
50
53
  children: e
51
- }), /* @__PURE__ */ r("div", { dangerouslySetInnerHTML: { __html: S(e) } })]
54
+ }), /* @__PURE__ */ r("div", { dangerouslySetInnerHTML: { __html: C(e) } })]
52
55
  }, `rule-${t}`))
53
56
  })
54
57
  ]
55
58
  });
56
- n(() => h.render(C)), (() => {
59
+ n(() => h.render(w)), (() => {
57
60
  let t = e.view.nodeDOM(e.state.selection.from)?.parentNode;
58
61
  if (t) {
59
62
  let e = f.parentElement.parentElement.parentElement.getBoundingClientRect(), n = t.getBoundingClientRect();
@@ -118,4 +121,4 @@ var c = () => {
118
121
  }
119
122
  });
120
123
  //#endregion
121
- export { u as CSSMark, c as removeDialogs };
124
+ export { u as CSSMark };
@@ -1,5 +1,5 @@
1
1
  import { ListItem as e } from "@tiptap/extension-list-item";
2
2
  //#region src/extensions/extended-list-item.tsx
3
- var t = e.extend({ content: "(div | paragraph | heading | bulletList | orderedList | blockquote | codeBlock | horizontalRule | image | imageUploadNode)+" });
3
+ var t = e.extend({ content: "(div | paragraph | heading | bulletList | orderedList | blockquote | codeBlock | horizontalRule | imageUploadNode)+" });
4
4
  //#endregion
5
5
  export { t as ExtendedListItem };
@@ -2,7 +2,7 @@ import { scopeAttribute as e } from "./table-semantics.js";
2
2
  import { TableCell as t } from "@tiptap/extension-table-cell";
3
3
  import { TableHeader as n } from "@tiptap/extension-table-header";
4
4
  //#region src/extensions/extended-table-cell.ts
5
- var r = "(div | paragraph | heading | bulletList | orderedList | blockquote | codeBlock | horizontalRule | image | imageUploadNode)+", i = t.extend({ content: r }), a = n.extend({
5
+ var r = "(div | paragraph | heading | bulletList | orderedList | blockquote | codeBlock | horizontalRule | imageUploadNode)+", i = t.extend({ content: r }), a = n.extend({
6
6
  content: r,
7
7
  addAttributes() {
8
8
  return {
@@ -7,8 +7,6 @@ declare namespace ImageComponent {
7
7
  editor: PropTypes.Validator<object>;
8
8
  attributes: PropTypes.Requireable<object>;
9
9
  onFocus: PropTypes.Requireable<(...args: any[]) => any>;
10
- maxImageWidth: PropTypes.Requireable<number>;
11
- maxImageHeight: PropTypes.Requireable<number>;
12
10
  };
13
11
  }
14
12
  export default ImageComponent;
@@ -46,60 +46,74 @@ var y = f(v, { shouldForwardProp: (e) => e !== "hideProgress" })(({ hideProgress
46
46
  marginLeft: "5px",
47
47
  marginRight: "10px",
48
48
  display: "none"
49
- })), w = (e) => e ? `${e}px` : "calc(20px)";
50
- function T(f) {
51
- let { node: m, editor: _, attributes: v, onFocus: T, getPos: E, selected: D, options: O, maxImageWidth: k = 700, maxImageHeight: A = 900 } = f, { alt: j } = m.attrs, M = E(), N = _.state.selection.from, P = _.state.selection.to, F = s(() => N + m.nodeSize === P, [
52
- N,
53
- P,
49
+ })), w = (e) => e ? `${e}px` : "calc(20px)", T = 700, E = 900, D = ({ width: e, height: t }, n, r) => {
50
+ let i = Math.min(1, n / e, r / t);
51
+ return i < 1 ? {
52
+ width: Math.round(e * i),
53
+ height: Math.round(t * i)
54
+ } : {
55
+ width: e,
56
+ height: t
57
+ };
58
+ };
59
+ function O(f) {
60
+ let { node: m, editor: _, attributes: v, onFocus: O, getPos: k, selected: A, options: j } = f;
61
+ console.log({ ...f.options });
62
+ let M = j?.imageHandling?.maxImageWidth || T, N = j?.imageHandling?.maxImageHeight || E, { alt: ee } = m.attrs, P = k(), F = _.state.selection.from, I = _.state.selection.to, L = s(() => F + m.nodeSize === I, [
63
+ F,
64
+ I,
54
65
  m.nodeSize
55
- ]), [I, L] = l(!1), R = c(m), z = c(null), B = c(null), V = c(null), H = a((e) => {
56
- let t = e / z.current.naturalWidth * 4;
66
+ ]), [R, z] = l(!1), B = c(m), V = c(null), H = c(null), U = c(null), W = a((e) => {
67
+ let t = e / V.current.naturalWidth * 4;
57
68
  return parseInt(t.toFixed(0) * 25, 10);
58
- }, []), U = a(() => {
59
- let e = n(_, R.current.attrs.nodeKey);
69
+ }, []), G = a(() => {
70
+ let e = n(_, B.current.attrs.nodeKey);
60
71
  return e ? e[1] : null;
61
- }, [_]), W = a((e) => {
62
- let t = U();
72
+ }, [_]), K = a((e) => {
73
+ let t = G();
63
74
  if (t === null) return;
64
75
  let n = _.state.doc.nodeAt(t);
65
76
  n && _.view.dispatch(_.state.tr.setNodeMarkup(t, void 0, {
66
77
  ...n.attrs,
67
78
  ...e
68
79
  }));
69
- }, [_, U]), G = a(() => {
70
- if (!m.attrs.width || !z.current || !z.current.naturalWidth) return;
71
- let e = H(m.attrs.width);
72
- m.attrs.resizePercent !== e && W({ resizePercent: e });
80
+ }, [_, G]), q = a(() => {
81
+ if (!m.attrs.width || !V.current || !V.current.naturalWidth) return;
82
+ let e = W(m.attrs.width);
83
+ m.attrs.resizePercent !== e && K({ resizePercent: e });
73
84
  }, [
74
85
  m.attrs.width,
75
86
  m.attrs.resizePercent,
76
- H,
77
- W
87
+ W,
88
+ K
78
89
  ]);
79
90
  o(() => {
80
- R.current = {
91
+ B.current = {
81
92
  ...m,
82
- pos: M
93
+ pos: P
83
94
  };
84
- }, [m, M]), o(() => {
85
- D ? F && _.isEditable && (!String(m.attrs?.src ?? "").trim() && O.imageHandling?.insertImageRequested && O.imageHandling.insertImageRequested(_, [m, M], (e) => new r(_, [m, M], e)), L(D)) : L(D);
95
+ }, [m, P]), o(() => {
96
+ A ? L && _.isEditable && (!String(m.attrs?.src ?? "").trim() && j.imageHandling?.insertImageRequested && j.imageHandling.insertImageRequested(_, [m, P], (e) => new r(_, [m, P], e)), z(A)) : z(A);
86
97
  }, [
87
- F,
88
- D,
98
+ L,
99
+ A,
89
100
  _.isEditable
90
101
  ]), o(() => {
91
- G();
92
- let e = B?.current;
93
- return e && _.isEditable && e.addEventListener("mousedown", Z, !1), () => {
94
- e && e.removeEventListener("mousedown", Z, !1);
102
+ q();
103
+ let e = H?.current;
104
+ return e && _.isEditable && e.addEventListener("mousedown", $, !1), () => {
105
+ e && e.removeEventListener("mousedown", $, !1);
95
106
  };
96
107
  }, []), o(() => {
97
- G();
108
+ q();
98
109
  });
99
- let K = a(() => {
100
- let e = z.current;
110
+ let J = a(() => {
111
+ let e = V.current;
101
112
  if (e && (!e.style.width || e.style.width === "calc(20px)")) {
102
- let t = Math.min(e.naturalWidth, k), n = Math.min(e.naturalHeight, A);
113
+ let { width: t, height: n } = D({
114
+ width: e.naturalWidth,
115
+ height: e.naturalHeight
116
+ }, M, N);
103
117
  e.style.width = `${t}px`, e.style.height = `${n}px`;
104
118
  let r = {
105
119
  width: t,
@@ -108,15 +122,15 @@ function T(f) {
108
122
  u(r, {
109
123
  width: m.attrs.width,
110
124
  height: m.attrs.height
111
- }) || W(r);
125
+ }) || K(r);
112
126
  }
113
127
  }, [
114
128
  m.attrs.width,
115
129
  m.attrs.height,
116
- k,
117
- A,
118
- W
119
- ]), q = (e, t, n = !0, r) => {
130
+ M,
131
+ N,
132
+ K
133
+ ]), Y = (e, t, n = !0, r) => {
120
134
  if (n) {
121
135
  let n = e.width / e.height;
122
136
  return r === "height" ? {
@@ -128,40 +142,45 @@ function T(f) {
128
142
  };
129
143
  }
130
144
  return t;
131
- }, J = a((e) => {
132
- let t = z.current;
145
+ }, X = a((e) => {
146
+ let t = V.current;
133
147
  if (!t) return;
134
148
  let n = e.target.getBoundingClientRect(), r = {
135
149
  width: t.naturalWidth,
136
150
  height: t.naturalHeight
137
- }, i = q(r, {
151
+ }, i = D(Y(r, {
138
152
  width: e.clientX - n.left,
139
153
  height: e.clientY - n.top
140
- });
141
- i.width > 50 && i.height > 50 && i.width <= 700 && i.height <= 900 && (t.style.width = `${i.width}px`, t.style.height = `${i.height}px`, W({
154
+ }), M, N);
155
+ i.width > 50 && i.height > 50 && (t.style.width = `${i.width}px`, t.style.height = `${i.height}px`, K({
142
156
  width: i.width,
143
157
  height: i.height
144
158
  }));
145
- }, [_, W]), Y = a((e) => {
146
- W(e);
147
- }, [_, W]), X = a(() => {
148
- window.removeEventListener("mousemove", J), window.removeEventListener("mouseup", X);
149
- }, [J]), Z = a(() => {
150
- window.addEventListener("mousemove", J), window.addEventListener("mouseup", X);
151
- }, [J, X]), Q = {
159
+ }, [
160
+ _,
161
+ K,
162
+ M,
163
+ N
164
+ ]), Z = a((e) => {
165
+ K(e);
166
+ }, [_, K]), Q = a(() => {
167
+ window.removeEventListener("mousemove", X), window.removeEventListener("mouseup", Q);
168
+ }, [X]), $ = a(() => {
169
+ window.addEventListener("mousemove", X), window.addEventListener("mouseup", Q);
170
+ }, [X, Q]), te = {
152
171
  width: w(m.attrs.width),
153
172
  height: w(m.attrs.height),
154
173
  objectFit: "contain"
155
- }, $ = {
174
+ }, ne = {
156
175
  left: "flex-start",
157
176
  center: "center",
158
177
  right: "flex-end"
159
178
  }[m.attrs.alignment] || "flex-start";
160
179
  return /* @__PURE__ */ g(d, { children: [/* @__PURE__ */ g(b, {
161
- onFocus: T,
180
+ onFocus: O,
162
181
  loading: !m.attrs.loaded,
163
182
  pendingDelete: m.attrs.deleteStatus === "pending",
164
- style: { justifyContent: $ },
183
+ style: { justifyContent: ne },
165
184
  children: [/* @__PURE__ */ h(y, {
166
185
  mode: "determinate",
167
186
  value: m.attrs.percent || 0,
@@ -170,21 +189,21 @@ function T(f) {
170
189
  onDragStart: (e) => e.preventDefault(),
171
190
  children: [/* @__PURE__ */ h(S, {
172
191
  ...v,
173
- active: D && m.attrs.loaded,
192
+ active: A && m.attrs.loaded,
174
193
  draggable: !1,
175
- ref: z,
194
+ ref: V,
176
195
  src: m.attrs.src,
177
- style: Q,
178
- onLoad: K,
196
+ style: te,
197
+ onLoad: J,
179
198
  alt: m.attrs.alt
180
199
  }), /* @__PURE__ */ h(C, {
181
- ref: B,
200
+ ref: H,
182
201
  className: "resize",
183
202
  style: { display: _.isEditable ? void 0 : "none" }
184
203
  })]
185
204
  })]
186
- }), I && _._tiptapContainerEl && p.createPortal(/* @__PURE__ */ h("div", {
187
- ref: V,
205
+ }), R && _._tiptapContainerEl && p.createPortal(/* @__PURE__ */ h("div", {
206
+ ref: U,
188
207
  style: {
189
208
  zIndex: 20,
190
209
  background: e,
@@ -194,31 +213,29 @@ function T(f) {
194
213
  children: /* @__PURE__ */ h(t, {
195
214
  showDone: !0,
196
215
  deletable: !0,
197
- toolbarOpts: O.toolbarOpts || {},
216
+ toolbarOpts: j.toolbarOpts || {},
198
217
  onDelete: () => {
199
- let e = U();
200
- e !== null && (O.imageHandling?.onDelete?.(R.current), _.view.dispatch(_.state.tr.delete(e, e + _.state.doc.nodeAt(e).nodeSize)), L(!1), _.commands.focus());
218
+ let e = G();
219
+ e !== null && (j.imageHandling?.onDelete?.(B.current), _.view.dispatch(_.state.tr.delete(e, e + _.state.doc.nodeAt(e).nodeSize)), z(!1), _.commands.focus());
201
220
  },
202
221
  onDone: () => {
203
- L(!1), O.imageHandling?.onDone?.(_), _.commands.focus("end");
222
+ z(!1), j.imageHandling?.onDone?.(_), _.commands.focus("end");
204
223
  },
205
224
  children: /* @__PURE__ */ h(i, {
206
- disableImageAlignmentButtons: O.imageHandling?.disableImageAlignmentButtons,
225
+ disableImageAlignmentButtons: j.imageHandling?.disableImageAlignmentButtons,
207
226
  alt: m.attrs.alt,
208
227
  imageLoaded: m.attrs.loaded,
209
228
  alignment: m.attrs.alignment || "left",
210
- onChange: Y
229
+ onChange: Z
211
230
  })
212
231
  })
213
232
  }), _._tiptapContainerEl)] });
214
233
  }
215
- T.propTypes = {
234
+ O.propTypes = {
216
235
  node: m.object.isRequired,
217
236
  editor: m.object.isRequired,
218
237
  attributes: m.object,
219
- onFocus: m.func,
220
- maxImageWidth: m.number,
221
- maxImageHeight: m.number
238
+ onFocus: m.func
222
239
  };
223
240
  //#endregion
224
- export { T as default };
241
+ export { O as default };
@@ -34,19 +34,31 @@ var f = a.create({
34
34
  draggable: !0,
35
35
  addAttributes() {
36
36
  return {
37
- nodeKey: { default: null },
38
- loaded: { default: !1 },
37
+ nodeKey: {
38
+ default: null,
39
+ parseHTML: (e) => e.getAttribute("nodeKey") || t()
40
+ },
41
+ loaded: {
42
+ default: !1,
43
+ parseHTML: (e) => e.hasAttribute("loaded") ? e.getAttribute("loaded") !== "false" : !/^data:/i.test(e.getAttribute("src") ?? "")
44
+ },
39
45
  deleteStatus: { default: null },
40
46
  alignment: { default: null },
41
47
  percent: { default: null },
42
- width: { default: null },
43
- height: { default: null },
48
+ width: {
49
+ default: null,
50
+ parseHTML: (e) => parseInt(e.getAttribute("width"), 10) || null
51
+ },
52
+ height: {
53
+ default: null,
54
+ parseHTML: (e) => parseInt(e.getAttribute("height"), 10) || null
55
+ },
44
56
  src: { default: null },
45
57
  alt: { default: null }
46
58
  };
47
59
  },
48
60
  parseHTML() {
49
- return [{ tag: "img[data-type=\"image-upload-node\"]" }];
61
+ return [{ tag: "img[data-type=\"image-upload-node\"]" }, { tag: "img[src]" }];
50
62
  },
51
63
  renderHTML({ HTMLAttributes: e }) {
52
64
  return ["img", o(e, { "data-type": "image-upload-node" })];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-lib/editable-html-tip-tap",
3
- "version": "3.1.2-next.20261019223635",
3
+ "version": "3.1.2-next.20261020155912",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -13,10 +13,10 @@
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": "5.0.7-next.20261019223635",
17
- "@pie-lib/math-input": "9.0.7-next.20261019223635",
18
- "@pie-lib/math-toolbar": "4.0.7-next.20261019223635",
19
- "@pie-lib/render-ui": "8.0.7-next.20261019223635",
16
+ "@pie-lib/drag": "5.0.7-next.20261020155912",
17
+ "@pie-lib/math-input": "9.0.7-next.20261020155912",
18
+ "@pie-lib/math-toolbar": "4.0.7-next.20261020155912",
19
+ "@pie-lib/render-ui": "8.0.7-next.20261020155912",
20
20
  "@pie-lib/translator": "5.0.2-next.20261019155156",
21
21
  "@tiptap/core": "3.32.0",
22
22
  "@tiptap/extension-character-count": "3.32.0",
@@ -43,7 +43,7 @@
43
43
  "react-portal": "^4.2.0",
44
44
  "tippy.js": "latest",
45
45
  "to-style": "^1.3.3",
46
- "@pie-element/shared-lodash": "0.1.3-next.20261019151920",
46
+ "@pie-element/shared-lodash": "0.1.3-next.20261020155912",
47
47
  "clsx": "^2.1.1",
48
48
  "prosemirror-state": "^1.4.4",
49
49
  "@pie-element/shared-math-rendering-mathjax": "0.1.8-next.20261019155156",