jiku-ui
Version:
A Component Library for Vue.js.
2 lines (1 loc) • 9 kB
JavaScript
module.exports=function(t){var e={};function i(r){if(e[r])return e[r].exports;var n=e[r]={i:r,l:!1,exports:{}};return t[r].call(n.exports,n,n.exports,i),n.l=!0,n.exports}return i.m=t,i.c=e,i.d=function(t,e,r){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(i.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)i.d(r,n,function(e){return t[e]}.bind(null,n));return r},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=85)}({0:function(t,e,i){"use strict";function r(t,e,i,r,n,a,o,s){var l,u="function"==typeof t?t.options:t;if(e&&(u.render=e,u.staticRenderFns=i,u._compiled=!0),r&&(u.functional=!0),a&&(u._scopeId="data-v-"+a),o?(l=function(t){(t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),n&&n.call(this,t),t&&t._registeredComponents&&t._registeredComponents.add(o)},u._ssrRegister=l):n&&(l=s?function(){n.call(this,(u.functional?this.parent:this).$root.$options.shadowRoot)}:n),l)if(u.functional){u._injectStyles=l;var d=u.render;u.render=function(t,e){return l.call(e),d(t,e)}}else{var h=u.beforeCreate;u.beforeCreate=h?[].concat(h,l):[l]}return{exports:t,options:u}}i.d(e,"a",(function(){return r}))},3:function(t,e){t.exports=require("jiku-ui/lib/utils/util")},4:function(t,e){t.exports=require("jiku-ui/lib/mixins/emitter")},53:function(t,e){t.exports=require("async-validator")},85:function(t,e,i){"use strict";i.r(e);var r=function(){var t=this,e=t.$createElement,i=t._self._c||e;return i("div",{staticClass:"hn-form-item",class:[{"hn-form-item--feedback":t.hnForm&&t.hnForm.statusIcon,"is-error":"error"===t.validateState,"is-validating":"validating"===t.validateState,"is-success":"success"===t.validateState,"is-required":t.isRequired||t.required,"is-no-asterisk":t.hnForm&&t.hnForm.hideRequiredAsterisk},t.sizeClass?"hn-form-item--"+t.sizeClass:""]},[i("label-wrap",{attrs:{"is-auto-width":t.labelStyle&&"auto"===t.labelStyle.width,"update-all":"auto"===t.form.labelWidth}},[t.label||t.$slots.label?i("label",{staticClass:"hn-form-item__label",style:t.labelStyle,attrs:{for:t.labelFor}},[t._t("label",[t._v(t._s(t.label+t.form.labelSuffix))])],2):t._e()]),i("div",{staticClass:"hn-form-item__content",style:t.contentStyle},[t._t("default"),i("transition",{attrs:{name:"hn-zoom-in-top"}},["error"===t.validateState&&t.showMessage&&t.form.showMessage?t._t("error",[i("div",{staticClass:"hn-form-item__error",class:{"hn-form-item__error--inline":"boolean"==typeof t.inlineMessage?t.inlineMessage:t.hnForm&&t.hnForm.inlineMessage||!1}},[t._v("\n "+t._s(t.validateMessage)+"\n ")])],{error:t.validateMessage}):t._e()],2)],2)],1)};r._withStripped=!0;var n=i(53),a=i.n(n),o=i(4),s=i.n(o),l=i(9),u=i.n(l),d=i(3),h={props:{isAutoWidth:Boolean,updateAll:Boolean},inject:["hnForm","hnFormItem"],render:function(){var t=arguments[0],e=this.$slots.default;if(!e)return null;if(this.isAutoWidth){var i=this.hnForm.autoLabelWidth,r={};if(i&&"auto"!==i){var n=parseInt(i,10)-this.computedWidth;n&&(r.marginLeft=n+"px")}return t("div",{class:"hn-form-item__label-wrap",style:r},[e])}return e[0]},methods:{getLabelWidth:function(){if(this.$el&&this.$el.firstElementChild){var t=window.getComputedStyle(this.$el.firstElementChild).width;return Math.ceil(parseFloat(t))}return 0},updateLabelWidth:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"update";this.$slots.default&&this.isAutoWidth&&this.$el.firstElementChild&&("update"===t?this.computedWidth=this.getLabelWidth():"remove"===t&&this.hnForm.deregisterLabelWidth(this.computedWidth))}},watch:{computedWidth:function(t,e){this.updateAll&&(this.hnForm.registerLabelWidth(t,e),this.hnFormItem.updateComputedLabelWidth(t))}},data:function(){return{computedWidth:0}},mounted:function(){this.updateLabelWidth("update")},updated:function(){this.updateLabelWidth("update")},beforeDestroy:function(){this.updateLabelWidth("remove")}},f=i(0),c=Object(f.a)(h,void 0,void 0,!1,null,null,null);c.options.__file="packages/form/src/label-wrap.vue";var m=c.exports,p={name:"HnFormItem",componentName:"HnFormItem",mixins:[s.a],provide:function(){return{hnFormItem:this}},inject:["hnForm"],props:{label:String,labelWidth:String,prop:String,required:{type:Boolean,default:void 0},rules:[Object,Array],error:String,validateStatus:String,for:String,inlineMessage:{type:[String,Boolean],default:""},showMessage:{type:Boolean,default:!0},size:String},components:{LabelWrap:m},watch:{error:{immediate:!0,handler:function(t){this.validateMessage=t,this.validateState=t?"error":""}},validateStatus:function(t){this.validateState=t}},computed:{labelFor:function(){return this.for||this.prop},labelStyle:function(){var t={};if("top"===this.form.labelPosition)return t;var e=this.labelWidth||this.form.labelWidth;return e&&(t.width=e),t},contentStyle:function(){var t={},e=this.label;if("top"===this.form.labelPosition||this.form.inline)return t;if(!e&&!this.labelWidth&&this.isNested)return t;var i=this.labelWidth||this.form.labelWidth;return"auto"===i?"auto"===this.labelWidth?t.marginLeft=this.computedLabelWidth:"auto"===this.form.labelWidth&&(t.marginLeft=this.hnForm.autoLabelWidth):t.marginLeft=i,t},form:function(){for(var t=this.$parent,e=t.$options.componentName;"HnForm"!==e;)"HnFormItem"===e&&(this.isNested=!0),e=(t=t.$parent).$options.componentName;return t},fieldValue:function(){var t=this.form.model;if(t&&this.prop){var e=this.prop;return-1!==e.indexOf(":")&&(e=e.replace(/:/,".")),Object(d.getPropByPath)(t,e,!0).v}},isRequired:function(){var t=this.getRules(),e=!1;return t&&t.length&&t.every((function(t){return!t.required||(e=!0,!1)})),e},_formSize:function(){return this.hnForm.size},hnFormItemSize:function(){return this.size||this._formSize},sizeClass:function(){return this.hnFormItemSize||(this.$HEINER||{}).size}},data:function(){return{validateState:"",validateMessage:"",validateDisabled:!1,validator:{},isNested:!1,computedLabelWidth:""}},methods:{validate:function(t){var e=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:d.noop;this.validateDisabled=!1;var r=this.getFilteredRule(t);if((!r||0===r.length)&&void 0===this.required)return i(),!0;this.validateState="validating";var n={};r&&r.length>0&&r.forEach((function(t){delete t.trigger})),n[this.prop]=r;var o=new a.a(n),s={};s[this.prop]=this.fieldValue,o.validate(s,{firstFields:!0},(function(t,r){e.validateState=t?"error":"success",e.validateMessage=t?t[0].message:"",i(e.validateMessage,r),e.hnForm&&e.hnForm.$emit("validate",e.prop,!t,e.validateMessage||null)}))},clearValidate:function(){this.validateState="",this.validateMessage="",this.validateDisabled=!1},resetField:function(){var t=this;this.validateState="",this.validateMessage="";var e=this.form.model,i=this.fieldValue,r=this.prop;-1!==r.indexOf(":")&&(r=r.replace(/:/,"."));var n=Object(d.getPropByPath)(e,r,!0);this.validateDisabled=!0,Array.isArray(i)?n.o[n.k]=[].concat(this.initialValue):n.o[n.k]=this.initialValue,this.$nextTick((function(){t.validateDisabled=!1})),this.broadcast("HnTimeSelect","fieldReset",this.initialValue)},getRules:function(){var t=this.form.rules,e=this.rules,i=void 0!==this.required?{required:!!this.required}:[],r=Object(d.getPropByPath)(t,this.prop||"");return t=t?r.o[this.prop||""]||r.v:[],[].concat(e||t||[]).concat(i)},getFilteredRule:function(t){return this.getRules().filter((function(e){return!e.trigger||""===t||(Array.isArray(e.trigger)?e.trigger.indexOf(t)>-1:e.trigger===t)})).map((function(t){return u()({},t)}))},onFieldBlur:function(){this.validate("blur")},onFieldChange:function(){this.validateDisabled?this.validateDisabled=!1:this.validate("change")},updateComputedLabelWidth:function(t){this.computedLabelWidth=t?t+"px":""},addValidateEvents:function(){(this.getRules().length||void 0!==this.required)&&(this.$on("hn.form.blur",this.onFieldBlur),this.$on("hn.form.change",this.onFieldChange))},removeValidateEvents:function(){this.$off()}},mounted:function(){if(this.prop){this.dispatch("HnForm","hn.form.addField",[this]);var t=this.fieldValue;Array.isArray(t)&&(t=[].concat(t)),Object.defineProperty(this,"initialValue",{value:t}),this.addValidateEvents()}},beforeDestroy:function(){this.dispatch("HnForm","hn.form.removeField",[this])}},v=Object(f.a)(p,r,[],!1,null,null,null);v.options.__file="packages/form/src/form-item.vue";var b=v.exports;b.install=function(t){t.component(b.name,b)};e.default=b},9:function(t,e){t.exports=require("jiku-ui/lib/utils/merge")}}).default;