UNPKG

tdesign-vue

Version:
80 lines (74 loc) 3.49 kB
/** * tdesign v1.11.2 * (c) 2025 tdesign * @license MIT */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var VueCompositionAPI = require('@vue/composition-api'); var kebabCase = require('../_chunks/dep-47bca35e.js'); require('../_chunks/dep-6478392e.js'); require('../_chunks/dep-201f7798.js'); require('../_chunks/dep-a4308f57.js'); require('@babel/runtime/helpers/typeof'); require('../_chunks/dep-fcf0662d.js'); require('../_chunks/dep-d3015b4c.js'); require('../_chunks/dep-e4278c54.js'); function useVModel(value, defaultValue, onChange) { var eventName = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "change"; var propName = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : "value"; var alias = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : []; var _getCurrentInstance = VueCompositionAPI.getCurrentInstance(), emit = _getCurrentInstance.emit, vnode = _getCurrentInstance.vnode; var internalValue = VueCompositionAPI.ref(); internalValue.value = defaultValue; var isControlled = Object.prototype.hasOwnProperty.call(vnode.componentOptions.propsData, propName) || Object.prototype.hasOwnProperty.call(vnode.componentOptions.propsData, kebabCase.kebabCase(propName)); if (isControlled) { return [value, function (newValue) { for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { args[_key - 1] = arguments[_key]; } emit === null || emit === void 0 || emit.apply(void 0, ["input", newValue].concat(args)); onChange === null || onChange === void 0 || onChange.apply(void 0, [newValue].concat(args)); if (eventName && eventName !== "input") { emit === null || emit === void 0 || emit.apply(void 0, [eventName, newValue].concat(args)); } }]; } var _loop = function _loop() { var item = alias[i]; if (Object.prototype.hasOwnProperty.call(vnode.componentOptions.propsData, item.propName)) { return { v: [item.value, function (newValue) { for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { args[_key3 - 1] = arguments[_key3]; } emit === null || emit === void 0 || emit.apply(void 0, ["update:".concat(item.propName), newValue].concat(args)); onChange === null || onChange === void 0 || onChange.apply(void 0, [newValue].concat(args)); if (item.eventName && item.eventName !== "input") { emit === null || emit === void 0 || emit.apply(void 0, [item.eventName, newValue].concat(args)); } }] }; } }, _ret; for (var i = 0, len = alias.length; i < len; i++) { _ret = _loop(); if (_ret) return _ret.v; } return [internalValue, function (newValue) { internalValue.value = newValue; for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { args[_key2 - 1] = arguments[_key2]; } onChange === null || onChange === void 0 || onChange.apply(void 0, [newValue].concat(args)); if (eventName && eventName !== "input") { emit === null || emit === void 0 || emit.apply(void 0, [eventName, newValue].concat(args)); } }]; } exports["default"] = useVModel; exports.useVModel = useVModel; //# sourceMappingURL=useVModel.js.map