@wwog/react 1.2.3 → 1.2.4
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 +5 -2
- package/dist/index.d.mts +9 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/utils/index.ts +12 -0
package/README.md
CHANGED
|
@@ -320,13 +320,16 @@ function Layout() {
|
|
|
320
320
|
|
|
321
321
|
- 受控组件和非受控组件的切换,方便组件开发
|
|
322
322
|
|
|
323
|
-
###
|
|
323
|
+
### utils
|
|
324
324
|
|
|
325
325
|
- 用于部分组件的内部函数,如需要也可使用
|
|
326
326
|
|
|
327
|
-
formatDate
|
|
327
|
+
formatDate 比较标准的格式化时间函数
|
|
328
|
+
|
|
328
329
|
childrenLoop 可以中断的子节点遍历,让一些分支流程拥有极致性能
|
|
329
330
|
|
|
331
|
+
Counter 计数器
|
|
332
|
+
|
|
330
333
|
## License
|
|
331
334
|
|
|
332
335
|
MIT
|
package/dist/index.d.mts
CHANGED
|
@@ -384,6 +384,14 @@ declare function childrenLoop(children: React$1.ReactNode | undefined, callback:
|
|
|
384
384
|
* a | am | pm
|
|
385
385
|
*/
|
|
386
386
|
declare function formatDate(schema: string, date?: Date): string;
|
|
387
|
+
declare class Counter {
|
|
388
|
+
count: number;
|
|
389
|
+
/**
|
|
390
|
+
* @description 获取下一个计数值,不考虑越界。
|
|
391
|
+
* @description_en Get the next count value, without considering overflow.
|
|
392
|
+
*/
|
|
393
|
+
next(): number;
|
|
394
|
+
}
|
|
387
395
|
|
|
388
396
|
interface UseControlledOptions<T> {
|
|
389
397
|
/**
|
|
@@ -412,5 +420,5 @@ interface UseControlledOptions<T> {
|
|
|
412
420
|
}
|
|
413
421
|
declare function useControlled<T>(options: UseControlledOptions<T>): [T, Dispatch<React.SetStateAction<T>>];
|
|
414
422
|
|
|
415
|
-
export { ArrayRender, DateRender, False, If, Pipe, Scope, SizeBox, Switch, Toggle, True, When, childrenLoop, formatDate, useControlled };
|
|
423
|
+
export { ArrayRender, Counter, DateRender, False, If, Pipe, Scope, SizeBox, Switch, Toggle, True, When, childrenLoop, formatDate, useControlled };
|
|
416
424
|
export type { ArrayRenderProps, DateRenderProps, ElseIfProps, ElseProps, FalseProps, IfProps, PipeProps, ScopeProps, SwitchCaseProps, SwitchDefaultProps, SwitchProps, ThenProps, ToggleProps, TrueProps, UseControlledOptions, WhenProps };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import r,{useMemo as
|
|
1
|
+
import r,{useMemo as p,useEffect as J,useState as b,Fragment as O,useCallback as H}from"react";function I(e,t){if(e===void 0)return;let n=0;if(Array.isArray(e)){for(const l of e)if(t(l,n++)===!1)break}else t(e,n)}function R(e,t){const n=t||new Date,l=n.getFullYear(),a=n.getMonth()+1,o=n.getDate(),i=n.getHours(),c=n.getMinutes(),u=n.getSeconds(),d=n.getMilliseconds(),s=n.getDay(),f=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],m=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],y=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],T=["January","February","March","April","May","June","July","August","September","October","November","December"],M=s===0?6:s-1,C=m[M],v=f[M],D=a-1,Y=T[D],x=y[D],A={YY:l.toString().slice(2),YYYY:l.toString(),M:a.toString(),MM:a.toString().padStart(2,"0"),MMM:x,MMMM:Y,D:o.toString(),DD:o.toString().padStart(2,"0"),d:s.toString(),dd:v,ddd:v,dddd:C,H:i.toString(),HH:i.toString().padStart(2,"0"),h:(i%12).toString(),hh:(i%12).toString().padStart(2,"0"),m:c.toString(),mm:c.toString().padStart(2,"0"),s:u.toString(),ss:u.toString().padStart(2,"0"),SSS:d.toString().padStart(3,"0"),Z:"+08:00",ZZ:"+0800",A:i<12?"AM":"PM",a:i<12?"am":"pm"};return e.replace(/YYYY|YY|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|m{1,2}|s{1,2}|SSS|Z{1,2}|A|a/g,k=>A[k])}class _{count=0;next(){return this.count++}}const B=(e,t)=>e===t,S=e=>r.createElement(r.Fragment,null,e.children);S.displayName="Switch_Case";const E=e=>r.createElement(r.Fragment,null,e.children);E.displayName="Switch_Default";const g=e=>{const{value:t,compare:n=B,children:l,strict:a=!1}=e,o=new Set;let i=null,c=null,u=!1;return I(l,(d,s)=>{if(!r.isValidElement(d))throw new Error(`Switch Children only accepts valid React elements at index ${s}`);const f=d.type;if(f.displayName===S.displayName){const m=d.props;if(o.has(m.value))throw new Error(`Switch found duplicate Case value at index ${s}: ${JSON.stringify(m.value)}${a?" (detected in strict mode)":""}`);if(o.add(m.value),!i&&n(t,m.value)&&(i=m.children,a===!1))return!1}else if(f.displayName===E.displayName){if(u)throw new Error(`Switch can only have one Default child at index ${s}`);if(u=!0,c=d.props.children,!a&&i)return!1}else throw new Error(`Switch Children only accepts 'Case' or 'Default' elements, found: ${String(f.displayName||f.name||f)} at index ${s}`)}),r.createElement(r.Fragment,null,i??c)};g.displayName="Switch",g.Case=S,g.Default=E,g.createTyped=function(){return{Switch:g,Case:S,Default:E}};const w=e=>r.createElement(r.Fragment,null,e.children),N=({children:e})=>r.createElement(r.Fragment,null,e),F=e=>r.createElement(r.Fragment,null,e.children);w.displayName="If_Then",N.displayName="If_Else",F.displayName="If_ElseIf";const h=({condition:e,children:t})=>{let n=null,l=null;const a=[];if(r.Children.forEach(t,o=>{if(!r.isValidElement(o))throw new Error("If component only accepts valid React elements");const i=o.type;if(i.displayName===w.displayName){if(n)throw new Error("If component can only have one Then child");n=o}else if(i.displayName===F.displayName)a.push(o);else if(i.displayName===N.displayName){if(l)throw new Error("If component can only have one Else child");l=o}else throw new Error(`If component only accepts 'Then', 'ElseIf', or 'Else' elements as children, found: ${String(i.displayName||i.name||i)}`)}),e)return n?r.createElement(r.Fragment,null,n.props.children):null;for(const o of a)if(o.props.condition)return r.createElement(r.Fragment,null,o.props.children);return l?r.createElement(r.Fragment,null,l.props.children):null};h.displayName="If",h.Then=w,h.ElseIf=F,h.Else=N,h.createTyped=function(){return{If:h,Then:w,ElseIf:F,Else:N}};const P=({condition:e,children:t})=>e?r.createElement(r.Fragment,null,t):null,W=({condition:e,children:t})=>e===!1?r.createElement(r.Fragment,null,t):null,Z=({all:e,any:t,none:n,children:l,fallback:a})=>p(()=>(e&&(t||n)&&console.warn('When: Multiple condition types (all, any, none) provided; "all" takes precedence.'),!!(e&&e.length>0&&e.every(Boolean)||t&&t.length>0&&t.some(Boolean)||n&&n.length>0&&n.every(o=>!o))),[e,t,n])?r.createElement(r.Fragment,null,l):r.createElement(r.Fragment,null,a||null),V=({data:e,transform:t,render:n,fallback:l})=>{const a=p(()=>t.reduce((o,i)=>i(o),e),[e,t]);return a==null?r.createElement(r.Fragment,null,l||null):r.createElement(r.Fragment,null,n(a))},$=e=>{const{index:t=0,options:n,next:l,render:a}=e;J(()=>{if(n.length<t+1)throw new Error(`Index ${t} is out of bounds for options array of length ${n.length}. Defaulting to first option.`)},[t,n]);const[o,i]=b(t),c=()=>{i(u=>n.length?l?l(u,n):(u+1)%n.length:u)};return a(n[o],c)},j=e=>{const{children:t,h:n,w:l,size:a,height:o,width:i,className:c}=e;return r.createElement("div",{style:{width:a||l||i,height:a||n||o,flexShrink:0},className:c},t)};function z(e){const{items:t,renderItem:n,filter:l}=e;return t?r.createElement(O,null,t.map((a,o)=>l&&!l(a)?null:n(a,o))):(console.error("ArrayRender: items is null"),null)}const L=({let:e,props:t,children:n,fallback:l})=>{const a=p(()=>typeof e=="function"?e(t):e,[e,t]);return!n||!Object.keys(a).length?r.createElement(r.Fragment,null,l||null):r.createElement(r.Fragment,null,n(a))};function q({source:e,format:t,children:n}){const l=p(()=>{if(e instanceof Date)return e;if(typeof e=="string"||typeof e=="number"){const o=new Date(e);return isNaN(o.getTime())?null:o}return null},[e]),a=p(()=>l?t?t(l):l.toLocaleString():null,[l,t]);return!a||!n?null:r.createElement(r.Fragment,null,n(a))}const G="onChange",K="value";function Q(e){const{defaultValue:t,onBeforeChange:n,trigger:l=G,valuePropName:a=K,props:o}=e,i=Object.prototype.hasOwnProperty.call(o,a),[c,u]=b(t),d=i?o[a]:c,s=p(()=>o[l],[o,l]),f=H(m=>{const y=typeof m=="function"?m(d):m;n&&n(y,d)===!1||(i||u(y),s&&s(y))},[i,n,l,d,s]);return[d,f]}export{z as ArrayRender,_ as Counter,q as DateRender,W as False,h as If,V as Pipe,L as Scope,j as SizeBox,g as Switch,$ as Toggle,P as True,Z as When,I as childrenLoop,R as formatDate,Q as useControlled};
|
package/package.json
CHANGED
package/src/utils/index.ts
CHANGED
|
@@ -139,3 +139,15 @@ export function formatDate(schema: string, date?: Date): string {
|
|
|
139
139
|
}
|
|
140
140
|
);
|
|
141
141
|
}
|
|
142
|
+
|
|
143
|
+
export class Counter {
|
|
144
|
+
count = 0;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* @description 获取下一个计数值,不考虑越界。
|
|
148
|
+
* @description_en Get the next count value, without considering overflow.
|
|
149
|
+
*/
|
|
150
|
+
next() {
|
|
151
|
+
return this.count++;
|
|
152
|
+
}
|
|
153
|
+
}
|