| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 | import { mergeProps as _mergeProps, createVNode as _createVNode } from "vue";import { ref, defineComponent } from "vue";import { pick, extend, truthProp, preventDefault, makeStringProp, createNamespace } from "../utils/index.mjs";import { fieldSharedProps } from "../field/Field.mjs";import { useId } from "../composables/use-id.mjs";import { useExpose } from "../composables/use-expose.mjs";import { Field } from "../field/index.mjs";const [name, bem, t] = createNamespace("search");const searchProps = extend({}, fieldSharedProps, {  label: String,  shape: makeStringProp("square"),  leftIcon: makeStringProp("search"),  clearable: truthProp,  actionText: String,  background: String,  showAction: Boolean});var stdin_default = defineComponent({  name,  props: searchProps,  emits: ["blur", "focus", "clear", "search", "cancel", "click-input", "click-left-icon", "click-right-icon", "update:modelValue"],  setup(props, {    emit,    slots,    attrs  }) {    const id = useId();    const filedRef = ref();    const onCancel = () => {      if (!slots.action) {        emit("update:modelValue", "");        emit("cancel");      }    };    const onKeypress = (event) => {      const ENTER_CODE = 13;      if (event.keyCode === ENTER_CODE) {        preventDefault(event);        emit("search", props.modelValue);      }    };    const getInputId = () => props.id || `${id}-input`;    const renderLabel = () => {      if (slots.label || props.label) {        return _createVNode("label", {          "class": bem("label"),          "for": getInputId()        }, [slots.label ? slots.label() : props.label]);      }    };    const renderAction = () => {      if (props.showAction) {        const text = props.actionText || t("cancel");        return _createVNode("div", {          "class": bem("action"),          "role": "button",          "tabindex": 0,          "onClick": onCancel        }, [slots.action ? slots.action() : text]);      }    };    const blur = () => {      var _a;      return (_a = filedRef.value) == null ? void 0 : _a.blur();    };    const focus = () => {      var _a;      return (_a = filedRef.value) == null ? void 0 : _a.focus();    };    const onBlur = (event) => emit("blur", event);    const onFocus = (event) => emit("focus", event);    const onClear = (event) => emit("clear", event);    const onClickInput = (event) => emit("click-input", event);    const onClickLeftIcon = (event) => emit("click-left-icon", event);    const onClickRightIcon = (event) => emit("click-right-icon", event);    const fieldPropNames = Object.keys(fieldSharedProps);    const renderField = () => {      const fieldAttrs = extend({}, attrs, pick(props, fieldPropNames), {        id: getInputId()      });      const onInput = (value) => emit("update:modelValue", value);      return _createVNode(Field, _mergeProps({        "ref": filedRef,        "type": "search",        "class": bem("field"),        "border": false,        "onBlur": onBlur,        "onFocus": onFocus,        "onClear": onClear,        "onKeypress": onKeypress,        "onClick-input": onClickInput,        "onClick-left-icon": onClickLeftIcon,        "onClick-right-icon": onClickRightIcon,        "onUpdate:modelValue": onInput      }, fieldAttrs), pick(slots, ["left-icon", "right-icon"]));    };    useExpose({      focus,      blur    });    return () => {      var _a;      return _createVNode("div", {        "class": bem({          "show-action": props.showAction        }),        "style": {          background: props.background        }      }, [(_a = slots.left) == null ? void 0 : _a.call(slots), _createVNode("div", {        "class": bem("content", props.shape)      }, [renderLabel(), renderField()]), renderAction()]);    };  }});export {  stdin_default as default};
 |