@vuux/editor
Version:
Vue Nuxt 富文本编辑器
43 lines (42 loc) • 1.19 kB
JavaScript
import { computed as X, ref as u, onBeforeUnmount as x } from "vue";
const k = (o, l, i) => {
const f = X(() => ({
"--editor-theme": o.theme?.color,
"--editor-text-color": o.theme?.textColor,
"--editor-background-color": o.theme?.backgroundColor,
height: o.height
})), a = u(!1), r = u(50), d = u(50);
let s = !1, m = 0, h = 50;
const v = (e) => {
if (!s || !l.value)
return;
const n = l.value.clientWidth, W = e.clientX - m;
let t = (h / 100 * n + W) / n * 100;
t < 10 && (t = 10), t > 90 && (t = 90), r.value = t, d.value = 100 - t;
}, c = () => {
s = !1, document.removeEventListener("mousemove", v), document.removeEventListener("mouseup", c);
}, g = (e) => {
e.preventDefault(), s = !0, m = e.clientX, h = r.value, document.addEventListener("mousemove", v), document.addEventListener("mouseup", c);
}, L = (e, n) => {
i("success", e, n);
}, D = () => {
i("error");
}, E = (e) => {
a.value = e;
};
return x(() => {
c();
}), {
styles: f,
isFull: a,
leftWidth: r,
rightWidth: d,
startDrag: g,
onSuccess: L,
onError: D,
onFull: E
};
};
export {
k as useMethod
};