Skip to content

Commit edbaaa8

Browse files
authored
0.2.4
1 parent 1e39e09 commit edbaaa8

4 files changed

Lines changed: 40 additions & 28 deletions

File tree

index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const getRand = (a) => (a || "") + parseInt(10e8 * Math.random(), 10).toString(3
5656
isEmptyArray = value => isArray(value) && value.length===0,
5757
isEmptyObject = value => isObject(value) && value.keys.length===0,
5858

59-
isDomElem = value => typeof HTMLElement === "object" ? value instanceof HTMLElement : value && typeof value === "object" && (value.nodeType === 1||value.nodeType === 11) && typeof value.nodeName==="string",
59+
isDomElem = value => typeof Element === "object" ? value instanceof Element : typeof HTMLElement === "object" ? value instanceof HTMLElement : value && typeof value === "object" && (value.nodeType === 1||value.nodeType === 11) && typeof value.nodeName==="string",
6060
isEvent = value => value instanceof Event,
6161

6262
isReactClassCom = value => typeof value === 'function' && value.prototype && !!value.prototype.isReactComponent,
@@ -987,19 +987,21 @@ const LazyComponent = React.forwardRef(({component, _usemodule_in_design, _rende
987987
return com;
988988
}
989989
});
990-
const If = ({condition, exact, _usemodule_in_design, children, ...props} ) => {
990+
const If = ({condition, exact, _usemodule_in_design, _usemodule_lastsel, children, ...props} ) => {
991991
if(_usemodule_in_design){
992992
if(!isArray(children)) children = [children];
993-
children.unshift(React.createElement("div",null,`<If condition='${props['data-usemodule_condition']}'>`));
994-
return React.createElement("div",{style:{'font-size':'75%',border:'dashed #444 1px',padding:"4px",margin:"4px"}},children);
993+
children.unshift(React.createElement("div",{style:{'font-size':'75%',border:'dashed #444 1px',padding:"4px",margin:"4px 0",background:_usemodule_lastsel?"#fffbd4":""}},`<If condition='${props['data-usemodule_condition']}'>`));
994+
children.push(React.createElement("div",{style:{'font-size':'75%',border:'dashed #444 1px',padding:"4px",margin:"4px 0",background:_usemodule_lastsel?"#fffbd4":""}},`</If>`));
995+
return React.createElement("div", null, children );
995996
}else
996-
return exact?condition===true:condition ? utils.isArray(children)? React.Children.map(children, child => child): (children || null) : null;
997+
return (exact ? condition===true : condition) ? (utils.isArray(children)? React.Children.map(children, child => child): (children || null)) : null;
997998
}
998999
const Iterator = ({iterator, _usemodule_in_design, children, ...props} ) =>{
9991000
if(_usemodule_in_design){
10001001
if(!isArray(children)) children = [children];
1001-
children.unshift(React.createElement("div",null,`<Iterator iterator='${props['data-usemodule_iterator']}'>`));
1002-
return React.createElement("div",{style:{'font-size':'75%',border:'dashed #444 1px',padding:"4px",margin:"4px"}},children);
1002+
children.unshift(React.createElement("div",{style:{'font-size':'75%',border:'dashed #444 1px',padding:"4px 0",margin:"4px"}},`<Iterator iterator='${props['data-usemodule_iterator']}'>`));
1003+
children.push(React.createElement("div",{style:{'font-size':'75%',border:'dashed #444 1px',padding:"4px 0",margin:"4px"}},`</Iterator>`));
1004+
return React.createElement("div", null, _usemodule_lastsel ? children: children[0] );
10031005
}else
10041006
if(isArray(iterator)){
10051007
return iterator.map( item => isObject(item) ? React.Children.map(children, child => React.cloneElement(child, item)) : null );

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-hook-module",
3-
"version": "0.2.3",
3+
"version": "0.2.4",
44
"description": "A react module hook for real configurable app with stateful persistent module tree and peer-to-peer messaging mechanism",
55
"main": "index.js",
66
"scripts": {

plugin_mui.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,11 @@ const showBackdrop = (id="default", clickAway = true, style={}, transitionDurati
185185
return;
186186
}
187187
const div = getEmptyDiv();
188-
if(!style.zIndex){
189-
const useStyle = makeStyles(theme => {
188+
const theme = useTheme();
189+
if(!style.hasOwnProperty("zIndex")){
190190
style.zIndex = theme.zIndex.drawer + 1;
191-
});
192-
ReactDOM.render(React.createElement(() => {
193-
useStyle();
194-
return "";
195-
}),div);
196191
}
197-
if(!style.color){
192+
if(!style.hasOwnProperty("color")){
198193
style.color = "#fff"
199194
}
200195

plugin_router.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,33 @@ const RelativeRouter = ({ children, _usemodule_in_design }) =>{
99
const routes = [];
1010
children.forEach(child => {
1111
if(child.props && child.props.path && typeof(child.props.path)==="string"){
12-
routes.push({ path: child.props.path, element : child });
12+
routes.push({ path: child.props.path, element : React.createElement(React.Fragment,null,child.props.children) });
1313
}
1414
});
1515
return useRoutes(routes);
1616
}else{
1717
children.forEach(child => {
1818
if(child.props && Array.isArray(child.props.children)){
1919
child.props.children = child.props.children.map( c => {
20-
const { children, ...others } = c.props;
21-
return (c.props && !/^[AB]_/.test(c.props.id) && c.props.path) ? React.createElement( "div",
22-
{ ...others, style:{border:'dotted #444 1px',padding:"4px",margin:"4px",background:(c.props._usemodule_lastsel?"#fffbd4":"")}},
23-
!c.props._usemodule_lastsel
24-
? "{ path : '" + (c.props.path||"") + "', title : '" + (c.props.title||"") + "', component: <"+c.props._usemodule_vartag+">" + (children&&children.length===1&&children[0]&&children[0].type==='usemoduletext'?children[0].props.children[0]:"...") + "</"+c.props._usemodule_vartag+"> }"
25-
: c
26-
) : c;
27-
})
20+
let { children, ...others } = c.props;
21+
if (others && !/^[AB]_/.test(others.id) && others.path){
22+
if(!Array.isArray(children)) children = [children];
23+
children.unshift(React.createElement("div",
24+
{style:{'font-size':'75%',border:'dashed #444 1px',padding:"4px",margin:"4px 0",background:others._usemodule_lastsel?"#fffbd4":""}},
25+
"{ path : '" + (others.path||"") + "', title : '" + (others.title||"") + "', component: <"+others._usemodule_vartag+">" + (children&&children.length===1&&children[0]&&children[0].type==='usemoduletext'?children[0].props.children[0]:"...") + "</"+others._usemodule_vartag+"> }"
26+
));
27+
return React.createElement( "div", others, others._usemodule_lastsel ? children: children[0] );
28+
}else{
29+
return c;
2830
}
2931
});
30-
return React.createElement("div", {style:{"font-size":"75%",border:'dashed #444 1px',padding:"4px",margin:"4px"}}, children);
32+
}
33+
});
34+
return React.createElement("div", null, children);
3135
}
3236
};
37+
RelativeRouter._usemodule_nowrap = 1;
38+
RelativeRouter._usemodule_nostyle = 1;
3339

3440
const useRouter = () => {
3541
const params = useParams();
@@ -38,15 +44,24 @@ const useRouter = () => {
3844
const navigate = useNavigate();
3945

4046
return React.useMemo(() => {
41-
return { params, searchParams, setSearchParams, location, navigate, replace: route=>navigate(route, {replace: true}) };
47+
return { params, searchParams, setSearchParams, location, navigate,
48+
pathname: location.pathname,
49+
relativePath: "/" + params["*"].split("/").pop(),
50+
query: {
51+
...useModule.utils.getURLParams(location.search),
52+
...params
53+
},
54+
push: route=>navigate(route),
55+
replace: route=>navigate(route, {replace: true})
56+
};
4257
}, [params, searchParams, setSearchParams, location, navigate ]);
4358
};
4459

4560
useModule.statePlugIn("router", module => {
4661
const opt = module.options;
4762
if(opt.props && opt.props.router){
4863
return opt._usemodule_in_design
49-
? { params:{}, searchParams:{},setSearchParams:(searchParams)=>{}, location:{hash: "",key: "default",pathname: "/",search: "",state: null}, navigate:(route, option)=>{}, replace:(route)=>{} }
64+
? { params:{}, searchParams:{},setSearchParams:(searchParams)=>{}, location:{hash: "",key: "default",pathname: "/",search: "",state: null}, pathname:"/", relativePath:"/", query:{"*":"/"}, navigate:(route, option)=>{}, push:(route)=>{}, replace:(route)=>{} }
5065
: useRouter();
5166
}
5267
});

0 commit comments

Comments
 (0)