dynamicformdjx-react 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +75 -73
- package/dist/utils/tools.d.ts +2 -1
- package/package.json +1 -2
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('./index.css');const e=require("react/jsx-runtime"),R=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('./index.css');const e=require("react/jsx-runtime"),R=require("react"),P=(o,y,c)=>Object.keys(o).map((r,l)=>{const u=o[r],v=Array.isArray(u),F=v?u.every(L=>typeof L=="number"):typeof u=="number";return{rId:y(l),key:r,value:v?u.join(c):u,isArray:v||void 0,isNumber:F||void 0}}),_=(o,y)=>o.reduce((c,r)=>(r.key.trim()&&(c[r.key]=K(r.value,r.isArray,r.isNumber,y)),c),{}),K=(o,y,c,r=",")=>{let l;return y?c?l=String(o).split(r).map(Number).filter(u=>!Number.isNaN(u)):l=String(o).split(r):c?l=parseFloat(o):l=o.toString(),l},W=(o,y,c=",")=>{const r=l=>{l=l.replace(/[^\d.-]/g,"");let u=!1;l.startsWith("-")&&(u=!0),l=l.replace(/-/g,"");const v=l.indexOf(".");return v!==-1&&(l=l.slice(0,v+1)+l.slice(v+1).replace(/\./g,"")),(u?"-":"")+l};return y?o.split(c).map(l=>r(l)).join(c):r(o)},J=o=>`hsl(${o*35%360}, 60%, 65%)`,Q=(o,y)=>o[y-1]??J(y);function T(o,y,c){if(y.length===0)return c(o,-1);const[r,...l]=y,u=[...o];if(l.length===0)return c(u,r);const v=u[r];if(!Array.isArray(v.value))return u;const F=T(v.value,l,c);return F.length===0?u[r]={...v,value:"",isArray:void 0,isNumber:void 0}:u[r]={...v,value:F},u}function p(o){return o.filter(Boolean).join(" ")}const U=R.forwardRef((o,y)=>{const{value:c,size:r,dyCls:l,isController:u,configs:v,btnConfigs:F,dyListConfigs:L,randomFun:k=n=>`${Date.now()}_${n??0}`,onReset:B,onMerge:q,onChange:V}=o,M={resetTxt:"重置",newTxt:"添加项",mergeTxt:"合并",...F},$={hideReset:!1,maxHeight:"300px",autoScroll:!0,allowFilter:!0,...v},h={arraySplitSymbol:",",...L},[g,j]=R.useState(()=>P(c,k,h.arraySplitSymbol)),S=R.useRef(null);return R.useImperativeHandle(y,()=>({getResult(n){return n==="ori"?g:_(g,h.arraySplitSymbol)},onSet(n){j(P(n??c,k,h.arraySplitSymbol))}})),R.useEffect(()=>{u&&V(_(g,h.arraySplitSymbol))},[g]),e.jsxs("div",{className:l??`dynamicInput ${r}`,children:[e.jsx("div",{className:"dyFormList",ref:S,style:{maxHeight:$.maxHeight},children:g.map((n,d,O)=>e.jsxs("div",{className:"dItem",children:[e.jsxs("div",{className:"input",children:[e.jsx("input",{value:n.key,className:"key nativeInput",onInput:m=>{const t=m.target.value;j(a=>{const x=[...a],s=x[d];return x[d]={...s,key:t},x})}}),":",e.jsxs("div",{className:"vInput",children:[e.jsxs("div",{className:"slot",children:[e.jsx("button",{className:p([n.isArray?"success":"default","small","bt"]),onClick:()=>{j(m=>{const t=[...m],a=t[d];return t[d]={...a,isArray:!a.isArray},t})},children:"Array"})," ",e.jsx("button",{className:p([n.isNumber?"success":"default","small","bt"]),onClick:()=>{j(m=>{const t=[...m],a=t[d];return t[d]={...a,isNumber:!a.isNumber},t})},children:"Number"})]}),e.jsx("input",{value:n.value,className:"value nativeV",onInput:m=>{const t=m.target.value;let a=t;n.isNumber&&$.allowFilter&&(a=W(t,n.isArray,h.arraySplitSymbol)),j(x=>{const s=[...x],H=s[d];return s[d]={...H,value:a},s})}})]})]}),e.jsxs("div",{className:"btn",children:[e.jsx("button",{className:p([r,"success","bt"]),disabled:d!==O.length-1,onClick:()=>{j(m=>[...m,{rId:k(),key:"",value:""}]),$.autoScroll&&setTimeout(()=>{const m=S.current;m?.scrollTo({top:m?.scrollHeight+20,behavior:"smooth"})})},children:"+"}),e.jsx("button",{className:p(["danger",r,"bt"]),onClick:()=>{j(m=>m.filter(t=>t.rId!==n.rId))},children:"-"})]})]},n.rId))}),e.jsxs("div",{className:"control",children:[!g.length&&e.jsx("button",{className:p(["success",r,"bt"]),onClick:()=>{j(n=>[...n,{rId:k(),key:"",value:""}])},children:M.newTxt}),!u&&e.jsxs(e.Fragment,{children:[!$.hideReset&&e.jsx("button",{className:p(["default",r,"bt"]),onClick:()=>{j(P(c,k,h.arraySplitSymbol)),B?.()},children:M.resetTxt}),e.jsx("button",{className:p(["info",r,"bt"]),onClick:()=>{[...g].sort((O,m)=>+O.rId-+m.rId);const d=_(g,h.arraySplitSymbol);V(d),q?.(d,g),j(P(d,k,h.arraySplitSymbol))},children:M.mergeTxt})]})]})]})}),X=R.forwardRef((o,y)=>{const{depth:c=5,value:r,isController:l,dyCls:u,configs:v,btnConfigs:F,dyListConfigs:L,randomFun:k=t=>`${Date.now()}_${t??0}`,newChildTxt:B=t=>`添加 '${t.key}' 子项`,onReset:q,onMerge:V,onChange:M}=o,$={resetTxt:"重置",newTxt:"添加项",mergeTxt:"合并",...F},h={hideReset:!1,maxHeight:"600px",allowFilter:!0,showBorder:!0,showPad:!0,retractLen:0,borderColors:[],...v},g={arraySplitSymbol:",",...L},j=t=>["string","number"].includes(t),[S,n]=R.useState(()=>d(r));R.useImperativeHandle(y,()=>({getResult(t){return t==="ori"?S:O(S)},onSet(t){n(d(t??r))}}));function d(t){return Object.keys(t).map((a,x)=>{let s=t[a];const H=Array.isArray(s),z=H?s.every(D=>typeof D=="number"):typeof s=="number",I=s===null;return j(typeof s)&&(s=t[a]),I&&(s=""),{rId:k(x),key:a,value:Object.prototype.toString.call(s)==="[object Object]"?d(t[a]):H?s.join(g.arraySplitSymbol):s,isArray:H||void 0,isNumber:z||void 0}})}const O=t=>t.reduce((a,x)=>{const s=x.value;return x.key.trim().length&&(a[x.key]=Array.isArray(s)?O(s):K(x.value,x.isArray,x.isNumber,g.arraySplitSymbol)),a},{}),m=(t,a=1,x=[])=>e.jsx("div",{className:p([`depth-${a}`,h.showBorder?"":"no-border",h.showPad?"":"no-pad"]),style:{"--depth":a,["--c"+[a]]:Q(h.borderColors,a)},children:t.map((s,H,z)=>{const I=[...x,H],D=Array.isArray(s.value),G=j(typeof s.value);return e.jsxs("div",{className:"dItem",style:{marginLeft:a>1?`${a*h.retractLen}px`:"0"},children:[e.jsxs("div",{className:"input",children:[!D&&e.jsxs(e.Fragment,{children:[e.jsx("input",{value:s.key,className:"key nativeInput",onInput:A=>{const N=A.target.value;n(b=>T(b,I,(i,f)=>{const w=[...i],C=w[f];return w[f]={...C,key:N},w}))}}),":"]}),e.jsxs("div",{className:"vInput",children:[e.jsx("div",{className:"slot",children:Array.isArray(s.value)?void 0:e.jsxs(e.Fragment,{children:[e.jsx("button",{className:p([s.isArray?"success":"default","small","bt"]),onClick:()=>{n(A=>T(A,I,(N,b)=>{const i=[...N],f=i[b];return i[b]={...f,isArray:!f.isArray},i}))},children:"Array"})," ",e.jsx("button",{className:p([s.isNumber?"success":"default","small","bt"]),onClick:()=>{n(A=>T(A,I,(N,b)=>{const i=[...N],f=i[b];return i[b]={...f,isNumber:!f.isNumber},i}))},children:"Number"})]})}),e.jsx("input",{className:`value nativeV ${D?"isKey":""}`,value:G?s.value:s.key,onInput:A=>{const N=A.target.value;if(D){n(i=>T(i,I,(f,w)=>{const C=[...f],E=C[w];return C[w]={...E,key:N},C}));return}let b=N;h.allowFilter&&s.isNumber&&(b=W(N,s.isArray,g.arraySplitSymbol)),n(i=>T(i,I,(f,w)=>{const C=[...f],E=C[w];return C[w]={...E,value:b},C}))}}),e.jsx("div",{className:"surSlot",children:a<c?!D&&e.jsx("button",{className:p(["success","bt"]),onClick:()=>{n(A=>T(A,I,(N,b)=>{const i=[...N],f=i[b],C=[...Array.isArray(f.value)?f.value:[],{rId:k(),key:"",value:""}];return i[b]={...f,isArray:void 0,isNumber:void 0,value:C},i}))},children:B(s)}):null})]})]}),e.jsxs("div",{className:"btn",children:[e.jsx("button",{className:p(["success","bt"]),disabled:H!==z.length-1,onClick:()=>{n(A=>T(A,I,(N,b)=>{const i=[...N];return i.splice(b+1,0,{rId:k(),key:"",value:""}),i}))},children:"+"}),e.jsx("button",{className:p(["danger","bt"]),onClick:()=>{n(A=>T(A,I,(N,b)=>{const i=[...N];return i.splice(b,1),i}))},children:"-"})]}),Array.isArray(s.value)&&m(s.value,a+1,I)]},s.rId)})});return R.useEffect(()=>{l&&M(O(S))},[S]),e.jsxs("div",{className:u??"dynamicCascadeInput",children:[e.jsx("div",{className:"dyFormList",style:{maxHeight:h.maxHeight},children:m(S)}),e.jsxs("div",{className:"control",children:[!S.length&&e.jsx("button",{className:p(["success","bt"]),onClick:()=>{n(t=>[...t,{rId:k(),key:"",value:""}])},children:$.newTxt}),!l&&e.jsxs(e.Fragment,{children:[!h.hideReset&&e.jsx("button",{className:p(["default","bt"]),onClick:()=>{n(d(r)),q?.()},children:$.resetTxt}),e.jsx("button",{className:p(["info","bt"]),onClick:()=>{const t=O(S);M(t),V?.(t,S),n(d(t))},children:$.mergeTxt})]})]})]})});exports.DynamicCascadeInput=X;exports.DynamicInput=U;
|
package/dist/index.mjs
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import { jsxs as v, jsx as
|
|
1
|
+
import { jsxs as v, jsx as o, Fragment as P } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef as q, useState as G, useRef as Z, useImperativeHandle as J, useEffect as Q } from "react";
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
const u = o[r], h = Array.isArray(u), $ = h ? u.every((D) => typeof D == "number") : typeof u == "number";
|
|
3
|
+
import './index.css';const B = (a, y, c) => Object.keys(a).map((r, s) => {
|
|
4
|
+
const u = a[r], h = Array.isArray(u), F = h ? u.every((D) => typeof D == "number") : typeof u == "number";
|
|
6
5
|
return {
|
|
7
6
|
rId: y(s),
|
|
8
7
|
key: r,
|
|
9
8
|
value: h ? u.join(c) : u,
|
|
10
9
|
isArray: h || void 0,
|
|
11
|
-
isNumber:
|
|
10
|
+
isNumber: F || void 0
|
|
12
11
|
};
|
|
13
|
-
}), W = (
|
|
12
|
+
}), W = (a, y) => a.reduce((c, r) => (r.key.trim() && (c[r.key] = U(r.value, r.isArray, r.isNumber, y)), c), {}), U = (a, y, c, r = ",") => {
|
|
14
13
|
let s;
|
|
15
|
-
return y ? c ? s = String(
|
|
16
|
-
}, X = (
|
|
14
|
+
return y ? c ? s = String(a).split(r).map(Number).filter((u) => !Number.isNaN(u)) : s = String(a).split(r) : c ? s = parseFloat(a) : s = a.toString(), s;
|
|
15
|
+
}, X = (a, y, c = ",") => {
|
|
17
16
|
const r = (s) => {
|
|
18
17
|
s = s.replace(/[^\d.-]/g, "");
|
|
19
18
|
let u = !1;
|
|
@@ -21,47 +20,50 @@ import './index.css';const P = (o, y, c) => Object.keys(o).map((r, s) => {
|
|
|
21
20
|
const h = s.indexOf(".");
|
|
22
21
|
return h !== -1 && (s = s.slice(0, h + 1) + s.slice(h + 1).replace(/\./g, "")), (u ? "-" : "") + s;
|
|
23
22
|
};
|
|
24
|
-
return y ?
|
|
25
|
-
}, ee = (
|
|
26
|
-
function
|
|
23
|
+
return y ? a.split(c).map((s) => r(s)).join(c) : r(a);
|
|
24
|
+
}, ee = (a) => `hsl(${a * 35 % 360}, 60%, 65%)`, te = (a, y) => a[y - 1] ?? ee(y);
|
|
25
|
+
function j(a, y, c) {
|
|
27
26
|
if (y.length === 0)
|
|
28
|
-
return c(
|
|
29
|
-
const [r, ...s] = y, u = [...
|
|
27
|
+
return c(a, -1);
|
|
28
|
+
const [r, ...s] = y, u = [...a];
|
|
30
29
|
if (s.length === 0)
|
|
31
30
|
return c(u, r);
|
|
32
31
|
const h = u[r];
|
|
33
32
|
if (!Array.isArray(h.value)) return u;
|
|
34
|
-
const
|
|
33
|
+
const F = j(
|
|
35
34
|
h.value,
|
|
36
35
|
s,
|
|
37
36
|
c
|
|
38
37
|
);
|
|
39
|
-
return
|
|
38
|
+
return F.length === 0 ? u[r] = {
|
|
40
39
|
...h,
|
|
41
40
|
value: "",
|
|
42
41
|
isArray: void 0,
|
|
43
42
|
isNumber: void 0
|
|
44
|
-
} : u[r] = { ...h, value:
|
|
43
|
+
} : u[r] = { ...h, value: F }, u;
|
|
45
44
|
}
|
|
46
|
-
|
|
45
|
+
function g(a) {
|
|
46
|
+
return a.filter(Boolean).join(" ");
|
|
47
|
+
}
|
|
48
|
+
const se = q((a, y) => {
|
|
47
49
|
const {
|
|
48
50
|
value: c,
|
|
49
51
|
size: r,
|
|
50
52
|
dyCls: s,
|
|
51
53
|
isController: u,
|
|
52
54
|
configs: h,
|
|
53
|
-
btnConfigs:
|
|
55
|
+
btnConfigs: F,
|
|
54
56
|
dyListConfigs: D,
|
|
55
57
|
randomFun: I = (n) => `${Date.now()}_${n ?? 0}`,
|
|
56
|
-
onReset:
|
|
58
|
+
onReset: z,
|
|
57
59
|
onMerge: _,
|
|
58
60
|
onChange: V
|
|
59
|
-
} =
|
|
61
|
+
} = a, L = {
|
|
60
62
|
resetTxt: "重置",
|
|
61
63
|
newTxt: "添加项",
|
|
62
64
|
mergeTxt: "合并",
|
|
63
|
-
|
|
64
|
-
},
|
|
65
|
+
...F
|
|
66
|
+
}, $ = {
|
|
65
67
|
hideReset: !1,
|
|
66
68
|
maxHeight: "300px",
|
|
67
69
|
autoScroll: !0,
|
|
@@ -70,20 +72,20 @@ const le = q((o, y) => {
|
|
|
70
72
|
}, f = {
|
|
71
73
|
arraySplitSymbol: ",",
|
|
72
74
|
...D
|
|
73
|
-
}, [k, S] = G(() =>
|
|
75
|
+
}, [k, S] = G(() => B(c, I, f.arraySplitSymbol)), C = Z(null);
|
|
74
76
|
return J(y, () => ({
|
|
75
77
|
getResult(n) {
|
|
76
78
|
return n === "ori" ? k : W(k, f.arraySplitSymbol);
|
|
77
79
|
},
|
|
78
80
|
onSet(n) {
|
|
79
|
-
S(
|
|
81
|
+
S(B(n ?? c, I, f.arraySplitSymbol));
|
|
80
82
|
}
|
|
81
83
|
})), Q(() => {
|
|
82
84
|
u && V(W(k, f.arraySplitSymbol));
|
|
83
85
|
}, [k]), /* @__PURE__ */ v("div", { className: s ?? `dynamicInput ${r}`, children: [
|
|
84
|
-
/* @__PURE__ */
|
|
86
|
+
/* @__PURE__ */ o("div", { className: "dyFormList", ref: C, style: { maxHeight: $.maxHeight }, children: k.map((n, d, O) => /* @__PURE__ */ v("div", { className: "dItem", children: [
|
|
85
87
|
/* @__PURE__ */ v("div", { className: "input", children: [
|
|
86
|
-
/* @__PURE__ */
|
|
88
|
+
/* @__PURE__ */ o("input", { value: n.key, className: "key nativeInput", onInput: (m) => {
|
|
87
89
|
const e = m.target.value;
|
|
88
90
|
S((l) => {
|
|
89
91
|
const p = [...l], t = p[d];
|
|
@@ -93,7 +95,7 @@ const le = q((o, y) => {
|
|
|
93
95
|
":",
|
|
94
96
|
/* @__PURE__ */ v("div", { className: "vInput", children: [
|
|
95
97
|
/* @__PURE__ */ v("div", { className: "slot", children: [
|
|
96
|
-
/* @__PURE__ */
|
|
98
|
+
/* @__PURE__ */ o(
|
|
97
99
|
"button",
|
|
98
100
|
{
|
|
99
101
|
className: g([
|
|
@@ -111,7 +113,7 @@ const le = q((o, y) => {
|
|
|
111
113
|
}
|
|
112
114
|
),
|
|
113
115
|
" ",
|
|
114
|
-
/* @__PURE__ */
|
|
116
|
+
/* @__PURE__ */ o(
|
|
115
117
|
"button",
|
|
116
118
|
{
|
|
117
119
|
className: g([
|
|
@@ -129,10 +131,10 @@ const le = q((o, y) => {
|
|
|
129
131
|
}
|
|
130
132
|
)
|
|
131
133
|
] }),
|
|
132
|
-
/* @__PURE__ */
|
|
134
|
+
/* @__PURE__ */ o("input", { value: n.value, className: "value nativeV", onInput: (m) => {
|
|
133
135
|
const e = m.target.value;
|
|
134
136
|
let l = e;
|
|
135
|
-
n.isNumber &&
|
|
137
|
+
n.isNumber && $.allowFilter && (l = X(
|
|
136
138
|
e,
|
|
137
139
|
n.isArray,
|
|
138
140
|
f.arraySplitSymbol
|
|
@@ -144,13 +146,13 @@ const le = q((o, y) => {
|
|
|
144
146
|
] })
|
|
145
147
|
] }),
|
|
146
148
|
/* @__PURE__ */ v("div", { className: "btn", children: [
|
|
147
|
-
/* @__PURE__ */
|
|
149
|
+
/* @__PURE__ */ o(
|
|
148
150
|
"button",
|
|
149
151
|
{
|
|
150
152
|
className: g([r, "success", "bt"]),
|
|
151
153
|
disabled: d !== O.length - 1,
|
|
152
154
|
onClick: () => {
|
|
153
|
-
S((m) => [...m, { rId: I(), key: "", value: "" }]),
|
|
155
|
+
S((m) => [...m, { rId: I(), key: "", value: "" }]), $.autoScroll && setTimeout(() => {
|
|
154
156
|
const m = C.current;
|
|
155
157
|
m?.scrollTo({ top: m?.scrollHeight + 20, behavior: "smooth" });
|
|
156
158
|
});
|
|
@@ -158,7 +160,7 @@ const le = q((o, y) => {
|
|
|
158
160
|
children: "+"
|
|
159
161
|
}
|
|
160
162
|
),
|
|
161
|
-
/* @__PURE__ */
|
|
163
|
+
/* @__PURE__ */ o("button", { className: g([
|
|
162
164
|
"danger",
|
|
163
165
|
r,
|
|
164
166
|
"bt"
|
|
@@ -168,52 +170,52 @@ const le = q((o, y) => {
|
|
|
168
170
|
] })
|
|
169
171
|
] }, n.rId)) }),
|
|
170
172
|
/* @__PURE__ */ v("div", { className: "control", children: [
|
|
171
|
-
!k.length && /* @__PURE__ */
|
|
173
|
+
!k.length && /* @__PURE__ */ o("button", { className: g([
|
|
172
174
|
"success",
|
|
173
175
|
r,
|
|
174
176
|
"bt"
|
|
175
177
|
]), onClick: () => {
|
|
176
178
|
S((n) => [...n, { rId: I(), key: "", value: "" }]);
|
|
177
179
|
}, children: L.newTxt }),
|
|
178
|
-
!u && /* @__PURE__ */ v(
|
|
179
|
-
|
|
180
|
+
!u && /* @__PURE__ */ v(P, { children: [
|
|
181
|
+
!$.hideReset && /* @__PURE__ */ o("button", { className: g([
|
|
180
182
|
"default",
|
|
181
183
|
r,
|
|
182
184
|
"bt"
|
|
183
185
|
]), onClick: () => {
|
|
184
|
-
S(
|
|
186
|
+
S(B(c, I, f.arraySplitSymbol)), z?.();
|
|
185
187
|
}, children: L.resetTxt }),
|
|
186
|
-
/* @__PURE__ */
|
|
188
|
+
/* @__PURE__ */ o("button", { className: g([
|
|
187
189
|
"info",
|
|
188
190
|
r,
|
|
189
191
|
"bt"
|
|
190
192
|
]), onClick: () => {
|
|
191
193
|
[...k].sort((O, m) => +O.rId - +m.rId);
|
|
192
194
|
const d = W(k, f.arraySplitSymbol);
|
|
193
|
-
V(d), _?.(d, k), S(
|
|
195
|
+
V(d), _?.(d, k), S(B(d, I, f.arraySplitSymbol));
|
|
194
196
|
}, children: L.mergeTxt })
|
|
195
197
|
] })
|
|
196
198
|
] })
|
|
197
199
|
] });
|
|
198
|
-
}),
|
|
200
|
+
}), le = q((a, y) => {
|
|
199
201
|
const {
|
|
200
202
|
depth: c = 5,
|
|
201
203
|
value: r,
|
|
202
204
|
isController: s,
|
|
203
205
|
dyCls: u,
|
|
204
206
|
configs: h,
|
|
205
|
-
btnConfigs:
|
|
207
|
+
btnConfigs: F,
|
|
206
208
|
dyListConfigs: D,
|
|
207
209
|
randomFun: I = (e) => `${Date.now()}_${e ?? 0}`,
|
|
208
|
-
newChildTxt:
|
|
210
|
+
newChildTxt: z = (e) => `添加 '${e.key}' 子项`,
|
|
209
211
|
onReset: _,
|
|
210
212
|
onMerge: V,
|
|
211
213
|
onChange: L
|
|
212
|
-
} =
|
|
214
|
+
} = a, $ = {
|
|
213
215
|
resetTxt: "重置",
|
|
214
216
|
newTxt: "添加项",
|
|
215
217
|
mergeTxt: "合并",
|
|
216
|
-
|
|
218
|
+
...F
|
|
217
219
|
}, f = {
|
|
218
220
|
hideReset: !1,
|
|
219
221
|
maxHeight: "600px",
|
|
@@ -251,7 +253,7 @@ const le = q((o, y) => {
|
|
|
251
253
|
const O = (e) => e.reduce((l, p) => {
|
|
252
254
|
const t = p.value;
|
|
253
255
|
return p.key.trim().length && (l[p.key] = Array.isArray(t) ? O(t) : U(p.value, p.isArray, p.isNumber, k.arraySplitSymbol)), l;
|
|
254
|
-
}, {}), m = (e, l = 1, p = []) => /* @__PURE__ */
|
|
256
|
+
}, {}), m = (e, l = 1, p = []) => /* @__PURE__ */ o(
|
|
255
257
|
"div",
|
|
256
258
|
{
|
|
257
259
|
className: g([
|
|
@@ -273,8 +275,8 @@ const le = q((o, y) => {
|
|
|
273
275
|
style: { marginLeft: l > 1 ? `${l * f.retractLen}px` : "0" },
|
|
274
276
|
children: [
|
|
275
277
|
/* @__PURE__ */ v("div", { className: "input", children: [
|
|
276
|
-
!M && /* @__PURE__ */ v(
|
|
277
|
-
/* @__PURE__ */
|
|
278
|
+
!M && /* @__PURE__ */ v(P, { children: [
|
|
279
|
+
/* @__PURE__ */ o(
|
|
278
280
|
"input",
|
|
279
281
|
{
|
|
280
282
|
value: t.key,
|
|
@@ -282,7 +284,7 @@ const le = q((o, y) => {
|
|
|
282
284
|
onInput: (x) => {
|
|
283
285
|
const A = x.target.value;
|
|
284
286
|
n(
|
|
285
|
-
(b) =>
|
|
287
|
+
(b) => j(b, w, (i, N) => {
|
|
286
288
|
const R = [...i], T = R[N];
|
|
287
289
|
return R[N] = { ...T, key: A }, R;
|
|
288
290
|
})
|
|
@@ -293,8 +295,8 @@ const le = q((o, y) => {
|
|
|
293
295
|
":"
|
|
294
296
|
] }),
|
|
295
297
|
/* @__PURE__ */ v("div", { className: "vInput", children: [
|
|
296
|
-
/* @__PURE__ */
|
|
297
|
-
/* @__PURE__ */
|
|
298
|
+
/* @__PURE__ */ o("div", { className: "slot", children: Array.isArray(t.value) ? void 0 : /* @__PURE__ */ v(P, { children: [
|
|
299
|
+
/* @__PURE__ */ o(
|
|
298
300
|
"button",
|
|
299
301
|
{
|
|
300
302
|
className: g([
|
|
@@ -304,7 +306,7 @@ const le = q((o, y) => {
|
|
|
304
306
|
]),
|
|
305
307
|
onClick: () => {
|
|
306
308
|
n(
|
|
307
|
-
(x) =>
|
|
309
|
+
(x) => j(x, w, (A, b) => {
|
|
308
310
|
const i = [...A], N = i[b];
|
|
309
311
|
return i[b] = {
|
|
310
312
|
...N,
|
|
@@ -317,7 +319,7 @@ const le = q((o, y) => {
|
|
|
317
319
|
}
|
|
318
320
|
),
|
|
319
321
|
" ",
|
|
320
|
-
/* @__PURE__ */
|
|
322
|
+
/* @__PURE__ */ o(
|
|
321
323
|
"button",
|
|
322
324
|
{
|
|
323
325
|
className: g([
|
|
@@ -327,7 +329,7 @@ const le = q((o, y) => {
|
|
|
327
329
|
]),
|
|
328
330
|
onClick: () => {
|
|
329
331
|
n(
|
|
330
|
-
(x) =>
|
|
332
|
+
(x) => j(x, w, (A, b) => {
|
|
331
333
|
const i = [...A], N = i[b];
|
|
332
334
|
return i[b] = {
|
|
333
335
|
...N,
|
|
@@ -340,7 +342,7 @@ const le = q((o, y) => {
|
|
|
340
342
|
}
|
|
341
343
|
)
|
|
342
344
|
] }) }),
|
|
343
|
-
/* @__PURE__ */
|
|
345
|
+
/* @__PURE__ */ o(
|
|
344
346
|
"input",
|
|
345
347
|
{
|
|
346
348
|
className: `value nativeV ${M ? "isKey" : ""}`,
|
|
@@ -349,7 +351,7 @@ const le = q((o, y) => {
|
|
|
349
351
|
const A = x.target.value;
|
|
350
352
|
if (M) {
|
|
351
353
|
n(
|
|
352
|
-
(i) =>
|
|
354
|
+
(i) => j(i, w, (N, R) => {
|
|
353
355
|
const T = [...N], K = T[R];
|
|
354
356
|
return T[R] = { ...K, key: A }, T;
|
|
355
357
|
})
|
|
@@ -362,7 +364,7 @@ const le = q((o, y) => {
|
|
|
362
364
|
t.isArray,
|
|
363
365
|
k.arraySplitSymbol
|
|
364
366
|
)), n(
|
|
365
|
-
(i) =>
|
|
367
|
+
(i) => j(i, w, (N, R) => {
|
|
366
368
|
const T = [...N], K = T[R];
|
|
367
369
|
return T[R] = { ...K, value: b }, T;
|
|
368
370
|
})
|
|
@@ -370,7 +372,7 @@ const le = q((o, y) => {
|
|
|
370
372
|
}
|
|
371
373
|
}
|
|
372
374
|
),
|
|
373
|
-
/* @__PURE__ */
|
|
375
|
+
/* @__PURE__ */ o("div", { className: "surSlot", children: l < c ? !M && /* @__PURE__ */ o(
|
|
374
376
|
"button",
|
|
375
377
|
{
|
|
376
378
|
className: g([
|
|
@@ -379,7 +381,7 @@ const le = q((o, y) => {
|
|
|
379
381
|
]),
|
|
380
382
|
onClick: () => {
|
|
381
383
|
n(
|
|
382
|
-
(x) =>
|
|
384
|
+
(x) => j(x, w, (A, b) => {
|
|
383
385
|
const i = [...A], N = i[b], T = [
|
|
384
386
|
...Array.isArray(N.value) ? N.value : [],
|
|
385
387
|
{ rId: I(), key: "", value: "" }
|
|
@@ -393,19 +395,19 @@ const le = q((o, y) => {
|
|
|
393
395
|
})
|
|
394
396
|
);
|
|
395
397
|
},
|
|
396
|
-
children:
|
|
398
|
+
children: z(t)
|
|
397
399
|
}
|
|
398
400
|
) : null })
|
|
399
401
|
] })
|
|
400
402
|
] }),
|
|
401
403
|
/* @__PURE__ */ v("div", { className: "btn", children: [
|
|
402
|
-
/* @__PURE__ */
|
|
404
|
+
/* @__PURE__ */ o(
|
|
403
405
|
"button",
|
|
404
406
|
{
|
|
405
407
|
className: g(["success", "bt"]),
|
|
406
408
|
disabled: H !== E.length - 1,
|
|
407
409
|
onClick: () => {
|
|
408
|
-
n((x) =>
|
|
410
|
+
n((x) => j(x, w, (A, b) => {
|
|
409
411
|
const i = [...A];
|
|
410
412
|
return i.splice(b + 1, 0, {
|
|
411
413
|
rId: I(),
|
|
@@ -417,7 +419,7 @@ const le = q((o, y) => {
|
|
|
417
419
|
children: "+"
|
|
418
420
|
}
|
|
419
421
|
),
|
|
420
|
-
/* @__PURE__ */
|
|
422
|
+
/* @__PURE__ */ o(
|
|
421
423
|
"button",
|
|
422
424
|
{
|
|
423
425
|
className: g([
|
|
@@ -426,7 +428,7 @@ const le = q((o, y) => {
|
|
|
426
428
|
]),
|
|
427
429
|
onClick: () => {
|
|
428
430
|
n(
|
|
429
|
-
(x) =>
|
|
431
|
+
(x) => j(x, w, (A, b) => {
|
|
430
432
|
const i = [...A];
|
|
431
433
|
return i.splice(b, 1), i;
|
|
432
434
|
})
|
|
@@ -447,9 +449,9 @@ const le = q((o, y) => {
|
|
|
447
449
|
return Q(() => {
|
|
448
450
|
s && L(O(C));
|
|
449
451
|
}, [C]), /* @__PURE__ */ v("div", { className: u ?? "dynamicCascadeInput", children: [
|
|
450
|
-
/* @__PURE__ */
|
|
452
|
+
/* @__PURE__ */ o("div", { className: "dyFormList", style: { maxHeight: f.maxHeight }, children: m(C) }),
|
|
451
453
|
/* @__PURE__ */ v("div", { className: "control", children: [
|
|
452
|
-
!C.length && /* @__PURE__ */
|
|
454
|
+
!C.length && /* @__PURE__ */ o(
|
|
453
455
|
"button",
|
|
454
456
|
{
|
|
455
457
|
className: g([
|
|
@@ -459,11 +461,11 @@ const le = q((o, y) => {
|
|
|
459
461
|
onClick: () => {
|
|
460
462
|
n((e) => [...e, { rId: I(), key: "", value: "" }]);
|
|
461
463
|
},
|
|
462
|
-
children:
|
|
464
|
+
children: $.newTxt
|
|
463
465
|
}
|
|
464
466
|
),
|
|
465
|
-
!s && /* @__PURE__ */ v(
|
|
466
|
-
!f.hideReset && /* @__PURE__ */
|
|
467
|
+
!s && /* @__PURE__ */ v(P, { children: [
|
|
468
|
+
!f.hideReset && /* @__PURE__ */ o(
|
|
467
469
|
"button",
|
|
468
470
|
{
|
|
469
471
|
className: g([
|
|
@@ -473,10 +475,10 @@ const le = q((o, y) => {
|
|
|
473
475
|
onClick: () => {
|
|
474
476
|
n(d(r)), _?.();
|
|
475
477
|
},
|
|
476
|
-
children:
|
|
478
|
+
children: $.resetTxt
|
|
477
479
|
}
|
|
478
480
|
),
|
|
479
|
-
/* @__PURE__ */
|
|
481
|
+
/* @__PURE__ */ o(
|
|
480
482
|
"button",
|
|
481
483
|
{
|
|
482
484
|
className: g([
|
|
@@ -487,7 +489,7 @@ const le = q((o, y) => {
|
|
|
487
489
|
const e = O(C);
|
|
488
490
|
L(e), V?.(e, C), n(d(e));
|
|
489
491
|
},
|
|
490
|
-
children:
|
|
492
|
+
children: $.mergeTxt
|
|
491
493
|
}
|
|
492
494
|
)
|
|
493
495
|
] })
|
|
@@ -495,6 +497,6 @@ const le = q((o, y) => {
|
|
|
495
497
|
] });
|
|
496
498
|
});
|
|
497
499
|
export {
|
|
498
|
-
|
|
499
|
-
|
|
500
|
+
le as DynamicCascadeInput,
|
|
501
|
+
se as DynamicInput
|
|
500
502
|
};
|
package/dist/utils/tools.d.ts
CHANGED
|
@@ -7,4 +7,5 @@ declare const getDepthColor: (depth: number) => string;
|
|
|
7
7
|
declare const saferRepairColor: (colors: string[], i: number) => string;
|
|
8
8
|
declare function updateArrayAtPath(items: DyCasFormItem[], path: number[], // 指向某个 item(最后一个数字是下标)
|
|
9
9
|
updater: (arr: DyCasFormItem[], index: number) => DyCasFormItem[]): DyCasFormItem[];
|
|
10
|
-
|
|
10
|
+
declare function clsx(clsArr: (string | undefined)[]): string;
|
|
11
|
+
export { tranArr, resetObj, parseValue, formatNumberInput, getDepthColor, saferRepairColor, updateArrayAtPath, clsx };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dynamicformdjx-react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "xczcdjx",
|
|
6
6
|
"license": "MIT",
|
|
@@ -51,7 +51,6 @@
|
|
|
51
51
|
"@types/react-dom": "^18.3.7",
|
|
52
52
|
"@vitejs/plugin-react": "^5.1.1",
|
|
53
53
|
"antd": "^5.29.1",
|
|
54
|
-
"clsx": "^2.1.1",
|
|
55
54
|
"eslint": "^9.39.1",
|
|
56
55
|
"eslint-plugin-react-hooks": "^7.0.1",
|
|
57
56
|
"eslint-plugin-react-refresh": "^0.4.24",
|