InputSubForm--Jgj06qz.js 7.4 KB

1
  1. import{s as _,b7 as w,a3 as y,y as s,ap as R,a_ as z,ay as U,aC as A,f as r,L as S,ag as H,bs as j,z as L,P as q,Q as E,a1 as Q}from"./index-DT8qTvyx.js";var F,T=function(h){return h&&(F=F||document.createElement("div"),F.innerHTML=h,F.innerText)},W=function(h){_(i,h);function i(a){var e=h.call(this,a)||this;return e.state={},e.id=w(),e.addItem=e.addItem.bind(e),e.removeItem=e.removeItem.bind(e),e.editSingle=e.editSingle.bind(e),e.open=e.open.bind(e),e.close=e.close.bind(e),e.dragTipRef=e.dragTipRef.bind(e),e.handleDialogConfirm=e.handleDialogConfirm.bind(e),e}return i.prototype.addItem=function(){this.setState({dialogData:y(this.props.data,this.props.scaffold||{}),dialogCtx:{mode:"add"}})},i.prototype.removeItem=function(a){a.stopPropagation(),a.preventDefault();var e=parseInt(a.currentTarget.getAttribute("data-index"),10),o=this.props.value;Array.isArray(o)&&(o=o.concat(),o.splice(e,1),this.props.onChange(o))},i.prototype.editSingle=function(){var a=this.props.value;a?this.setState({dialogData:y(this.props.data,this.props.value),dialogCtx:{mode:"edit"}}):this.addItem()},i.prototype.open=function(a){var e=parseInt(a.currentTarget.getAttribute("data-index"),10),o=this.props.value;!Array.isArray(o)||!o[e]||(this.tempValue=o[e],this.setState({dialogData:y(this.props.data,o[e]),dialogCtx:{mode:"edit",index:e}}))},i.prototype.close=function(){this.setState({dialogData:void 0,dialogCtx:void 0})},i.prototype.handleDialogConfirm=function(a){var e=this.props,o=e.multiple,p=e.onChange,l=e.value,t=this.state.dialogCtx;if(o){var n=Array.isArray(l)?l.concat():[];(t==null?void 0:t.mode)==="add"?n.push(s({},a[0])):n[t.index]=s(s({},n[t.index]),a[0]),p(n)}else p(s(s({},l),a[0]));this.close()},i.prototype.handlePopupConfirm=function(){var a=this.tempValue,e=this.props,o=e.multiple,p=e.onChange,l=e.value,t=this.state.dialogCtx;if(o){var n=Array.isArray(l)?l.concat():[];(t==null?void 0:t.mode)==="add"?n.push(s({},a)):n[t.index]=s(s({},n[t.index]),a),p(n)}else p(s(s({},l),a));this.close()},i.prototype.dragTipRef=function(a){!this.dragTip&&a?this.initDragging():this.dragTip&&!a&&this.destroyDragging(),this.dragTip=a},i.prototype.initDragging=function(){var a=this,e=this.props.classPrefix,o=this.props.submitOnChange,p=R.findDOMNode(this);this.sortable=new z(p.querySelector(".".concat(e,"SubForm-values")),{group:"SubForm-".concat(this.id),animation:150,handle:".".concat(e,"SubForm-valueDragBar"),ghostClass:"".concat(e,"SubForm-value--dragging"),onEnd:function(l){if(l.newIndex!==l.oldIndex){var t=l.to;l.oldIndex<t.childNodes.length-1?t.insertBefore(l.item,t.childNodes[l.oldIndex>l.newIndex?l.oldIndex+1:l.oldIndex]):t.appendChild(l.item);var n=a.props.value;if(Array.isArray(n)){var m=n.concat();m.splice(l.newIndex,0,m.splice(l.oldIndex,1)[0]),a.props.onChange(m,o,!0)}}}})},i.prototype.destroyDragging=function(){this.sortable&&this.sortable.destroy()},i.prototype.buildDialogSchema=function(){var a=this.props.form,e=["title","actions","name","size","closeOnEsc","closeOnOutside","showErrorMsg","showCloseButton","bodyClassName","type"];return s(s({},U(a,e)),{type:"dialog",body:s(s({type:"form",canAccessSuperData:!1},A(a,e)),{inheritData:!1})})},i.prototype.buildFormSchema=function(){var a=this.props.form,e=["title","actions","name","size","closeOnEsc","closeOnOutside","showErrorMsg","showCloseButton","bodyClassName","type"];return s(s({type:"form",canAccessSuperData:!1},A(a,e)),{inheritData:!1})},i.prototype.renderMultipe=function(){var a=this,e=this.props,o=e.addButtonClassName,p=e.itemClassName,l=e.itemsClassName,t=e.disabled,n=e.maxLength,m=e.labelField,b=e.defaultLabel,d=e.value,g=e.btnLabel,v=e.render,C=e.data,u=e.translate,c=e.classnames,B=e.placeholder,I=e.draggable,P=e.draggableTip,O=e.addable,M=e.removable,D=e.minLength,k=e.addButtonText,f=e.testIdBuilder;return r.createElement(r.Fragment,null,Array.isArray(d)&&d.length?r.createElement("div",{className:c("SubForm-values",l),key:"values"},d.map(function(x,N){return r.createElement("div",s({className:c("SubForm-value",{"is-disabled":t},p),key:N},f==null?void 0:f.getChild("item-".concat(N)).getTestId()),I&&d.length>1?r.createElement("a",{className:c("SubForm-valueDragBar")},r.createElement(S,{icon:"drag-bar",className:c("icon")})):null,r.createElement("span",{className:c("SubForm-valueLabel")},g&&v("label",{type:"tpl",tpl:u(g)},{data:y(C,x)}),!g&&(x&&m&&x[m]&&T(x[m])||u(b))),r.createElement("a",{"data-index":N,onClick:a.open,className:c("SubForm-valueEdit")},r.createElement(S,{icon:"pencil",className:"icon"})),!t&&M!==!1&&(!D||d.length>D)?r.createElement("a",{"data-index":N,className:c("SubForm-valueDel"),onClick:a.removeItem},r.createElement(S,{icon:"close",className:"icon"})):null)})):r.createElement("div",{className:c("SubForm-placeholder"),key:"placeholder"},u(B||"placeholder.empty")),r.createElement("div",{key:"toolbar",className:c("SubForm-toolbar")},O!==!1?r.createElement("button",s({type:"button",onClick:this.addItem,className:c("Button SubForm-addBtn",o),disabled:t||!!(n&&Array.isArray(d)&&d.length>=n)},f==null?void 0:f.getChild("add-button").getTestId()),r.createElement(S,{icon:"plus",className:"icon"}),r.createElement("span",null,u(k||"SubForm.add"))):null,I&&Array.isArray(d)&&d.length>1?r.createElement("span",{className:c("Combo-dragableTip"),ref:this.dragTipRef},Array.isArray(d)&&d.length>1?u(P):""):null))},i.prototype.renderSingle=function(){var a=this.props,e=a.classnames,o=a.itemsClassName,p=a.itemClassName,l=a.disabled,t=a.value,n=a.labelField,m=a.defaultLabel,b=a.btnLabel,d=a.render,g=a.data,v=a.translate,C=a.testIdBuilder,u=C==null?void 0:C.getChild("edit-single");return r.createElement("div",{className:e("SubForm-values",o),key:"values"},r.createElement("div",s({className:e("SubForm-value",{"is-disabled":l},p),onClick:this.editSingle,"data-tooltip":v("SubForm.editDetail"),"data-position":"bottom"},u==null?void 0:u.getTestId()),r.createElement("span",{className:e("SubForm-valueLabel")},b&&d("label",{type:"tpl",tpl:v(b)},{data:y(g,t)}),!b&&(t&&n&&t[n]&&T(t[n])||v(m))),r.createElement("a",s({className:e("SubForm-valueEdit")},u==null?void 0:u.getChild("icon").getTestId()),r.createElement(S,{icon:"pencil",className:"icon"}))))},i.prototype.render=function(){var a=this,e=this.props,o=e.multiple,p=e.classPrefix,l=e.className;e.style;var t=e.render,n=e.mobileUI,m=e.env,b=e.popOverContainer,d=this.state.dialogData,g=this.state.dialogCtx;return r.createElement("div",{className:H("".concat(p,"SubFormControl"),l)},o?this.renderMultipe():this.renderSingle(),n?r.createElement(j,{isShow:!!g,showConfirm:!0,onConfirm:this.handlePopupConfirm,onHide:this.close,container:n?m==null?void 0:m.getModalContainer:b||m.getModalContainer},r.createElement("div",{className:"flex-1 pl-10 pr-10"},t("form",this.buildFormSchema(),{data:d,formStore:void 0,wrapWithPanel:!1,onChange:function(v){a.tempValue=v}}))):t("modal",this.buildDialogSchema(),{show:!!g,onClose:this.close,onConfirm:this.handleDialogConfirm,data:d,formStore:void 0}))},i.defaultProps={minLength:0,maxLength:0,multiple:!1,btnClassName:"",addButtonClassName:"",itemClassName:"",labelField:"label",defaultLabel:"SubForm.button",placeholder:"placeholder.empty"},i.propsList=["form","formStore"],L([q,E("design:type",Function),E("design:paramtypes",[]),E("design:returntype",void 0)],i.prototype,"handlePopupConfirm",null),i}(r.PureComponent),G=function(h){_(i,h);function i(){return h!==null&&h.apply(this,arguments)||this}return i=L([Q({type:"input-sub-form",sizeMutable:!1,strictMode:!1})],i),i}(W);export{G as SubFormControlRenderer,W as default};