UNPKG

tdesign-vue

Version:
323 lines (315 loc) 13.1 kB
/** * tdesign v1.11.2 * (c) 2025 tdesign * @license MIT */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var helper = require('../_chunks/dep-ece3c062.js'); var _slicedToArray = require('@babel/runtime/helpers/slicedToArray'); var _defineProperty = require('@babel/runtime/helpers/defineProperty'); var VueCompositionAPI = require('@vue/composition-api'); var checkbox_props = require('./props.js'); var checkbox_constants = require('./constants.js'); var checkbox_store = require('./store.js'); var checkbox_hooks_useKeyboardEvent = require('./hooks/useKeyboardEvent.js'); var hooks_useConfig = require('../hooks/useConfig.js'); var hooks_useVModel = require('../hooks/useVModel.js'); var hooks_useFormDisabled = require('../hooks/useFormDisabled.js'); var hooks_useElementLazyRender = require('../hooks/useElementLazyRender.js'); var utils_renderTnode = require('../utils/render-tnode.js'); require('@babel/runtime/helpers/classCallCheck'); require('@babel/runtime/helpers/createClass'); require('../_common/js/common.js'); require('../config-provider/useConfig.js'); require('../_chunks/dep-07fb8c0e.js'); require('../_common/js/global-config/default-config.js'); require('../_common/js/global-config/locale/zh_CN.js'); require('../_chunks/dep-a4a18104.js'); require('@babel/runtime/helpers/typeof'); require('../_chunks/dep-27dd8cc6.js'); require('dayjs'); require('../_chunks/dep-87c765cc.js'); require('../_chunks/dep-75cd6d52.js'); require('../_chunks/dep-b1a02818.js'); require('../_chunks/dep-3d8ab37d.js'); require('../_chunks/dep-ecccff93.js'); require('../_chunks/dep-a4308f57.js'); require('../_chunks/dep-a4cecac4.js'); require('../_chunks/dep-ab142eaf.js'); require('../_chunks/dep-6ad3de7c.js'); require('../_chunks/dep-e4278c54.js'); require('../_chunks/dep-fcf0662d.js'); require('../_chunks/dep-8b1e056e.js'); require('../_chunks/dep-5db8defc.js'); require('../_chunks/dep-6e4c473c.js'); require('../_chunks/dep-234b7c02.js'); require('../_chunks/dep-a4747856.js'); require('../_chunks/dep-932dd69e.js'); require('../_chunks/dep-9f4caea4.js'); require('../_chunks/dep-dbd838d6.js'); require('../_chunks/dep-b3120c1b.js'); require('../_chunks/dep-68ba2357.js'); require('../_chunks/dep-173eb46c.js'); require('../_chunks/dep-47bca35e.js'); require('../_chunks/dep-6478392e.js'); require('../_chunks/dep-201f7798.js'); require('../_chunks/dep-d3015b4c.js'); require('../_common/js/utils/observe.js'); require('@babel/runtime/helpers/readOnlyError'); require('vue'); require('../_chunks/dep-7c854ec6.js'); require('../_chunks/dep-eceed11d.js'); require('../_chunks/dep-f8a85d6a.js'); require('../_chunks/dep-5b117689.js'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray); var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty); function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty__default["default"](e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } var _Checkbox = VueCompositionAPI.defineComponent({ name: "TCheckbox", props: _objectSpread(_objectSpread({}, checkbox_props["default"]), {}, { stopLabelTrigger: Boolean, storeKey: String, index: Number, data: Object }), model: { prop: "checked", event: "change" }, setup: function setup(props2) { var _toRefs = VueCompositionAPI.toRefs(props2), storeKey = _toRefs.storeKey; var checkboxStore = VueCompositionAPI.computed(function () { return checkbox_store.getCheckboxStore(storeKey.value); }); var labelRef = VueCompositionAPI.ref(); var _useCommonClassName = hooks_useConfig.useCommonClassName(), STATUS = _useCommonClassName.STATUS; var checkboxGroupExist = VueCompositionAPI.ref(false); var _toRefs2 = VueCompositionAPI.toRefs(props2), checked = _toRefs2.checked, indeterminate = _toRefs2.indeterminate, disabled = _toRefs2.disabled, value = _toRefs2.value, lazyLoad = _toRefs2.lazyLoad, label = _toRefs2.label, data = _toRefs2.data; var _useVModel = hooks_useVModel.useVModel(checked, props2.defaultChecked, props2.onChange, "change", "checked"), _useVModel2 = _slicedToArray__default["default"](_useVModel, 2), innerChecked = _useVModel2[0], setInnerChecked = _useVModel2[1]; var checkboxGroupData = VueCompositionAPI.inject(checkbox_constants.CheckboxGroupInjectionKey, void 0); var tIndeterminate = VueCompositionAPI.ref(false); var tChecked = VueCompositionAPI.ref(false); var handleParentCheckedChange = function handleParentCheckedChange(_ref) { var parentIsCheckAll = _ref.parentIsCheckAll, parentChecked = _ref.parentChecked, parentIsIndeterminate = _ref.parentIsIndeterminate; var value2 = props2.value, checkAll = props2.checkAll; if (checkAll) { tChecked.value = parentIsCheckAll; tIndeterminate.value = parentIsIndeterminate; } else { tChecked.value = parentChecked.includes(value2); } checkboxGroupExist.value = checkboxStore.value.parentExist; }; VueCompositionAPI.watch([innerChecked, checkboxStore], function () { var _checkboxStore$value; if ((_checkboxStore$value = checkboxStore.value) !== null && _checkboxStore$value !== void 0 && _checkboxStore$value.parentExist) { checkboxGroupExist.value = true; } else { tChecked.value = innerChecked.value; } }, { immediate: true }); VueCompositionAPI.watch([indeterminate, checkboxStore], function (_ref2) { var _ref3 = _slicedToArray__default["default"](_ref2, 2), val = _ref3[0], checkboxStore2 = _ref3[1]; if (!(checkboxStore2 !== null && checkboxStore2 !== void 0 && checkboxStore2.parentExist)) { tIndeterminate.value = val; } }, { immediate: true }); var tName = VueCompositionAPI.ref(); var tDisabled = VueCompositionAPI.ref(); var _useFormDisabled = hooks_useFormDisabled.useFormDisabled(), formDisabled = _useFormDisabled.formDisabled; var handleParentDisabled = function handleParentDisabled(_ref4) { var parentDisabled = _ref4.parentDisabled, parentMaxExceeded = _ref4.parentMaxExceeded; var checkAll = props2.checkAll, disabled2 = props2.disabled; if (!checkAll && !tChecked.value && parentMaxExceeded) { tDisabled.value = true; return; } if (disabled2 !== void 0) { tDisabled.value = disabled2; return; } if (parentDisabled !== void 0) { tDisabled.value = parentDisabled; return; } tDisabled.value = disabled2; }; VueCompositionAPI.watch([checkboxStore], function () { var _checkboxStore$value2; if (!((_checkboxStore$value2 = checkboxStore.value) !== null && _checkboxStore$value2 !== void 0 && _checkboxStore$value2.parentExist)) { tDisabled.value = props2.disabled; } }); VueCompositionAPI.watch([disabled], function (_ref5) { var _ref6 = _slicedToArray__default["default"](_ref5, 1), val = _ref6[0]; tDisabled.value = val; }, { immediate: true }); var COMPONENT_NAME = hooks_useConfig.usePrefixClass("checkbox"); var labelClasses = VueCompositionAPI.ref([]); VueCompositionAPI.watch([tChecked, tIndeterminate], function (_ref7) { var _ref8 = _slicedToArray__default["default"](_ref7, 2), tChecked2 = _ref8[0], tIndeterminate2 = _ref8[1]; labelClasses.value = ["".concat(COMPONENT_NAME.value), _defineProperty__default["default"](_defineProperty__default["default"]({}, STATUS.value.checked, tChecked2), STATUS.value.indeterminate, tIndeterminate2)]; }, { immediate: true }); var subscribeParentData = function subscribeParentData(val) { checkboxStore.value.subscribe(val, function (data2) { if (data2.type === "checked") { handleParentCheckedChange(data2); } else if (data2.type === "checkbox") { setTimeout(function () { handleParentDisabled(data2); }, 0); if (data2.checkboxName) { tName.value = data2.checkboxName; } } }); }; VueCompositionAPI.watch([data, label, storeKey], function () { var _checkboxStore$value3; if (!storeKey.value) return; if (!tChecked.value && (_checkboxStore$value3 = checkboxStore.value) !== null && _checkboxStore$value3 !== void 0 && (_checkboxStore$value3 = _checkboxStore$value3.parentChecked) !== null && _checkboxStore$value3 !== void 0 && _checkboxStore$value3.includes(props2.value)) { tChecked.value = true; } subscribeParentData(props2.checkAll ? "CHECK_ALL" : value.value); }, { immediate: true }); VueCompositionAPI.onBeforeUnmount(function () { var _checkboxStore$value4; (_checkboxStore$value4 = checkboxStore.value) === null || _checkboxStore$value4 === void 0 || _checkboxStore$value4.unSubscribe(props2.checkAll ? "CHECK_ALL" : value.value); }); var handleChange = function handleChange(e) { if (props2.readonly) return; var checked2 = !tChecked.value; setInnerChecked(checked2, { e: e }); if (checkboxGroupData !== null && checkboxGroupData !== void 0 && checkboxGroupData.value.onCheckedChange) { checkboxGroupData.value.onCheckedChange({ checked: checked2, checkAll: props2.checkAll, e: e, option: props2 }); } }; var handleLabelClick = function handleLabelClick(e) { if (props2.stopLabelTrigger) e.preventDefault(); }; var _useElementLazyRender = hooks_useElementLazyRender.useElementLazyRender(labelRef, lazyLoad), showCheckbox = _useElementLazyRender.showElement; var _useKeyboardEvent = checkbox_hooks_useKeyboardEvent.useKeyboardEvent(handleChange), onCheckboxFocus = _useKeyboardEvent.onCheckboxFocus, onCheckboxBlur = _useKeyboardEvent.onCheckboxBlur; return { labelRef: labelRef, labelClasses: labelClasses, COMPONENT_NAME: COMPONENT_NAME, tDisabled: tDisabled, tIndeterminate: tIndeterminate, tName: tName, tChecked: tChecked, showCheckbox: showCheckbox, formDisabled: formDisabled, STATUS: STATUS, checkboxGroupExist: checkboxGroupExist, handleChange: handleChange, handleLabelClick: handleLabelClick, onCheckboxFocus: onCheckboxFocus, onCheckboxBlur: onCheckboxBlur }; }, render: function render() { var _this$tDisabled; var h = arguments[0]; var disabled = (_this$tDisabled = this.tDisabled) !== null && _this$tDisabled !== void 0 ? _this$tDisabled : this.formDisabled; var classes = this.labelClasses.concat(_defineProperty__default["default"]({}, this.STATUS.disabled, disabled)); var slotsPrams = { data: this.data, index: this.index }; return h("label", { "ref": "labelRef", "class": classes, "attrs": { "tabindex": disabled ? void 0 : "0" }, "on": { "focus": this.onCheckboxFocus, "blur": this.onCheckboxBlur } }, [!this.showCheckbox ? null : [h("input", helper.helper([{ "attrs": { "type": "checkbox", "disabled": disabled, "readonly": this.readonly, "indeterminate": this.tIndeterminate, "name": this.tName || this.name || void 0 }, "class": "".concat(this.COMPONENT_NAME, "__former"), "domProps": { "value": this.value ? this.value : void 0, "checked": this.tChecked } }, { "on": { change: this.handleChange } }, { "key": "input", "attrs": { "tabindex": "-1" } }])), h("span", { "class": "".concat(this.COMPONENT_NAME, "__input"), "key": "input-span" }), h("span", { "class": "".concat(this.COMPONENT_NAME, "__label"), "key": "label", "on": { "click": this.handleLabelClick } }, [utils_renderTnode.renderTNodeJSX(this, "default", { params: slotsPrams }) || utils_renderTnode.renderTNodeJSX(this, "label", { params: slotsPrams, slotFirst: this.checkboxGroupExist })])]]); } }); exports["default"] = _Checkbox; //# sourceMappingURL=checkbox.js.map