@wwog/react 1.1.7 → 1.1.8
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 +16 -9
- package/dist/index.d.mts +1 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/Common/SizeBox.tsx +8 -2
package/README.md
CHANGED
|
@@ -145,7 +145,7 @@ function Example({ isActive }) {
|
|
|
145
145
|
|
|
146
146
|
#### `<ArrayRender>`
|
|
147
147
|
|
|
148
|
-
|
|
148
|
+
内部仅单次循环。高效渲染数组数据的工具组件,支持过滤和自定义渲染。
|
|
149
149
|
|
|
150
150
|
```tsx
|
|
151
151
|
import { ArrayRender } from "@wwog/react";
|
|
@@ -181,8 +181,8 @@ function Example({ users }) {
|
|
|
181
181
|
<Pipe
|
|
182
182
|
data={users}
|
|
183
183
|
transform={[
|
|
184
|
-
(data) => data.filter(user => user.active),
|
|
185
|
-
(data) => data.map(user => user.name)
|
|
184
|
+
(data) => data.filter((user) => user.active),
|
|
185
|
+
(data) => data.map((user) => user.name),
|
|
186
186
|
]}
|
|
187
187
|
render={(names) => <div>{names.join(", ")}</div>}
|
|
188
188
|
fallback={<div>No Data</div>}
|
|
@@ -210,15 +210,23 @@ import { Scope } from "@wwog/react";
|
|
|
210
210
|
function Example() {
|
|
211
211
|
return (
|
|
212
212
|
<Scope let={{ count: 1, text: "Hello" }}>
|
|
213
|
-
{({ count, text }) =>
|
|
213
|
+
{({ count, text }) => (
|
|
214
|
+
<div>
|
|
215
|
+
{text} {count}
|
|
216
|
+
</div>
|
|
217
|
+
)}
|
|
214
218
|
</Scope>
|
|
215
219
|
);
|
|
216
220
|
}
|
|
217
221
|
|
|
218
222
|
// 支持函数式 let
|
|
219
|
-
<Scope
|
|
223
|
+
<Scope
|
|
224
|
+
let={(props) => ({ total: props.items.length })}
|
|
225
|
+
props={{ items: [1, 2] }}
|
|
226
|
+
fallback={<div>Empty</div>}
|
|
227
|
+
>
|
|
220
228
|
{({ total }) => <div>Total: {total}</div>}
|
|
221
|
-
</Scope
|
|
229
|
+
</Scope>;
|
|
222
230
|
```
|
|
223
231
|
|
|
224
232
|
- `let`:对象或函数,定义作用域变量。
|
|
@@ -230,6 +238,8 @@ function Example() {
|
|
|
230
238
|
|
|
231
239
|
创建固定尺寸的容器,用于布局调整和间距控制。
|
|
232
240
|
|
|
241
|
+
> v1.1.8: Fixed SizeBox not working in 'flex' layouts, add classname props
|
|
242
|
+
|
|
233
243
|
```tsx
|
|
234
244
|
import { SizeBox } from "@wwog/react";
|
|
235
245
|
|
|
@@ -261,9 +271,6 @@ function Layout() {
|
|
|
261
271
|
- Once:确保内容仅渲染一次,适合初始化。
|
|
262
272
|
- Each:增强列表渲染,支持过滤和排序。
|
|
263
273
|
|
|
264
|
-
|
|
265
274
|
## License
|
|
266
275
|
|
|
267
276
|
MIT
|
|
268
|
-
|
|
269
|
-
|
package/dist/index.d.mts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import n,{useMemo as
|
|
1
|
+
import n,{useMemo as N,Fragment as S}from"react";function v(e,l){if(e===void 0)return;let t=0;if(Array.isArray(e)){for(const a of e)if(l(a,t++)===!1)break}else l(e,t)}const I=(e,l)=>e===l,p=e=>n.createElement(n.Fragment,null,e.children);p.displayName="Switch_Case";const y=e=>n.createElement(n.Fragment,null,e.children);y.displayName="Switch_Default";const o=e=>{const{value:l,compare:t=I,children:a,strict:r=!1}=e,i=new Set;let c=null,u=null,F=!1;return v(a,(h,f)=>{if(!n.isValidElement(h))throw new Error(`Switch Children only accepts valid React elements at index ${f}`);const d=h.type;if(d.displayName===p.displayName){const m=h.props;if(i.has(m.value))throw new Error(`Switch found duplicate Case value at index ${f}: ${JSON.stringify(m.value)}${r?" (detected in strict mode)":""}`);if(i.add(m.value),!c&&t(l,m.value)&&(c=m.children,r===!1))return!1}else if(d.displayName===y.displayName){if(F)throw new Error(`Switch can only have one Default child at index ${f}`);if(F=!0,u=h.props.children,!r&&c)return!1}else throw new Error(`Switch Children only accepts 'Case' or 'Default' elements, found: ${String(d.displayName||d.name||d)} at index ${f}`)}),n.createElement(n.Fragment,null,c??u)};o.displayName="Switch",o.Case=p,o.Default=y,o.createTyped=function(){return{Switch:o,Case:p,Default:y}};const E=e=>n.createElement(n.Fragment,null,e.children),w=({children:e})=>n.createElement(n.Fragment,null,e),g=e=>n.createElement(n.Fragment,null,e.children);E.displayName="If_Then",w.displayName="If_Else",g.displayName="If_ElseIf";const s=({condition:e,children:l})=>{let t=null,a=null;const r=[];if(n.Children.forEach(l,i=>{if(!n.isValidElement(i))throw new Error("If component only accepts valid React elements");const c=i.type;if(c.displayName===E.displayName){if(t)throw new Error("If component can only have one Then child");t=i}else if(c.displayName===g.displayName)r.push(i);else if(c.displayName===w.displayName){if(a)throw new Error("If component can only have one Else child");a=i}else throw new Error(`If component only accepts 'Then', 'ElseIf', or 'Else' elements as children, found: ${String(c.displayName||c.name||c)}`)}),e)return t?n.createElement(n.Fragment,null,t.props.children):null;for(const i of r)if(i.props.condition)return n.createElement(n.Fragment,null,i.props.children);return a?n.createElement(n.Fragment,null,a.props.children):null};s.displayName="If",s.Then=E,s.ElseIf=g,s.Else=w,s.createTyped=function(){return{If:s,Then:E,ElseIf:g,Else:w}};const C=({condition:e,children:l})=>e?n.createElement(n.Fragment,null,l):null,T=({condition:e,children:l})=>e===!1?n.createElement(n.Fragment,null,l):null,k=({all:e,any:l,none:t,children:a,fallback:r})=>N(()=>(e&&(l||t)&&console.warn('When: Multiple condition types (all, any, none) provided; "all" takes precedence.'),!!(e&&e.length>0&&e.every(Boolean)||l&&l.length>0&&l.some(Boolean)||t&&t.length>0&&t.every(i=>!i))),[e,l,t])?n.createElement(n.Fragment,null,a):n.createElement(n.Fragment,null,r||null),x=({data:e,transform:l,render:t,fallback:a})=>{const r=N(()=>l.reduce((i,c)=>c(i),e),[e,l]);return r==null?n.createElement(n.Fragment,null,a||null):n.createElement(n.Fragment,null,t(r))},$=e=>{const{children:l,h:t,w:a,size:r,height:i,width:c,className:u}=e;return n.createElement("div",{style:{width:r||a||c,height:r||t||i,flexShrink:0},className:u},l)};function b(e){const{items:l,renderItem:t,filter:a}=e;return l?n.createElement(S,null,l.map((r,i)=>a&&!a(r)?null:t(r,i))):(console.error("ArrayRender: items is null"),null)}const D=({let:e,props:l,children:t,fallback:a})=>{const r=N(()=>typeof e=="function"?e(l):e,[e,l]);return!t||!Object.keys(r).length?n.createElement(n.Fragment,null,a||null):n.createElement(n.Fragment,null,t(r))};export{b as ArrayRender,T as False,s as If,x as Pipe,D as Scope,$ as SizeBox,o as Switch,C as True,k as When,v as childrenLoop};
|
package/package.json
CHANGED
package/src/Common/SizeBox.tsx
CHANGED
|
@@ -7,16 +7,22 @@ interface SizeBoxProps {
|
|
|
7
7
|
h?: number | string;
|
|
8
8
|
w?: number | string;
|
|
9
9
|
children?: ReactNode;
|
|
10
|
+
className?: string;
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
12
13
|
* @description SizeBox 组件用于设置一个固定大小的盒子
|
|
13
14
|
*/
|
|
14
15
|
export const SizeBox: FC<SizeBoxProps> = (props) => {
|
|
15
|
-
const { children, h, w, size, height, width } = props;
|
|
16
|
+
const { children, h, w, size, height, width, className } = props;
|
|
16
17
|
|
|
17
18
|
const widthValue = size || w || width;
|
|
18
19
|
const heightValue = size || h || height;
|
|
19
20
|
return (
|
|
20
|
-
<div
|
|
21
|
+
<div
|
|
22
|
+
style={{ width: widthValue, height: heightValue, flexShrink: 0 }}
|
|
23
|
+
className={className}
|
|
24
|
+
>
|
|
25
|
+
{children}
|
|
26
|
+
</div>
|
|
21
27
|
);
|
|
22
28
|
};
|