@qingwu-ui/ai-editor 0.9.0-beta.15 → 0.9.0-beta.16

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/index.js CHANGED
@@ -130,8 +130,8 @@ function Pe(e, t, n = "16px system-ui") {
130
130
  }
131
131
  //#endregion
132
132
  //#region ../toast/dist/index.mjs
133
- var Fe = typeof window < "u" && window.matchMedia("(prefers-reduced-motion: reduce)").matches, X = "13.5px -apple-system, BlinkMacSystemFont, \"SF Pro Text\", \"PingFang SC\", \"Microsoft YaHei\", system-ui, sans-serif";
134
- function Ie() {
133
+ var Fe = typeof window < "u" && window.matchMedia("(prefers-reduced-motion: reduce)").matches, Ie = "13.5px -apple-system, BlinkMacSystemFont, \"SF Pro Text\", \"PingFang SC\", \"Microsoft YaHei\", system-ui, sans-serif";
134
+ function X() {
135
135
  if (typeof window > "u") return 290;
136
136
  let e = window.innerWidth;
137
137
  return e <= 480 ? Math.max(140, e - 98) : 290;
@@ -280,10 +280,10 @@ var Ge = class {
280
280
  let c = Be("span", "qt-icon");
281
281
  c.innerHTML = Le[n], s.appendChild(c);
282
282
  let l = Be("div", "qt-body"), u = Be("span", "qt-msg"), d = Pe(t, {
283
- maxWidth: Ie(),
283
+ maxWidth: X(),
284
284
  lineHeight: 1,
285
285
  maxLines: i
286
- }, X);
286
+ }, Ie);
287
287
  if (d.lineCount <= 1 ? Ve(u, t) : d.lines.forEach((e, t) => {
288
288
  let n = Be("span", "qt-line"), r = e.text;
289
289
  t === d.lines.length - 1 && d.truncated && !r.endsWith("…") && (r += "…"), Ve(n, r), u.appendChild(n);
@@ -720,7 +720,7 @@ function ot(e) {
720
720
  let t = e.parentElement;
721
721
  for (; t && t !== document.documentElement;) {
722
722
  let e = getComputedStyle(t).overflowY;
723
- if (e === "auto" || e === "scroll" || e === "overlay") return t;
723
+ if ((e === "auto" || e === "scroll" || e === "overlay") && t.scrollHeight > t.clientHeight) return t;
724
724
  t = t.parentElement;
725
725
  }
726
726
  return null;
@@ -809,13 +809,22 @@ var ct = 84, lt = 3e3, ut = ({ editor: e, className: t = "", onClose: n }) => {
809
809
  break;
810
810
  }
811
811
  }
812
- n && (_(), h.current = {
812
+ if (!n) return;
813
+ _(), h.current = {
813
814
  id: t.id,
814
815
  timer: setTimeout(_, lt)
815
- }, o(t.id), n.scrollIntoView({
816
- behavior: "smooth",
817
- block: "start"
818
- }));
816
+ }, o(t.id);
817
+ let r = m.current, i = n.getBoundingClientRect().top;
818
+ if (r) {
819
+ let e = r.getBoundingClientRect().top;
820
+ r.scrollTo({
821
+ top: r.scrollTop + i - e - ct,
822
+ behavior: "smooth"
823
+ });
824
+ } else window.scrollTo({
825
+ top: window.scrollY + i - ct,
826
+ behavior: "smooth"
827
+ });
819
828
  }, [e, _]), A = C(() => nt(r), [r]), j = C(() => rt(A), [A]), M = C(() => {
820
829
  let e = /* @__PURE__ */ new Map(), t = (n, r) => {
821
830
  for (let i of n) r && e.set(i.id, r), t(i.children, i.id);
@@ -6705,7 +6714,7 @@ var Ci = y(() => Promise.resolve().then(() => $e).then((e) => ({ default: e.Imag
6705
6714
  x(() => {
6706
6715
  pe(m);
6707
6716
  }, [m]);
6708
- let [ge, _e] = T(!1), [ve, ye] = T(() => typeof window < "u" && typeof window.matchMedia == "function" ? window.matchMedia("(min-width: 80rem)").matches : !0), [be, xe] = T(() => typeof window < "u" && typeof window.matchMedia == "function" ? window.matchMedia("(min-width: 64rem)").matches : !0), Se = w(null), Ce = w(null), we = w(null), Te = w(0), Ee = w(null), De = w(null), Oe = w(null), [ke, Ae] = T(!1), [Y, je] = T(!1), [Me, Ne] = T(!1), Pe = b(() => {
6717
+ let [ge, _e] = T(!1), [ve, ye] = T(() => typeof window < "u" && typeof window.matchMedia == "function" ? window.matchMedia("(min-width: 80rem)").matches : !0), [be, xe] = T(() => typeof window < "u" && typeof window.matchMedia == "function" ? window.matchMedia("(min-width: 64rem)").matches : !0), Se = w(null), Ce = w(null), we = w(null), Te = w(0), Ee = w(null), De = w(null), Oe = w(null), [ke, Ae] = T(!1), [Y, je] = T(!1), [Me, Ne] = T(!1), Pe = w(null), Fe = b(() => {
6709
6718
  let e = Ce.current, t = we.current;
6710
6719
  e && (Y ? (document.body.style.overflow = "", Object.assign(e.style, {
6711
6720
  position: "",
@@ -6742,13 +6751,13 @@ var Ci = y(() => Promise.resolve().then(() => $e).then((e) => ({ default: e.Imag
6742
6751
  overflow: "auto",
6743
6752
  minHeight: "0"
6744
6753
  }), document.body.style.overflow = "hidden", je(!0)));
6745
- }, [Y]), Fe = b(() => {
6754
+ }, [Y]), Ie = b(() => {
6746
6755
  let e = Ce.current;
6747
- e && (document.fullscreenElement ? document.exitFullscreen() : (Y && Pe(), Te.current = window.scrollY, e.requestFullscreen()));
6748
- }, [Y, Pe]);
6756
+ e && (document.fullscreenElement ? document.exitFullscreen() : (Y && Fe(), Te.current = window.scrollY, e.requestFullscreen()));
6757
+ }, [Y, Fe]);
6749
6758
  x(() => {
6750
6759
  let e = (e) => {
6751
- e.key === "Escape" && Y && Pe();
6760
+ e.key === "Escape" && Y && Fe();
6752
6761
  }, t = () => {
6753
6762
  document.fullscreenElement ? Ne(!0) : (Ne(!1), requestAnimationFrame(() => {
6754
6763
  window.scrollTo(0, Te.current);
@@ -6757,7 +6766,7 @@ var Ci = y(() => Promise.resolve().then(() => $e).then((e) => ({ default: e.Imag
6757
6766
  return window.addEventListener("keydown", e), document.addEventListener("fullscreenchange", t), () => {
6758
6767
  window.removeEventListener("keydown", e), document.removeEventListener("fullscreenchange", t);
6759
6768
  };
6760
- }, [Y, Pe]), x(() => {
6769
+ }, [Y, Fe]), x(() => {
6761
6770
  if (!h) return;
6762
6771
  let e = (e) => {
6763
6772
  if ((e.ctrlKey || e.metaKey) && (e.key === "f" || e.key === "F")) {
@@ -6840,10 +6849,10 @@ var Ci = y(() => Promise.resolve().then(() => $e).then((e) => ({ default: e.Imag
6840
6849
  o,
6841
6850
  s
6842
6851
  ]);
6843
- let Ie = w(e);
6852
+ let Le = w(e);
6844
6853
  x(() => {
6845
- if (!X || e === Ie.current) return;
6846
- Ie.current = e;
6854
+ if (!X || e === Le.current) return;
6855
+ Le.current = e;
6847
6856
  let t = typeof e == "object" && e || xi(e) ? e : d(e);
6848
6857
  X.commands.setContent(t, { emitUpdate: !1 });
6849
6858
  }, [X, e]), x(() => {
@@ -6866,7 +6875,7 @@ var Ci = y(() => Promise.resolve().then(() => $e).then((e) => ({ default: e.Imag
6866
6875
  o,
6867
6876
  s
6868
6877
  ]);
6869
- let Le = b((e) => {
6878
+ let Re = b((e) => {
6870
6879
  let t = Oe.current?.getBoundingClientRect();
6871
6880
  q(e), Ae(!1), ce({
6872
6881
  position: "fixed",
@@ -6874,45 +6883,45 @@ var Ci = y(() => Promise.resolve().then(() => $e).then((e) => ({ default: e.Imag
6874
6883
  left: t ? Math.max(8, Math.min(t.left, window.innerWidth - 240)) : 8,
6875
6884
  zIndex: 9999
6876
6885
  });
6877
- }, []), Re = li((e) => f(e)), ze = Re.filter((e) => !e.more), Be = Re.filter((e) => e.more), Ve = ze.filter((e) => e.key !== "ai"), He = ze.find((e) => e.key === "ai"), Ue = b((e) => {
6886
+ }, []), ze = li((e) => f(e)), Be = ze.filter((e) => !e.more), Ve = ze.filter((e) => e.more), He = Be.filter((e) => e.key !== "ai"), Ue = Be.find((e) => e.key === "ai"), We = b((e) => {
6878
6887
  if (X) if (Ae(!1), e.key === "link") if (X.isActive("link")) X.chain().focus().unsetLink().run();
6879
6888
  else {
6880
6889
  let e = X.getAttributes("link").href || "";
6881
- le(e), Le("link");
6890
+ le(e), Re("link");
6882
6891
  }
6883
- else e.key === "highlight" ? K === "highlight" ? q("none") : Le("highlight") : e.command(X);
6892
+ else e.key === "highlight" ? K === "highlight" ? q("none") : Re("highlight") : e.command(X);
6884
6893
  }, [
6885
6894
  X,
6886
6895
  K,
6887
- Le
6888
- ]), We = b((e) => X ? e.key === "highlight" ? K === "highlight" : e.key === "link" ? X.isActive("link") : e.isActive(X) : !1, [X, K]), [Ge, Ke] = T(0);
6896
+ Re
6897
+ ]), Ge = b((e) => X ? e.key === "highlight" ? K === "highlight" : e.key === "link" ? X.isActive("link") : e.isActive(X) : !1, [X, K]), [Ke, qe] = T(0);
6889
6898
  x(() => {
6890
6899
  if (!X) return;
6891
- let e = () => Ke((e) => (e + 1) % 1e6);
6900
+ let e = () => qe((e) => (e + 1) % 1e6);
6892
6901
  return X.on("update", e), () => {
6893
6902
  X.off("update", e);
6894
6903
  };
6895
6904
  }, [X]);
6896
- let [qe, Je] = T(!1);
6905
+ let [Je, Ye] = T(!1);
6897
6906
  x(() => {
6898
6907
  if (!X) return;
6899
6908
  let e = () => {
6900
6909
  let e = !1;
6901
6910
  X.state.doc.descendants((t) => {
6902
6911
  t.type.name === "heading" && (e = !0);
6903
- }), Je(e);
6912
+ }), Ye(e);
6904
6913
  };
6905
6914
  return e(), X.on("update", e), () => {
6906
6915
  X.off("update", e);
6907
6916
  };
6908
6917
  }, [X]);
6909
- let Ye = C(() => X?.storage?.characterCount?.characters?.() ?? 0, [X, Ge]), Xe = a ? Ye > a : !1;
6918
+ let Xe = C(() => X?.storage?.characterCount?.characters?.() ?? 0, [X, Ke]), Ze = a ? Xe > a : !1;
6910
6919
  x(() => () => {
6911
6920
  Se.current && clearTimeout(Se.current);
6912
6921
  }, []), x(() => () => {
6913
6922
  ue && ue.resolve(null);
6914
6923
  }, []);
6915
- let Ze = b((e) => {
6924
+ let $e = b((e) => {
6916
6925
  if (!X?.isEditable) return;
6917
6926
  let t = window.getSelection(), n;
6918
6927
  if (e) {
@@ -6952,10 +6961,10 @@ var Ci = y(() => Promise.resolve().then(() => $e).then((e) => ({ default: e.Imag
6952
6961
  filename: e,
6953
6962
  resolve: t
6954
6963
  });
6955
- }, e.openAI = Ze, e.parseMd = (e, t) => X ? Si(X, t) : null, () => {
6964
+ }, e.openAI = $e, e.parseMd = (e, t) => X ? Si(X, t) : null, () => {
6956
6965
  delete e.openImageDialog, delete e.openVideoDialog, delete e.openAI, delete e.parseMd, delete e.chooseMd;
6957
6966
  };
6958
- }, [X, Ze]), S(() => {
6967
+ }, [X, $e]), S(() => {
6959
6968
  if (!j || !X) return;
6960
6969
  let e = Ee.current;
6961
6970
  if (!e) return;
@@ -6979,14 +6988,25 @@ var Ci = y(() => Promise.resolve().then(() => $e).then((e) => ({ default: e.Imag
6979
6988
  }, [j, X]), x(() => {
6980
6989
  j || (Ee.current = null);
6981
6990
  }, [j]);
6982
- let $e = b((e) => {
6991
+ let et = b((e) => {
6983
6992
  X?.chain().focus().setImage({ src: e }).run();
6984
- }, [X]), et = b((e) => {
6993
+ }, [X]), tt = b((e) => {
6985
6994
  (X?.commands).insertVideo?.({ src: e });
6986
- }, [X]), tt = fe && ve && !Y && !Me, nt = !tt && !me && (fe || qe && !(!k && be)), rt = w(!1);
6995
+ }, [X]), nt = fe && ve && !Y && !Me, rt = !nt && !me && (fe || Je && !(!k && be)), it = w(!1);
6987
6996
  return x(() => {
6988
- rt.current || (rt.current = !0, fe && !tt && he(!0));
6989
- }, [fe, tt]), X ? /* @__PURE__ */ O("div", {
6997
+ it.current || (it.current = !0, fe && !nt && he(!0));
6998
+ }, [fe, nt]), x(() => {
6999
+ if (!me) return;
7000
+ let e = (e) => {
7001
+ let t = e.target;
7002
+ Pe.current?.contains(t) || he(!1);
7003
+ }, t = (e) => {
7004
+ e.key === "Escape" && he(!1);
7005
+ };
7006
+ return document.addEventListener("mousedown", e), document.addEventListener("touchstart", e, { passive: !0 }), document.addEventListener("keydown", t), () => {
7007
+ document.removeEventListener("mousedown", e), document.removeEventListener("touchstart", e), document.removeEventListener("keydown", t);
7008
+ };
7009
+ }, [me]), X ? /* @__PURE__ */ O("div", {
6990
7010
  className: "qingwu-editor-row",
6991
7011
  children: [/* @__PURE__ */ O("div", {
6992
7012
  ref: Ce,
@@ -7043,7 +7063,7 @@ var Ci = y(() => Promise.resolve().then(() => $e).then((e) => ({ default: e.Imag
7043
7063
  !k && /* @__PURE__ */ D("button", {
7044
7064
  type: "button",
7045
7065
  className: `qed-tb-btn qed-tb-btn--ai${j ? " is-active" : ""}`,
7046
- onClick: (e) => j ? M(!1) : Ze(e.currentTarget),
7066
+ onClick: (e) => j ? M(!1) : $e(e.currentTarget),
7047
7067
  title: f("editor.toolbar.aiTitle"),
7048
7068
  "aria-label": f("editor.toolbar.ai"),
7049
7069
  "aria-pressed": j,
@@ -7092,7 +7112,7 @@ var Ci = y(() => Promise.resolve().then(() => $e).then((e) => ({ default: e.Imag
7092
7112
  /* @__PURE__ */ D("button", {
7093
7113
  type: "button",
7094
7114
  className: `qed-tb-btn${Y ? " is-active" : ""}`,
7095
- onClick: Pe,
7115
+ onClick: Fe,
7096
7116
  title: Y ? "退出网页全屏" : "网页全屏",
7097
7117
  "aria-label": Y ? "退出网页全屏" : "网页全屏",
7098
7118
  "aria-pressed": Y,
@@ -7112,7 +7132,7 @@ var Ci = y(() => Promise.resolve().then(() => $e).then((e) => ({ default: e.Imag
7112
7132
  /* @__PURE__ */ D("button", {
7113
7133
  type: "button",
7114
7134
  className: `qed-tb-btn${Me ? " is-active" : ""}`,
7115
- onClick: Fe,
7135
+ onClick: Ie,
7116
7136
  title: Me ? "退出全屏" : "全屏",
7117
7137
  "aria-label": Me ? "退出全屏" : "全屏",
7118
7138
  "aria-pressed": Me,
@@ -7148,11 +7168,11 @@ var Ci = y(() => Promise.resolve().then(() => $e).then((e) => ({ default: e.Imag
7148
7168
  e.target.closest("button") && e.preventDefault();
7149
7169
  },
7150
7170
  children: [
7151
- Ve.map((e) => /* @__PURE__ */ D("button", {
7171
+ He.map((e) => /* @__PURE__ */ D("button", {
7152
7172
  type: "button",
7153
7173
  className: `flex items-center justify-center w-7 h-7 rounded-lg transition-colors ${e.isActive(X) ? "bg-primary/10 text-primary" : "text-default-600 hover:bg-default-100"}`,
7154
7174
  onClick: (t) => {
7155
- t.preventDefault(), Ue(e);
7175
+ t.preventDefault(), We(e);
7156
7176
  },
7157
7177
  title: e.label,
7158
7178
  "aria-label": e.label,
@@ -7166,10 +7186,10 @@ var Ci = y(() => Promise.resolve().then(() => $e).then((e) => ({ default: e.Imag
7166
7186
  type: "button",
7167
7187
  className: `flex items-center justify-center w-7 h-7 rounded-lg transition-colors ${j ? "bg-primary/15 text-primary" : "text-primary hover:bg-primary/10"}`,
7168
7188
  onClick: (e) => {
7169
- e.preventDefault(), Ae(!1), He?.command(X);
7189
+ e.preventDefault(), Ae(!1), Ue?.command(X);
7170
7190
  },
7171
- title: He?.label,
7172
- "aria-label": He?.label,
7191
+ title: Ue?.label,
7192
+ "aria-label": Ue?.label,
7173
7193
  children: /* @__PURE__ */ D(zt, {})
7174
7194
  }),
7175
7195
  /* @__PURE__ */ D("span", {
@@ -7193,12 +7213,12 @@ var Ci = y(() => Promise.resolve().then(() => $e).then((e) => ({ default: e.Imag
7193
7213
  onPointerDown: (e) => {
7194
7214
  e.target.closest("button") && e.preventDefault();
7195
7215
  },
7196
- children: Be.map((e) => /* @__PURE__ */ O("button", {
7216
+ children: Ve.map((e) => /* @__PURE__ */ O("button", {
7197
7217
  type: "button",
7198
7218
  role: "menuitem",
7199
- className: `flex items-center gap-2 w-full whitespace-nowrap px-3 py-1.5 text-xs rounded-md transition-colors ${We(e) ? "bg-primary/10 text-primary" : "text-default-600 hover:bg-default-100"}`,
7219
+ className: `flex items-center gap-2 w-full whitespace-nowrap px-3 py-1.5 text-xs rounded-md transition-colors ${Ge(e) ? "bg-primary/10 text-primary" : "text-default-600 hover:bg-default-100"}`,
7200
7220
  onClick: (t) => {
7201
- t.preventDefault(), Ue(e);
7221
+ t.preventDefault(), We(e);
7202
7222
  },
7203
7223
  title: e.label,
7204
7224
  children: [/* @__PURE__ */ D("span", {
@@ -7283,7 +7303,7 @@ var Ci = y(() => Promise.resolve().then(() => $e).then((e) => ({ default: e.Imag
7283
7303
  children: /* @__PURE__ */ D(Ci, {
7284
7304
  open: B,
7285
7305
  onClose: () => V(!1),
7286
- onInsert: $e,
7306
+ onInsert: et,
7287
7307
  validate: (e) => X ? un(X.state.doc, e, {
7288
7308
  maxAttachmentSize: o,
7289
7309
  maxTotalAttachmentSize: s
@@ -7295,7 +7315,7 @@ var Ci = y(() => Promise.resolve().then(() => $e).then((e) => ({ default: e.Imag
7295
7315
  children: /* @__PURE__ */ D(Ei, {
7296
7316
  open: H,
7297
7317
  onClose: () => ae(!1),
7298
- onInsert: et
7318
+ onInsert: tt
7299
7319
  })
7300
7320
  }),
7301
7321
  oe && /* @__PURE__ */ D(v, {
@@ -7340,9 +7360,9 @@ var Ci = y(() => Promise.resolve().then(() => $e).then((e) => ({ default: e.Imag
7340
7360
  /* @__PURE__ */ D("div", {
7341
7361
  className: `${Y || Me ? "fixed" : "absolute"} bottom-2 right-4 z-10 pointer-events-none select-none`,
7342
7362
  children: /* @__PURE__ */ O("span", {
7343
- className: `text-xs ${Xe ? "bg-danger/10 text-danger font-medium px-2 py-0.5 rounded" : a && Ye > a * .9 ? "bg-warning/10 text-warning px-2 py-0.5 rounded" : "text-default-300"}`,
7363
+ className: `text-xs ${Ze ? "bg-danger/10 text-danger font-medium px-2 py-0.5 rounded" : a && Xe > a * .9 ? "bg-warning/10 text-warning px-2 py-0.5 rounded" : "text-default-300"}`,
7344
7364
  children: [
7345
- Ye,
7365
+ Xe,
7346
7366
  a ? ` / ${a}` : "",
7347
7367
  " 字"
7348
7368
  ]
@@ -7355,7 +7375,7 @@ var Ci = y(() => Promise.resolve().then(() => $e).then((e) => ({ default: e.Imag
7355
7375
  editor: X,
7356
7376
  onClose: () => _e(!1)
7357
7377
  }),
7358
- nt && /* @__PURE__ */ D("button", {
7378
+ rt && /* @__PURE__ */ D("button", {
7359
7379
  type: "button",
7360
7380
  className: "qingwu-toc-fab",
7361
7381
  onClick: () => he(!0),
@@ -7374,8 +7394,10 @@ var Ci = y(() => Promise.resolve().then(() => $e).then((e) => ({ default: e.Imag
7374
7394
  })
7375
7395
  })
7376
7396
  }),
7377
- me && /* @__PURE__ */ O("div", {
7397
+ me && ne(/* @__PURE__ */ O("div", {
7398
+ ref: Pe,
7378
7399
  className: "qingwu-toc-drawer toc-scroll",
7400
+ "data-lenis-prevent": !0,
7379
7401
  children: [/* @__PURE__ */ O("div", {
7380
7402
  className: "qed-drawer-head",
7381
7403
  children: [/* @__PURE__ */ D("span", {
@@ -7406,10 +7428,11 @@ var Ci = y(() => Promise.resolve().then(() => $e).then((e) => ({ default: e.Imag
7406
7428
  he(!1), pe(!1);
7407
7429
  }
7408
7430
  })]
7409
- })
7431
+ }), document.body)
7410
7432
  ]
7411
- }), tt && /* @__PURE__ */ D("aside", {
7433
+ }), nt && /* @__PURE__ */ D("aside", {
7412
7434
  className: "qingwu-toc-desktop toc-scroll",
7435
+ "data-lenis-prevent": !0,
7413
7436
  children: /* @__PURE__ */ D(ut, {
7414
7437
  editor: X,
7415
7438
  onClose: () => pe(!1)