Comparing version 0.0.2 to 1.0.0
@@ -21,88 +21,31 @@ var __defProp = Object.defineProperty; | ||
// src/store.tsx | ||
import React, { | ||
createContext, | ||
useCallback, | ||
useContext, | ||
useState | ||
} from "react"; | ||
var useStore = (initialState) => { | ||
const [modalMap, setModalMap] = useState(initialState || {}); | ||
const show = useCallback((id, props) => { | ||
setModalMap((modalMap2) => __spreadProps(__spreadValues({}, modalMap2), { | ||
[id]: { | ||
visible: true, | ||
props: props || {} | ||
} | ||
})); | ||
}, []); | ||
const hide = useCallback((id) => { | ||
setModalMap((modalMap2) => __spreadProps(__spreadValues({}, modalMap2), { | ||
[id]: { | ||
visible: false, | ||
props: {} | ||
} | ||
})); | ||
}, []); | ||
return { | ||
modalMap, | ||
// src/index.ts | ||
import React, { useRef, useState } from "react"; | ||
var useModal = () => { | ||
const [visible, setVisible] = useState(false); | ||
const args = useRef({}); | ||
const show = (props) => { | ||
args.current = props || {}; | ||
setVisible(true); | ||
}; | ||
const hide = () => { | ||
setVisible(false); | ||
}; | ||
return __spreadProps(__spreadValues({}, args.current), { | ||
visible, | ||
show, | ||
hide | ||
}; | ||
}); | ||
}; | ||
var Context = createContext(null); | ||
var Provider = (props) => { | ||
const value = useStore(props.initialState); | ||
return /* @__PURE__ */ React.createElement(Context.Provider, { | ||
value | ||
}, props.children); | ||
}; | ||
var useModal = (id) => { | ||
const context = useContext(Context); | ||
if (!context) { | ||
console.error(`useModal \u4F7F\u7528\u9519\u8BEF\uFF0C\u8BF7\u5728 Provider \u5185\u4F7F\u7528`); | ||
return {}; | ||
} | ||
const { modalMap, show, hide } = context; | ||
if (!modalMap[id]) { | ||
console.error(`model ${id} \u4E0D\u5B58\u5728`); | ||
return {}; | ||
} | ||
return { | ||
visible: modalMap[id].visible, | ||
props: modalMap[id].props, | ||
show: (props) => show(id, props), | ||
hide: () => hide(id) | ||
var createModal = (Comp) => { | ||
const Modal = () => { | ||
const modal = useModal(); | ||
Object.assign(Modal, modal); | ||
return React.createElement(Comp, modal); | ||
}; | ||
return Modal; | ||
}; | ||
// src/ukyou.tsx | ||
import React2, { | ||
cloneElement | ||
} from "react"; | ||
var Modal = (props) => { | ||
const { name, component } = props; | ||
const { visible, show, hide, props: modalProps } = useModal(name); | ||
return cloneElement(component, __spreadProps(__spreadValues({}, modalProps), { visible, show, hide })); | ||
}; | ||
var connect = (Comp, modalMap) => { | ||
const initialState = Object.keys(modalMap).reduce((all, item) => __spreadProps(__spreadValues({}, all), { | ||
[item]: { | ||
visible: false, | ||
props: {} | ||
} | ||
}), {}); | ||
return (props) => /* @__PURE__ */ React2.createElement(Provider, { | ||
initialState | ||
}, /* @__PURE__ */ React2.createElement(Comp, __spreadValues({}, props)), Object.entries(modalMap).map(([id, Component]) => { | ||
return /* @__PURE__ */ React2.createElement(Modal, { | ||
name: id, | ||
component: /* @__PURE__ */ React2.createElement(Component, null), | ||
key: id | ||
}); | ||
})); | ||
}; | ||
export { | ||
connect, | ||
createModal, | ||
useModal | ||
}; |
@@ -1,2 +0,2 @@ | ||
import React, { ComponentType, ComponentProps } from 'react'; | ||
import React from 'react'; | ||
@@ -6,18 +6,11 @@ interface PlainObject<T = any> { | ||
} | ||
declare const useModal: (id: string) => { | ||
visible?: undefined; | ||
props?: undefined; | ||
show?: undefined; | ||
hide?: undefined; | ||
} | { | ||
interface ModalProps extends PlainObject { | ||
visible: boolean; | ||
props: PlainObject<any>; | ||
show: (props: PlainObject) => void; | ||
show: (props?: PlainObject) => void; | ||
hide: () => void; | ||
}; | ||
} | ||
declare type ModalType = ModalProps | React.ComponentType; | ||
declare const useModal: () => ModalProps; | ||
declare const createModal: <T = any>(Comp: React.ComponentType<ModalProps | T>) => ModalType; | ||
declare const connect: (Comp: ComponentType, modalMap: { | ||
[key: string]: React.ComponentType<{}>; | ||
}) => (props: ComponentProps<any>) => JSX.Element; | ||
export { connect, useModal }; | ||
export { ModalProps, ModalType, PlainObject, createModal, useModal }; |
{ | ||
"name": "ukyou", | ||
"version": "0.0.2", | ||
"version": "1.0.0", | ||
"main": "dist/esm/index.js", | ||
@@ -5,0 +5,0 @@ "typings": "dist/index.d.ts", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
0
14306
62