UNPKG

@aplus-frontend/ui

Version:

138 lines (137 loc) 3.2 kB
import { isVNode as g, defineComponent as C, ref as S, useSlots as _, createVNode as i, mergeProps as V, unref as r, computed as w, createBlock as R, openBlock as T, resolveDynamicComponent as j } from "vue"; import { Input as U } from "@aplus-frontend/antdv"; import "../../hooks/index.mjs"; import { omit as z } from "lodash-unified"; import { useDefaultPlaceholder as F } from "../hooks/use-default-placeholder.mjs"; import { useControllableValue as M } from "../../hooks/useControllableValue.mjs"; function N(n) { return typeof n == "function" || Object.prototype.toString.call(n) === "[object Object]" && !g(n); } const K = /* @__PURE__ */ C({ name: "ApFieldText", __name: "index", props: { mode: { default: "edit" }, class: {}, style: {}, variant: {}, size: {}, value: {}, name: {}, type: { default: "text" }, onCompositionend: {}, onCompositionstart: {}, 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 }, 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": {}, valueModifiers: {}, status: {}, defaultValue: {}, inputElement: {}, triggerFocus: {}, handleReset: {}, addonBefore: {}, addonAfter: {}, prefix: {}, suffix: {}, clearIcon: {}, allowClear: { type: Boolean, default: !0 }, emptyText: { default: "--" }, beforeInput: {} }, emits: ["update:value"], setup(n, { expose: d, emit: c }) { const t = S(), l = _(), f = (o) => { t.value?.focus(o); }, m = () => { t.value?.blur(); }, y = (o, u, a) => { t.value?.setSelectionRange(o, u, a); }, v = () => { t.value?.select(); }, x = c, e = n, { value: p, updateValue: B } = M(e, x), b = F("Text", e); function h(o) { const u = o.target.value || "", a = e.beforeInput ? e.beforeInput?.(u) : u, s = t.value?.$el?.querySelector("input"); s && (s.value = a), B(a); } function I() { return e.mode === "edit" ? i(U, V(z(e, ["mode", "emptyText", "value", "onUpdate:value", "beforeInput"]), { placeholder: r(b), value: r(p), onInput: h, ref: t }), N(l) ? l : { default: () => [l] }) : i("span", null, [e.prefix || l?.prefix?.(), r(p) || e.emptyText, e.suffix || l?.suffix?.()]); } return d({ focus: f, blur: m, setSelectionRange: y, select: v, input: w(() => t.value?.input) }), (o, u) => (T(), R(j(I()))); } }); export { K as default };