@qingwu-ui/ai-editor 0.9.0-beta.6 → 0.9.0-beta.8
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/editor/ai/components/ai-selector.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +38 -24
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1779,19 +1779,19 @@ function en({ editor: e, onClose: t }) {
|
|
|
1779
1779
|
from: 0,
|
|
1780
1780
|
to: 0,
|
|
1781
1781
|
empty: !0
|
|
1782
|
-
}), g = w(null), _ = b(async (e) => {
|
|
1782
|
+
}), g = w(null), _ = w(null), v = w(!0), y = b(async (e) => {
|
|
1783
1783
|
if (r(e), d(null), e !== "zap") {
|
|
1784
|
-
await
|
|
1784
|
+
await C(e);
|
|
1785
1785
|
return;
|
|
1786
1786
|
}
|
|
1787
1787
|
setTimeout(() => g.current?.focus(), 100);
|
|
1788
|
-
}, [e]),
|
|
1788
|
+
}, [e]), C = b(async (t) => {
|
|
1789
1789
|
let n = e.state.selection;
|
|
1790
1790
|
h.current = {
|
|
1791
1791
|
from: n.from,
|
|
1792
1792
|
to: n.to,
|
|
1793
1793
|
empty: n.empty
|
|
1794
|
-
}, l(!0), s(""), d(null);
|
|
1794
|
+
}, l(!0), s(""), v.current = !0, d(null);
|
|
1795
1795
|
try {
|
|
1796
1796
|
let r = ft(), a = n.empty ? e.state.doc.textContent : e.state.doc.textBetween(n.from, n.to), o = [];
|
|
1797
1797
|
for await (let e of r.stream({
|
|
@@ -1804,12 +1804,25 @@ function en({ editor: e, onClose: t }) {
|
|
|
1804
1804
|
} finally {
|
|
1805
1805
|
l(!1);
|
|
1806
1806
|
}
|
|
1807
|
-
}, [e, i])
|
|
1807
|
+
}, [e, i]);
|
|
1808
|
+
x(() => {
|
|
1809
|
+
let e = _.current;
|
|
1810
|
+
if (!e) return;
|
|
1811
|
+
let t = () => {
|
|
1812
|
+
let t = e.scrollHeight - e.scrollTop - e.clientHeight < 24;
|
|
1813
|
+
v.current = t;
|
|
1814
|
+
};
|
|
1815
|
+
return e.addEventListener("scroll", t, { passive: !0 }), () => e.removeEventListener("scroll", t);
|
|
1816
|
+
}, [!!o]), S(() => {
|
|
1817
|
+
let e = _.current;
|
|
1818
|
+
!e || !v.current || (e.scrollTop = e.scrollHeight);
|
|
1819
|
+
}, [o]);
|
|
1820
|
+
let k = b((t, n, r) => {
|
|
1808
1821
|
let i = new Set(Xt(e, r.from, r.to).map((e) => e.src));
|
|
1809
1822
|
t === "replaceAll" ? Qt(e, n) : $t(e, n, "replace", h.current);
|
|
1810
1823
|
let a = Zt(e);
|
|
1811
1824
|
Wt(e, [...i].filter((e) => !a.has(e)));
|
|
1812
|
-
}, [e]),
|
|
1825
|
+
}, [e]), A = b((n) => {
|
|
1813
1826
|
if (n === "below") {
|
|
1814
1827
|
$t(e, o, "below", h.current), t();
|
|
1815
1828
|
return;
|
|
@@ -1828,13 +1841,13 @@ function en({ editor: e, onClose: t }) {
|
|
|
1828
1841
|
});
|
|
1829
1842
|
return;
|
|
1830
1843
|
}
|
|
1831
|
-
|
|
1844
|
+
k(n, o, i), t();
|
|
1832
1845
|
}, [
|
|
1833
1846
|
e,
|
|
1834
1847
|
o,
|
|
1835
|
-
|
|
1848
|
+
k,
|
|
1836
1849
|
t
|
|
1837
|
-
]),
|
|
1850
|
+
]), j = b(() => {
|
|
1838
1851
|
if (!p) return;
|
|
1839
1852
|
let { position: n } = p, r = n === "replaceAll" ? {
|
|
1840
1853
|
from: 0,
|
|
@@ -1843,17 +1856,17 @@ function en({ editor: e, onClose: t }) {
|
|
|
1843
1856
|
from: h.current.from,
|
|
1844
1857
|
to: h.current.to
|
|
1845
1858
|
};
|
|
1846
|
-
|
|
1859
|
+
k(n, o, r), m(null), t();
|
|
1847
1860
|
}, [
|
|
1848
1861
|
p,
|
|
1849
1862
|
e,
|
|
1850
1863
|
o,
|
|
1851
|
-
|
|
1864
|
+
k,
|
|
1852
1865
|
t
|
|
1853
|
-
]),
|
|
1866
|
+
]), M = b(() => {
|
|
1854
1867
|
s(""), r(null), d(null);
|
|
1855
|
-
}, []),
|
|
1856
|
-
for (let e of p?.willRemove ?? [])
|
|
1868
|
+
}, []), N = {};
|
|
1869
|
+
for (let e of p?.willRemove ?? []) N[e.type] = (N[e.type] ?? 0) + 1;
|
|
1857
1870
|
return /* @__PURE__ */ O(E, { children: [/* @__PURE__ */ O("div", {
|
|
1858
1871
|
className: "ai-selector w-full flex-1 min-h-0 flex flex-col",
|
|
1859
1872
|
children: [
|
|
@@ -1876,7 +1889,7 @@ function en({ editor: e, onClose: t }) {
|
|
|
1876
1889
|
children: Kt.map(({ mode: e, labelKey: t, descKey: r, icon: i }) => /* @__PURE__ */ O("button", {
|
|
1877
1890
|
type: "button",
|
|
1878
1891
|
className: `flex flex-col items-center gap-1 px-1 py-2 rounded-xl border transition-colors ${n === e ? "border-primary/40 bg-primary/10 text-primary" : "border-default-200 text-default-600 hover:bg-default-100 hover:text-default-900"}`,
|
|
1879
|
-
onClick: () =>
|
|
1892
|
+
onClick: () => y(e),
|
|
1880
1893
|
title: f(r),
|
|
1881
1894
|
children: [/* @__PURE__ */ D("span", {
|
|
1882
1895
|
className: "text-base leading-none",
|
|
@@ -1901,7 +1914,7 @@ function en({ editor: e, onClose: t }) {
|
|
|
1901
1914
|
value: i,
|
|
1902
1915
|
onChange: (e) => a(e.target.value),
|
|
1903
1916
|
onKeyDown: (e) => {
|
|
1904
|
-
e.key === "Enter" && i.trim() &&
|
|
1917
|
+
e.key === "Enter" && i.trim() && C("zap");
|
|
1905
1918
|
}
|
|
1906
1919
|
}), /* @__PURE__ */ O("div", {
|
|
1907
1920
|
className: "flex gap-2 mt-2",
|
|
@@ -1909,7 +1922,7 @@ function en({ editor: e, onClose: t }) {
|
|
|
1909
1922
|
type: "button",
|
|
1910
1923
|
className: "px-3 py-1.5 text-xs bg-primary text-white rounded-lg disabled:opacity-50",
|
|
1911
1924
|
disabled: !i.trim(),
|
|
1912
|
-
onClick: () =>
|
|
1925
|
+
onClick: () => C("zap"),
|
|
1913
1926
|
children: f("editor.ai.confirm")
|
|
1914
1927
|
}), /* @__PURE__ */ D("button", {
|
|
1915
1928
|
type: "button",
|
|
@@ -1929,6 +1942,7 @@ function en({ editor: e, onClose: t }) {
|
|
|
1929
1942
|
}), f("editor.ai.thinking")]
|
|
1930
1943
|
}),
|
|
1931
1944
|
o && /* @__PURE__ */ O(E, { children: [/* @__PURE__ */ O("div", {
|
|
1945
|
+
ref: _,
|
|
1932
1946
|
className: "flex-1 min-h-0 overflow-y-auto text-sm whitespace-pre-wrap text-default-700 mb-3",
|
|
1933
1947
|
children: [o, c && /* @__PURE__ */ D("span", {
|
|
1934
1948
|
className: "animate-pulse",
|
|
@@ -1940,24 +1954,24 @@ function en({ editor: e, onClose: t }) {
|
|
|
1940
1954
|
h.current.empty ? /* @__PURE__ */ D("button", {
|
|
1941
1955
|
type: "button",
|
|
1942
1956
|
className: "px-3 py-1.5 text-xs bg-primary text-white rounded-lg",
|
|
1943
|
-
onClick: () =>
|
|
1957
|
+
onClick: () => A("replaceAll"),
|
|
1944
1958
|
children: f("editor.ai.replaceAll")
|
|
1945
1959
|
}) : /* @__PURE__ */ D("button", {
|
|
1946
1960
|
type: "button",
|
|
1947
1961
|
className: "px-3 py-1.5 text-xs bg-primary text-white rounded-lg",
|
|
1948
|
-
onClick: () =>
|
|
1962
|
+
onClick: () => A("replace"),
|
|
1949
1963
|
children: f("editor.ai.replace")
|
|
1950
1964
|
}),
|
|
1951
1965
|
/* @__PURE__ */ D("button", {
|
|
1952
1966
|
type: "button",
|
|
1953
1967
|
className: "px-3 py-1.5 text-xs border border-default-200 rounded-lg hover:bg-default-100",
|
|
1954
|
-
onClick: () =>
|
|
1968
|
+
onClick: () => A("below"),
|
|
1955
1969
|
children: f("editor.ai.insert")
|
|
1956
1970
|
}),
|
|
1957
1971
|
/* @__PURE__ */ D("button", {
|
|
1958
1972
|
type: "button",
|
|
1959
1973
|
className: "px-3 py-1.5 text-xs text-danger",
|
|
1960
|
-
onClick:
|
|
1974
|
+
onClick: M,
|
|
1961
1975
|
children: f("editor.ai.discard")
|
|
1962
1976
|
})
|
|
1963
1977
|
]
|
|
@@ -2007,12 +2021,12 @@ function en({ editor: e, onClose: t }) {
|
|
|
2007
2021
|
children: [/* @__PURE__ */ D("p", {
|
|
2008
2022
|
className: "mb-2",
|
|
2009
2023
|
children: p.position === "replaceAll" ? f("editor.ai.replaceAllText") : f("editor.ai.replaceText")
|
|
2010
|
-
}), Object.keys(
|
|
2024
|
+
}), Object.keys(N).length > 0 && /* @__PURE__ */ O(E, { children: [/* @__PURE__ */ D("p", {
|
|
2011
2025
|
className: "text-xs text-default-500",
|
|
2012
2026
|
children: f("editor.ai.removeNodes")
|
|
2013
2027
|
}), /* @__PURE__ */ D("ul", {
|
|
2014
2028
|
className: "mt-1 space-y-0.5",
|
|
2015
|
-
children: Object.entries(
|
|
2029
|
+
children: Object.entries(N).map(([e, t]) => /* @__PURE__ */ O("li", {
|
|
2016
2030
|
className: "text-sm text-default-700",
|
|
2017
2031
|
children: [
|
|
2018
2032
|
f(Jt[e] ?? e),
|
|
@@ -2037,7 +2051,7 @@ function en({ editor: e, onClose: t }) {
|
|
|
2037
2051
|
}), /* @__PURE__ */ D("button", {
|
|
2038
2052
|
type: "button",
|
|
2039
2053
|
className: "qed-btn qed-btn--primary",
|
|
2040
|
-
onClick:
|
|
2054
|
+
onClick: j,
|
|
2041
2055
|
children: f("editor.ai.confirmReplace")
|
|
2042
2056
|
})]
|
|
2043
2057
|
})
|