@aplus-frontend/ui
Version:
115 lines (114 loc) • 3.62 kB
JavaScript
import { defineComponent as A, shallowRef as k, computed as c, createElementBlock as s, createBlock as z, openBlock as n, Fragment as T, normalizeClass as m, unref as e, toDisplayString as f, createElementVNode as w, mergeProps as R } from "vue";
import { Input as F } from "@aplus-frontend/antdv";
import { isNil as S, omit as V } from "lodash-unified";
import "../../config-provider/index.mjs";
import "../../hooks/index.mjs";
import { useDefaultPlaceholder as E } from "../hooks/use-default-placeholder.mjs";
import U from "../style/index.mjs";
import { languageFormat as _ } from "./utils.mjs";
import { useControllableValue as j } from "../../hooks/useControllableValue.mjs";
import { useNamespace as M } from "../../config-provider/hooks/use-namespace.mjs";
const L = /* @__PURE__ */ A({
name: "ApFieldTextArea",
__name: "index",
props: {
mode: { default: "edit" },
class: {},
style: {},
rows: {},
autoSize: { type: [Boolean, Object] },
onResize: {},
onCompositionstart: {},
onCompositionend: {},
valueModifiers: {},
size: {},
value: {},
name: {},
type: { default: "text" },
onFocus: {},
onBlur: {},
onChange: {},
onInput: {},
onKeydown: {},
onKeyup: {},
onMousedown: {},
focused: { type: Boolean },
hidden: { type: Boolean },
disabled: { type: Boolean, default: void 0 },
prefixCls: {},
id: {},
readonly: { type: Boolean },
autofocus: { type: Boolean },
variant: {},
autocomplete: {},
placeholder: {},
lazy: { type: Boolean, default: !0 },
maxlength: {},
loading: { type: Boolean },
bordered: { type: Boolean, default: !0 },
showCount: { type: [Boolean, Object] },
htmlSize: {},
onPressEnter: {},
onMouseUp: {},
onRawInput: {},
"onUpdate:value": {},
status: {},
defaultValue: {},
inputElement: {},
triggerFocus: {},
handleReset: {},
clearIcon: {},
allowClear: { type: Boolean, default: !0 },
emptyText: { default: "--" },
beforeInput: {},
code: { type: [Boolean, Object], default: !1 }
},
emits: ["update:value"],
setup(y, { expose: g, emit: v }) {
const a = k(), o = y, x = v, { value: l, updateValue: h } = j(o, x), { b: B, m: p } = M("field-textarea"), r = U("field"), b = E("TextArea", o), I = c(() => {
if (o.code)
return o.code === !0 ? {
language: "text"
} : {
language: o.code?.language ?? "text"
};
});
function C(t) {
const u = t.target.value || "", d = o.beforeInput ? o.beforeInput?.(u) : u, i = a.value?.$el?.querySelector("textarea");
i && (i.value = d), h(d);
}
return g({
focus: (t) => {
a.value?.focus(t);
},
blur: () => {
a.value?.blur();
},
resizableTextArea: c(() => a.value?.resizableTextArea)
}), (t, u) => t.mode === "read" ? (n(), s(T, { key: 0 }, [
t.code ? (n(), s("pre", {
key: 1,
class: m([e(p)("code"), e(r)])
}, [
w("code", null, f(e(_)(e(l), I.value.language)), 1)
], 2)) : (n(), s("span", {
key: 0,
class: m([e(p)("read"), e(r)])
}, f(e(S)(e(l)) || e(l) === "" ? t.emptyText : e(l)), 3))
], 64)) : (n(), z(e(F).TextArea, R(
{ key: 1 },
e(V)(o, ["onUpdate:value", "value", "beforeInput", "emptyText"]),
{
ref_key: "textAreaRef",
ref: a,
placeholder: e(b),
value: e(l),
class: [e(B)(), e(r)],
onInput: C
}
), null, 16, ["placeholder", "value", "class"]));
}
});
export {
L as default
};