@wwog/react 1.3.5 → 1.3.6
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.d.mts +1 -6
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/hooks/{useScreen.tsx → useScreen.ts} +1 -22
package/README.md
CHANGED
|
@@ -458,7 +458,7 @@ You can also use a container wrapper element:
|
|
|
458
458
|
|
|
459
459
|
- Supports passing in custom breakpoints, defaults to the same breakpoint definitions as TailwindCSS
|
|
460
460
|
|
|
461
|
-
This hook is implemented based on listening. If
|
|
461
|
+
This hook is implemented based on listening. If useScreen needs to be used multiple times without changing the passed parameters, it is recommended to wrap Context
|
|
462
462
|
|
|
463
463
|
Development notes: Internally implemented via `mediaQuery`, it does not listen to a specific breakpoint but is optimized to listen only to the previous and next breakpoints of the current breakpoint for better performance.
|
|
464
464
|
|
package/dist/index.d.mts
CHANGED
|
@@ -716,11 +716,6 @@ type Responsive<T> = T | Partial<Record<BreakpointName, T>>;
|
|
|
716
716
|
|
|
717
717
|
declare function getCurrentBreakpoint(breakpointDesc: BreakpointDesc, width: number): BreakpointName;
|
|
718
718
|
declare function useScreen(breakpointDesc?: BreakpointDesc): "base" | "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl";
|
|
719
|
-
declare function BreakpointProvider({ children, breakpointDesc, }: {
|
|
720
|
-
children: React$1.ReactNode;
|
|
721
|
-
breakpointDesc?: BreakpointDesc;
|
|
722
|
-
}): React$1.JSX.Element;
|
|
723
|
-
declare function useBreakpoint(): "base" | "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl";
|
|
724
719
|
|
|
725
|
-
export { ArrayRender,
|
|
720
|
+
export { ArrayRender, Counter, DateRender, DefBreakpointDesc, False, If, Observer, Pipe, Scope, SizeBox, Styles, Switch, Toggle, True, When, breakpoints, childrenLoop, createExternalState, createStorageState, cx, formatDate, getCurrentBreakpoint, safePromiseTry, useControlled, useScreen };
|
|
726
721
|
export type { ArrayRenderProps, BreakpointDesc, BreakpointName, CreateStateListener, CxInput, DateRenderProps, ElseIfProps, ElseProps, ExternalSideEffect, ExternalState, ExternalStateOptions, ExternalWithKernel, FalseProps, IfProps, ObserverProps, PipeProps, Responsive, ScopeProps, StorageStateOptions, StylesDescriptor, StylesProps, StylesType, SwitchCaseProps, SwitchDefaultProps, SwitchProps, ThenProps, ToggleProps, Transform, TrueProps, UseControlledOptions, WhenProps };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import a,{useMemo as g,Fragment as E,Children as V,isValidElement as Z,cloneElement as z,useEffect as w,useState as k,useRef as C,useCallback as U,createContext as G,useContext as q}from"react";function Y(e,n){if(e===void 0)return;let t=0;if(Array.isArray(e)){for(const r of e)if(n(r,t++)===!1)break}else n(e,t)}const K=(e,n)=>e===n,v=e=>a.createElement(a.Fragment,null,e.children);v.displayName="Switch_Case";const N=e=>a.createElement(a.Fragment,null,e.children);N.displayName="Switch_Default";const y=e=>{const{value:n,compare:t=K,children:r,strict:l=!1}=e,o=new Set;let i=null,m=null,d=!1;return Y(r,(s,c)=>{if(!a.isValidElement(s))throw new Error(`Switch Children only accepts valid React elements at index ${c}`);const u=s.type;if(u.displayName===v.displayName){const f=s.props;if(o.has(f.value))throw new Error(`Switch found duplicate Case value at index ${c}: ${JSON.stringify(f.value)}${l?" (detected in strict mode)":""}`);if(o.add(f.value),!i&&t(n,f.value)&&(i=f.children,l===!1))return!1}else if(u.displayName===N.displayName){if(d)throw new Error(`Switch can only have one Default child at index ${c}`);if(d=!0,m=s.props.children,!l&&i)return!1}else throw new Error(`Switch Children only accepts 'Case' or 'Default' elements, found: ${String(u.displayName||u.name||u)} at index ${c}`)}),a.createElement(a.Fragment,null,i??m)};y.displayName="Switch",y.Case=v,y.Default=N,y.createTyped=function(){return{Switch:y,Case:v,Default:N}};const b=e=>a.createElement(a.Fragment,null,e.children),x=({children:e})=>a.createElement(a.Fragment,null,e),M=e=>a.createElement(a.Fragment,null,e.children);b.displayName="If_Then",x.displayName="If_Else",M.displayName="If_ElseIf";const p=({condition:e,children:n})=>{let t=null,r=null;const l=[];if(a.Children.forEach(n,o=>{if(!a.isValidElement(o))throw new Error("If component only accepts valid React elements");const i=o.type;if(i.displayName===b.displayName){if(t)throw new Error("If component can only have one Then child");t=o}else if(i.displayName===M.displayName)l.push(o);else if(i.displayName===x.displayName){if(r)throw new Error("If component can only have one Else child");r=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 t?a.createElement(a.Fragment,null,t.props.children):null;for(const o of l)if(o.props.condition)return a.createElement(a.Fragment,null,o.props.children);return r?a.createElement(a.Fragment,null,r.props.children):null};p.displayName="If",p.Then=b,p.ElseIf=M,p.Else=x,p.createTyped=function(){return{If:p,Then:b,ElseIf:M,Else:x}};const Q=({condition:e,children:n})=>e?a.createElement(a.Fragment,null,n):null,X=({condition:e,children:n})=>e===!1?a.createElement(a.Fragment,null,n):null,ee=({all:e,any:n,none:t,children:r,fallback:l})=>g(()=>(e&&(n||t)&&console.warn('When: Multiple condition types (all, any, none) provided; "all" takes precedence.'),!!(e&&e.length>0&&e.every(Boolean)||n&&n.length>0&&n.some(Boolean)||t&&t.length>0&&t.every(o=>!o))),[e,n,t])?a.createElement(a.Fragment,null,r):a.createElement(a.Fragment,null,l||null),te=({data:e,transform:n,render:t,fallback:r})=>{const l=g(()=>n.reduce((o,i)=>i(o),e),[e,n]);return l==null?a.createElement(a.Fragment,null,r||null):a.createElement(a.Fragment,null,t(l))},ne=e=>{const{children:n,h:t,w:r,size:l,height:o,width:i,className:m}=e;return a.createElement("div",{style:{width:l||r||i,height:l||t||o,flexShrink:0},className:m},n)},re=({let:e,props:n,children:t,fallback:r})=>{const l=g(()=>typeof e=="function"?e(n):e,[e,n]);return!t||!Object.keys(l).length?a.createElement(a.Fragment,null,r||null):a.createElement(a.Fragment,null,t(l))};function F(...e){const n=new Set;for(const t of e)if(t){if(typeof t=="string")n.add(t);else if(Array.isArray(t))t.forEach(r=>n.add(r));else if(typeof t=="object")for(const[r,l]of Object.entries(t))l&&n.add(r)}return Array.from(n).join(" ")}const oe=e=>typeof e=="object"&&!!e,O=({className:e,children:n,asWrapper:t=!1})=>{if(!n)return null;if(!e)return a.createElement(E,null,n);const r=typeof e=="string"?e:F(...Object.values(e));if(t)return a.createElement(t===!0?"div":t,{className:r},n);if(V.count(n)>1)return console.error("<Styles>: children has more than one child. Please check your code."),a.createElement(E,null,n);if(Z(n)){const l=n;let o=l?.props?.className;return l?.type?.displayName===O.displayName&&oe(o)&&(o=F(...Object.values(o))),z(n,{className:F(r,o)})}return console.error("<Styles>: children is not a valid React element. Please check your code."),a.createElement(E,null,n)};O.displayName="W/Styles";const le=e=>{const{index:n=0,options:t,next:r,render:l}=e;w(()=>{if(t.length<n+1)throw new Error(`Index ${n} is out of bounds for options array of length ${t.length}. Defaulting to first option.`)},[n,t]);const[o,i]=k(n),m=()=>{i(d=>t.length?r?r(d,t):(d+1)%t.length:d)};return l(t[o],m)},ae=({onIntersect:e,threshold:n=.1,root:t=null,rootMargin:r="0px",triggerOnce:l=!1,disabled:o=!1,children:i,className:m,style:d})=>{const s=C(null),c=C(null),u=C(!1);return w(()=>{if(o||!s.current)return;if(!window.IntersectionObserver){console.warn("IntersectionObserver is not supported in this browser");return}const f=s.current,h=D=>{D.forEach(I=>{l&&u.current||(e(I,c.current),l&&(u.current=!0,c.current?.unobserve(f)))})};return c.current=new IntersectionObserver(h,{root:t,rootMargin:r,threshold:n}),c.current.observe(f),()=>{c.current&&c.current.disconnect()}},[e,n,t,r,l,o]),w(()=>{l||(u.current=!1)},[l]),a.createElement("div",{ref:s,className:m,style:d},i)};function se(e){const{items:n,renderItem:t,filter:r}=e;return n?a.createElement(E,null,n.map((l,o)=>r&&!r(l)?null:t(l,o))):(console.error("ArrayRender: items is null"),null)}function ie({source:e,format:n,children:t}){const r=g(()=>{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]),l=g(()=>r?n?n(r):r.toLocaleString():null,[r,n]);return!l||!t?null:a.createElement(a.Fragment,null,t(l))}const ce="onChange",ue="value";function de(e){const{defaultValue:n,onBeforeChange:t,trigger:r=ce,valuePropName:l=ue,props:o}=e,i=Object.prototype.hasOwnProperty.call(o,l),[m,d]=k(n),s=i?o[l]:m,c=g(()=>o[r],[o,r]),u=U(f=>{const h=typeof f=="function"?f(s):f;t&&t(h,s)===!1||(i||d(h),c&&c(h))},[i,t,s,c]);return[s,u]}function fe(e,...n){try{const t=e(...n);return t instanceof Promise?t:Promise.resolve(t)}catch(t){return Promise.reject(t)}}const j=typeof Promise.try=="function"?Promise.try.bind(Promise):fe;function J(e,n={}){let t=typeof e=="function"?e():e;const r=[],{sideEffect:l,transform:o}=n,i=()=>{const s=t;return o?.get?o.get(s):s},m=s=>{const c=t,u=o?.get?o.get(c):c;t=o?.set?o.set(typeof s=="function"?s(u):s):typeof s=="function"?s(u):s,r.forEach(f=>f(t)),l&&j(l,t,c).catch(f=>{console.error("Error in external state side effect, Please do it within side effects:",f)})},d=()=>{const[s,c]=a.useState(t);return a.useEffect(()=>(r.push(c),()=>{const u=r.indexOf(c);u>-1&&r.splice(u,1)}),[]),[o?.get?o.get(s):s,m]};return{get:i,set:m,use:d,useGetter:()=>{const[s]=d();return s},__listeners:r}}function me(e,n,t){const{storageType:r="local",sideEffect:l,transform:o}=t??{},i=r==="local"?localStorage:sessionStorage;let m=n;const d=i.getItem(e);if(d)try{m=JSON.parse(d)}catch(s){console.warn(`Failed to parse ${r}Storage value for key "${e}", using initial state:`,s),m=n}return J(m,{sideEffect:s=>{i.setItem(e,JSON.stringify(s)),l?.(s)},transform:o})}function he(e,n){const t=n||new Date,r=t.getFullYear(),l=t.getMonth()+1,o=t.getDate(),i=t.getHours(),m=t.getMinutes(),d=t.getSeconds(),s=t.getMilliseconds(),c=t.getDay(),u=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],f=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],h=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],D=["January","February","March","April","May","June","July","August","September","October","November","December"],I=f[c],T=u[c],A=l-1,_=D[A],$=h[A],L={YY:r.toString().slice(2),YYYY:r.toString(),M:l.toString(),MM:l.toString().padStart(2,"0"),MMM:$,MMMM:_,D:o.toString(),DD:o.toString().padStart(2,"0"),d:c.toString(),dd:T,ddd:T,dddd:I,H:i.toString(),HH:i.toString().padStart(2,"0"),h:(i%12).toString(),hh:(i%12).toString().padStart(2,"0"),m:m.toString(),mm:m.toString().padStart(2,"0"),s:d.toString(),ss:d.toString().padStart(2,"0"),SSS:s.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,H=>L[H])}class pe{count=0;next(){return this.count++}}const S=["base","xs","sm","md","lg","xl","2xl","3xl"],B={xs:475,sm:640,md:768,lg:1024,xl:1280,"2xl":1536,"3xl":1920},ge=[...S].reverse();function P(e,n){for(const t of ge){const r=e[t];if(r!==void 0&&!Number.isNaN(r)&&n>=r)return t}return"base"}function W(e=B){const[n,t]=k(P(e,window.innerWidth));return w(()=>{let r=[],l=[];const o=()=>{l.forEach(c=>c()),r=[],l=[];const i=P(e,window.innerWidth);t(i);const m=S.indexOf(i),d=S[m+1];if(d&&e[d]!==void 0){const c=e[d];if(Number.isNaN(c))throw new Error(`Invalid breakpoint value for ${d}: ${e[d]}`);{const u=window.matchMedia(`(min-width: ${c}px)`);r.push(u);const f=()=>o();u.addEventListener("change",f),l.push(()=>u.removeEventListener("change",f))}}const s=S[m-1];if(s&&e[s]!==void 0){const c=e[s];if(Number.isNaN(c))throw new Error(`Invalid breakpoint value for ${s}: ${e[s]}`);{const u=window.matchMedia(`(max-width: ${c-1}px)`);r.push(u);const f=()=>o();u.addEventListener("change",f),l.push(()=>u.removeEventListener("change",f))}}};return o(),()=>{l.forEach(i=>i())}},[e]),n}const R=G("base");function ye({children:e,breakpointDesc:n}){const t=W(n);return a.createElement(R.Provider,{value:t},e)}function Se(){return q(R)}export{se as ArrayRender,ye as BreakpointProvider,pe as Counter,ie as DateRender,B as DefBreakpointDesc,X as False,p as If,ae as Observer,te as Pipe,re as Scope,ne as SizeBox,O as Styles,y as Switch,le as Toggle,Q as True,ee as When,S as breakpoints,Y as childrenLoop,J as createExternalState,me as createStorageState,F as cx,he as formatDate,P as getCurrentBreakpoint,j as safePromiseTry,Se as useBreakpoint,de as useControlled,W as useScreen};
|
|
1
|
+
import a,{useMemo as g,Fragment as E,Children as L,isValidElement as H,cloneElement as V,useEffect as w,useState as O,useRef as k,useCallback as Z}from"react";function Y(e,n){if(e===void 0)return;let t=0;if(Array.isArray(e)){for(const r of e)if(n(r,t++)===!1)break}else n(e,t)}const z=(e,n)=>e===n,v=e=>a.createElement(a.Fragment,null,e.children);v.displayName="Switch_Case";const N=e=>a.createElement(a.Fragment,null,e.children);N.displayName="Switch_Default";const y=e=>{const{value:n,compare:t=z,children:r,strict:o=!1}=e,l=new Set;let i=null,m=null,d=!1;return Y(r,(s,c)=>{if(!a.isValidElement(s))throw new Error(`Switch Children only accepts valid React elements at index ${c}`);const u=s.type;if(u.displayName===v.displayName){const f=s.props;if(l.has(f.value))throw new Error(`Switch found duplicate Case value at index ${c}: ${JSON.stringify(f.value)}${o?" (detected in strict mode)":""}`);if(l.add(f.value),!i&&t(n,f.value)&&(i=f.children,o===!1))return!1}else if(u.displayName===N.displayName){if(d)throw new Error(`Switch can only have one Default child at index ${c}`);if(d=!0,m=s.props.children,!o&&i)return!1}else throw new Error(`Switch Children only accepts 'Case' or 'Default' elements, found: ${String(u.displayName||u.name||u)} at index ${c}`)}),a.createElement(a.Fragment,null,i??m)};y.displayName="Switch",y.Case=v,y.Default=N,y.createTyped=function(){return{Switch:y,Case:v,Default:N}};const b=e=>a.createElement(a.Fragment,null,e.children),M=({children:e})=>a.createElement(a.Fragment,null,e),x=e=>a.createElement(a.Fragment,null,e.children);b.displayName="If_Then",M.displayName="If_Else",x.displayName="If_ElseIf";const p=({condition:e,children:n})=>{let t=null,r=null;const o=[];if(a.Children.forEach(n,l=>{if(!a.isValidElement(l))throw new Error("If component only accepts valid React elements");const i=l.type;if(i.displayName===b.displayName){if(t)throw new Error("If component can only have one Then child");t=l}else if(i.displayName===x.displayName)o.push(l);else if(i.displayName===M.displayName){if(r)throw new Error("If component can only have one Else child");r=l}else throw new Error(`If component only accepts 'Then', 'ElseIf', or 'Else' elements as children, found: ${String(i.displayName||i.name||i)}`)}),e)return t?a.createElement(a.Fragment,null,t.props.children):null;for(const l of o)if(l.props.condition)return a.createElement(a.Fragment,null,l.props.children);return r?a.createElement(a.Fragment,null,r.props.children):null};p.displayName="If",p.Then=b,p.ElseIf=x,p.Else=M,p.createTyped=function(){return{If:p,Then:b,ElseIf:x,Else:M}};const U=({condition:e,children:n})=>e?a.createElement(a.Fragment,null,n):null,G=({condition:e,children:n})=>e===!1?a.createElement(a.Fragment,null,n):null,q=({all:e,any:n,none:t,children:r,fallback:o})=>g(()=>(e&&(n||t)&&console.warn('When: Multiple condition types (all, any, none) provided; "all" takes precedence.'),!!(e&&e.length>0&&e.every(Boolean)||n&&n.length>0&&n.some(Boolean)||t&&t.length>0&&t.every(l=>!l))),[e,n,t])?a.createElement(a.Fragment,null,r):a.createElement(a.Fragment,null,o||null),K=({data:e,transform:n,render:t,fallback:r})=>{const o=g(()=>n.reduce((l,i)=>i(l),e),[e,n]);return o==null?a.createElement(a.Fragment,null,r||null):a.createElement(a.Fragment,null,t(o))},Q=e=>{const{children:n,h:t,w:r,size:o,height:l,width:i,className:m}=e;return a.createElement("div",{style:{width:o||r||i,height:o||t||l,flexShrink:0},className:m},n)},X=({let:e,props:n,children:t,fallback:r})=>{const o=g(()=>typeof e=="function"?e(n):e,[e,n]);return!t||!Object.keys(o).length?a.createElement(a.Fragment,null,r||null):a.createElement(a.Fragment,null,t(o))};function F(...e){const n=new Set;for(const t of e)if(t){if(typeof t=="string")n.add(t);else if(Array.isArray(t))t.forEach(r=>n.add(r));else if(typeof t=="object")for(const[r,o]of Object.entries(t))o&&n.add(r)}return Array.from(n).join(" ")}const ee=e=>typeof e=="object"&&!!e,C=({className:e,children:n,asWrapper:t=!1})=>{if(!n)return null;if(!e)return a.createElement(E,null,n);const r=typeof e=="string"?e:F(...Object.values(e));if(t)return a.createElement(t===!0?"div":t,{className:r},n);if(L.count(n)>1)return console.error("<Styles>: children has more than one child. Please check your code."),a.createElement(E,null,n);if(H(n)){const o=n;let l=o?.props?.className;return o?.type?.displayName===C.displayName&&ee(l)&&(l=F(...Object.values(l))),V(n,{className:F(r,l)})}return console.error("<Styles>: children is not a valid React element. Please check your code."),a.createElement(E,null,n)};C.displayName="W/Styles";const te=e=>{const{index:n=0,options:t,next:r,render:o}=e;w(()=>{if(t.length<n+1)throw new Error(`Index ${n} is out of bounds for options array of length ${t.length}. Defaulting to first option.`)},[n,t]);const[l,i]=O(n),m=()=>{i(d=>t.length?r?r(d,t):(d+1)%t.length:d)};return o(t[l],m)},ne=({onIntersect:e,threshold:n=.1,root:t=null,rootMargin:r="0px",triggerOnce:o=!1,disabled:l=!1,children:i,className:m,style:d})=>{const s=k(null),c=k(null),u=k(!1);return w(()=>{if(l||!s.current)return;if(!window.IntersectionObserver){console.warn("IntersectionObserver is not supported in this browser");return}const f=s.current,h=I=>{I.forEach(D=>{o&&u.current||(e(D,c.current),o&&(u.current=!0,c.current?.unobserve(f)))})};return c.current=new IntersectionObserver(h,{root:t,rootMargin:r,threshold:n}),c.current.observe(f),()=>{c.current&&c.current.disconnect()}},[e,n,t,r,o,l]),w(()=>{o||(u.current=!1)},[o]),a.createElement("div",{ref:s,className:m,style:d},i)};function re(e){const{items:n,renderItem:t,filter:r}=e;return n?a.createElement(E,null,n.map((o,l)=>r&&!r(o)?null:t(o,l))):(console.error("ArrayRender: items is null"),null)}function le({source:e,format:n,children:t}){const r=g(()=>{if(e instanceof Date)return e;if(typeof e=="string"||typeof e=="number"){const l=new Date(e);return isNaN(l.getTime())?null:l}return null},[e]),o=g(()=>r?n?n(r):r.toLocaleString():null,[r,n]);return!o||!t?null:a.createElement(a.Fragment,null,t(o))}const oe="onChange",ae="value";function se(e){const{defaultValue:n,onBeforeChange:t,trigger:r=oe,valuePropName:o=ae,props:l}=e,i=Object.prototype.hasOwnProperty.call(l,o),[m,d]=O(n),s=i?l[o]:m,c=g(()=>l[r],[l,r]),u=Z(f=>{const h=typeof f=="function"?f(s):f;t&&t(h,s)===!1||(i||d(h),c&&c(h))},[i,t,s,c]);return[s,u]}function ie(e,...n){try{const t=e(...n);return t instanceof Promise?t:Promise.resolve(t)}catch(t){return Promise.reject(t)}}const j=typeof Promise.try=="function"?Promise.try.bind(Promise):ie;function J(e,n={}){let t=typeof e=="function"?e():e;const r=[],{sideEffect:o,transform:l}=n,i=()=>{const s=t;return l?.get?l.get(s):s},m=s=>{const c=t,u=l?.get?l.get(c):c;t=l?.set?l.set(typeof s=="function"?s(u):s):typeof s=="function"?s(u):s,r.forEach(f=>f(t)),o&&j(o,t,c).catch(f=>{console.error("Error in external state side effect, Please do it within side effects:",f)})},d=()=>{const[s,c]=a.useState(t);return a.useEffect(()=>(r.push(c),()=>{const u=r.indexOf(c);u>-1&&r.splice(u,1)}),[]),[l?.get?l.get(s):s,m]};return{get:i,set:m,use:d,useGetter:()=>{const[s]=d();return s},__listeners:r}}function ce(e,n,t){const{storageType:r="local",sideEffect:o,transform:l}=t??{},i=r==="local"?localStorage:sessionStorage;let m=n;const d=i.getItem(e);if(d)try{m=JSON.parse(d)}catch(s){console.warn(`Failed to parse ${r}Storage value for key "${e}", using initial state:`,s),m=n}return J(m,{sideEffect:s=>{i.setItem(e,JSON.stringify(s)),o?.(s)},transform:l})}function ue(e,n){const t=n||new Date,r=t.getFullYear(),o=t.getMonth()+1,l=t.getDate(),i=t.getHours(),m=t.getMinutes(),d=t.getSeconds(),s=t.getMilliseconds(),c=t.getDay(),u=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],f=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],h=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],I=["January","February","March","April","May","June","July","August","September","October","November","December"],D=f[c],A=u[c],P=o-1,B=I[P],R=h[P],_={YY:r.toString().slice(2),YYYY:r.toString(),M:o.toString(),MM:o.toString().padStart(2,"0"),MMM:R,MMMM:B,D:l.toString(),DD:l.toString().padStart(2,"0"),d:c.toString(),dd:A,ddd:A,dddd:D,H:i.toString(),HH:i.toString().padStart(2,"0"),h:(i%12).toString(),hh:(i%12).toString().padStart(2,"0"),m:m.toString(),mm:m.toString().padStart(2,"0"),s:d.toString(),ss:d.toString().padStart(2,"0"),SSS:s.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,$=>_[$])}class de{count=0;next(){return this.count++}}const S=["base","xs","sm","md","lg","xl","2xl","3xl"],W={xs:475,sm:640,md:768,lg:1024,xl:1280,"2xl":1536,"3xl":1920},fe=[...S].reverse();function T(e,n){for(const t of fe){const r=e[t];if(r!==void 0&&!Number.isNaN(r)&&n>=r)return t}return"base"}function me(e=W){const[n,t]=O(T(e,window.innerWidth));return w(()=>{let r=[],o=[];const l=()=>{o.forEach(c=>c()),r=[],o=[];const i=T(e,window.innerWidth);t(i);const m=S.indexOf(i),d=S[m+1];if(d&&e[d]!==void 0){const c=e[d];if(Number.isNaN(c))throw new Error(`Invalid breakpoint value for ${d}: ${e[d]}`);{const u=window.matchMedia(`(min-width: ${c}px)`);r.push(u);const f=()=>l();u.addEventListener("change",f),o.push(()=>u.removeEventListener("change",f))}}const s=S[m-1];if(s&&e[s]!==void 0){const c=e[s];if(Number.isNaN(c))throw new Error(`Invalid breakpoint value for ${s}: ${e[s]}`);{const u=window.matchMedia(`(max-width: ${c-1}px)`);r.push(u);const f=()=>l();u.addEventListener("change",f),o.push(()=>u.removeEventListener("change",f))}}};return l(),()=>{o.forEach(i=>i())}},[e]),n}export{re as ArrayRender,de as Counter,le as DateRender,W as DefBreakpointDesc,G as False,p as If,ne as Observer,K as Pipe,X as Scope,Q as SizeBox,C as Styles,y as Switch,te as Toggle,U as True,q as When,S as breakpoints,Y as childrenLoop,J as createExternalState,ce as createStorageState,F as cx,ue as formatDate,T as getCurrentBreakpoint,j as safePromiseTry,se as useControlled,me as useScreen};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wwog/react",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.6",
|
|
4
4
|
"description": "A practical React component library providing declarative flow control and common UI utility components to make your React code more concise and readable.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
2
|
import {
|
|
3
3
|
breakpoints,
|
|
4
4
|
DefBreakpointDesc,
|
|
@@ -97,24 +97,3 @@ export function useScreen(breakpointDesc: BreakpointDesc = DefBreakpointDesc) {
|
|
|
97
97
|
|
|
98
98
|
return currentBreakpoint;
|
|
99
99
|
}
|
|
100
|
-
|
|
101
|
-
const BreakpointContext = createContext<BreakpointName>("base");
|
|
102
|
-
|
|
103
|
-
export function BreakpointProvider({
|
|
104
|
-
children,
|
|
105
|
-
breakpointDesc,
|
|
106
|
-
}: {
|
|
107
|
-
children: React.ReactNode;
|
|
108
|
-
breakpointDesc?: BreakpointDesc;
|
|
109
|
-
}) {
|
|
110
|
-
const breakpoint = useScreen(breakpointDesc);
|
|
111
|
-
return (
|
|
112
|
-
<BreakpointContext.Provider value={breakpoint}>
|
|
113
|
-
{children}
|
|
114
|
-
</BreakpointContext.Provider>
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export function useBreakpoint() {
|
|
119
|
-
return useContext(BreakpointContext);
|
|
120
|
-
}
|