react-shared-states 1.0.0
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/.editorconfig +9 -0
- package/CODE_OF_CONDUCT.md +128 -0
- package/CONTRIBUTING.md +112 -0
- package/LICENSE +21 -0
- package/README.md +359 -0
- package/assets/banner.png +0 -0
- package/dist/SharedData.d.ts +25 -0
- package/dist/context/SharedStatesContext.d.ts +11 -0
- package/dist/context/index.d.ts +1 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/use-shared-function.d.ts +29 -0
- package/dist/hooks/use-shared-state.d.ts +17 -0
- package/dist/hooks/use-shared.d.ts +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/main.js +820 -0
- package/dist/main.min.js +37 -0
- package/dist/types.d.ts +6 -0
- package/package.json +50 -0
- package/pnpm-workspace.yaml +2 -0
- package/vite.config.ts +45 -0
package/dist/main.min.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* react-shared-states v1.0.0
|
|
3
|
+
* (c) Hichem Taboukouyout
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
* Github: github.com/HichemTab-tech/react-shared-states
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
(function(P,C){typeof exports=="object"&&typeof module<"u"?C(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],C):(P=typeof globalThis<"u"?globalThis:P||self,C(P.ReactSharedStates={},P.React))})(this,function(P,C){"use strict";var $={exports:{}},Y={};/**
|
|
9
|
+
* @license React
|
|
10
|
+
* react-jsx-runtime.production.min.js
|
|
11
|
+
*
|
|
12
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
13
|
+
*
|
|
14
|
+
* This source code is licensed under the MIT license found in the
|
|
15
|
+
* LICENSE file in the root directory of this source tree.
|
|
16
|
+
*/var te;function Le(){if(te)return Y;te=1;var l=C,t=Symbol.for("react.element"),i=Symbol.for("react.fragment"),a=Object.prototype.hasOwnProperty,E=l.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,j={key:!0,ref:!0,__self:!0,__source:!0};function p(T,d,S){var x,w={},F=null,B=null;S!==void 0&&(F=""+S),d.key!==void 0&&(F=""+d.key),d.ref!==void 0&&(B=d.ref);for(x in d)a.call(d,x)&&!j.hasOwnProperty(x)&&(w[x]=d[x]);if(T&&T.defaultProps)for(x in d=T.defaultProps,d)w[x]===void 0&&(w[x]=d[x]);return{$$typeof:t,type:T,key:F,ref:B,props:w,_owner:E.current}}return Y.Fragment=i,Y.jsx=p,Y.jsxs=p,Y}var M={};/**
|
|
17
|
+
* @license React
|
|
18
|
+
* react-jsx-runtime.development.js
|
|
19
|
+
*
|
|
20
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
21
|
+
*
|
|
22
|
+
* This source code is licensed under the MIT license found in the
|
|
23
|
+
* LICENSE file in the root directory of this source tree.
|
|
24
|
+
*/var ne;function Ve(){return ne||(ne=1,process.env.NODE_ENV!=="production"&&function(){var l=C,t=Symbol.for("react.element"),i=Symbol.for("react.portal"),a=Symbol.for("react.fragment"),E=Symbol.for("react.strict_mode"),j=Symbol.for("react.profiler"),p=Symbol.for("react.provider"),T=Symbol.for("react.context"),d=Symbol.for("react.forward_ref"),S=Symbol.for("react.suspense"),x=Symbol.for("react.suspense_list"),w=Symbol.for("react.memo"),F=Symbol.for("react.lazy"),B=Symbol.for("react.offscreen"),se=Symbol.iterator,Ge="@@iterator";function ze(e){if(e===null||typeof e!="object")return null;var r=se&&e[se]||e[Ge];return typeof r=="function"?r:null}var I=l.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function R(e){{for(var r=arguments.length,n=new Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];Xe("error",e,n)}}function Xe(e,r,n){{var o=I.ReactDebugCurrentFrame,f=o.getStackAddendum();f!==""&&(r+="%s",n=n.concat([f]));var c=n.map(function(u){return String(u)});c.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,c)}}var qe=!1,He=!1,Ze=!1,Qe=!1,er=!1,ue;ue=Symbol.for("react.module.reference");function rr(e){return!!(typeof e=="string"||typeof e=="function"||e===a||e===j||er||e===E||e===S||e===x||Qe||e===B||qe||He||Ze||typeof e=="object"&&e!==null&&(e.$$typeof===F||e.$$typeof===w||e.$$typeof===p||e.$$typeof===T||e.$$typeof===d||e.$$typeof===ue||e.getModuleId!==void 0))}function tr(e,r,n){var o=e.displayName;if(o)return o;var f=r.displayName||r.name||"";return f!==""?n+"("+f+")":n}function le(e){return e.displayName||"Context"}function A(e){if(e==null)return null;if(typeof e.tag=="number"&&R("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case a:return"Fragment";case i:return"Portal";case j:return"Profiler";case E:return"StrictMode";case S:return"Suspense";case x:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case T:var r=e;return le(r)+".Consumer";case p:var n=e;return le(n._context)+".Provider";case d:return tr(e,e.render,"ForwardRef");case w:var o=e.displayName||null;return o!==null?o:A(e.type)||"Memo";case F:{var f=e,c=f._payload,u=f._init;try{return A(u(c))}catch{return null}}}return null}var L=Object.assign,k=0,fe,ce,de,ve,pe,ge,he;function be(){}be.__reactDisabledLog=!0;function nr(){{if(k===0){fe=console.log,ce=console.info,de=console.warn,ve=console.error,pe=console.group,ge=console.groupCollapsed,he=console.groupEnd;var e={configurable:!0,enumerable:!0,value:be,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}k++}}function ar(){{if(k--,k===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:L({},e,{value:fe}),info:L({},e,{value:ce}),warn:L({},e,{value:de}),error:L({},e,{value:ve}),group:L({},e,{value:pe}),groupCollapsed:L({},e,{value:ge}),groupEnd:L({},e,{value:he})})}k<0&&R("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var z=I.ReactCurrentDispatcher,X;function J(e,r,n){{if(X===void 0)try{throw Error()}catch(f){var o=f.stack.trim().match(/\n( *(at )?)/);X=o&&o[1]||""}return`
|
|
25
|
+
`+X+e}}var q=!1,N;{var ir=typeof WeakMap=="function"?WeakMap:Map;N=new ir}function Ee(e,r){if(!e||q)return"";{var n=N.get(e);if(n!==void 0)return n}var o;q=!0;var f=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var c;c=z.current,z.current=null,nr();try{if(r){var u=function(){throw Error()};if(Object.defineProperty(u.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(u,[])}catch(y){o=y}Reflect.construct(e,[],u)}else{try{u.call()}catch(y){o=y}e.call(u.prototype)}}else{try{throw Error()}catch(y){o=y}e()}}catch(y){if(y&&o&&typeof y.stack=="string"){for(var s=y.stack.split(`
|
|
26
|
+
`),_=o.stack.split(`
|
|
27
|
+
`),g=s.length-1,h=_.length-1;g>=1&&h>=0&&s[g]!==_[h];)h--;for(;g>=1&&h>=0;g--,h--)if(s[g]!==_[h]){if(g!==1||h!==1)do if(g--,h--,h<0||s[g]!==_[h]){var O=`
|
|
28
|
+
`+s[g].replace(" at new "," at ");return e.displayName&&O.includes("<anonymous>")&&(O=O.replace("<anonymous>",e.displayName)),typeof e=="function"&&N.set(e,O),O}while(g>=1&&h>=0);break}}}finally{q=!1,z.current=c,ar(),Error.prepareStackTrace=f}var W=e?e.displayName||e.name:"",V=W?J(W):"";return typeof e=="function"&&N.set(e,V),V}function or(e,r,n){return Ee(e,!1)}function sr(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function K(e,r,n){if(e==null)return"";if(typeof e=="function")return Ee(e,sr(e));if(typeof e=="string")return J(e);switch(e){case S:return J("Suspense");case x:return J("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case d:return or(e.render);case w:return K(e.type,r,n);case F:{var o=e,f=o._payload,c=o._init;try{return K(c(f),r,n)}catch{}}}return""}var U=Object.prototype.hasOwnProperty,Re={},_e=I.ReactDebugCurrentFrame;function G(e){if(e){var r=e._owner,n=K(e.type,e._source,r?r.type:null);_e.setExtraStackFrame(n)}else _e.setExtraStackFrame(null)}function ur(e,r,n,o,f){{var c=Function.call.bind(U);for(var u in e)if(c(e,u)){var s=void 0;try{if(typeof e[u]!="function"){var _=Error((o||"React class")+": "+n+" type `"+u+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[u]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw _.name="Invariant Violation",_}s=e[u](r,u,o,n,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(g){s=g}s&&!(s instanceof Error)&&(G(f),R("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",o||"React class",n,u,typeof s),G(null)),s instanceof Error&&!(s.message in Re)&&(Re[s.message]=!0,G(f),R("Failed %s type: %s",n,s.message),G(null))}}}var lr=Array.isArray;function H(e){return lr(e)}function fr(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,n=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return n}}function cr(e){try{return me(e),!1}catch{return!0}}function me(e){return""+e}function Se(e){if(cr(e))return R("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",fr(e)),me(e)}var ye=I.ReactCurrentOwner,dr={key:!0,ref:!0,__self:!0,__source:!0},xe,Te;function vr(e){if(U.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function pr(e){if(U.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function gr(e,r){typeof e.ref=="string"&&ye.current}function hr(e,r){{var n=function(){xe||(xe=!0,R("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}}function br(e,r){{var n=function(){Te||(Te=!0,R("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};n.isReactWarning=!0,Object.defineProperty(e,"ref",{get:n,configurable:!0})}}var Er=function(e,r,n,o,f,c,u){var s={$$typeof:t,type:e,key:r,ref:n,props:u,_owner:c};return s._store={},Object.defineProperty(s._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(s,"_self",{configurable:!1,enumerable:!1,writable:!1,value:o}),Object.defineProperty(s,"_source",{configurable:!1,enumerable:!1,writable:!1,value:f}),Object.freeze&&(Object.freeze(s.props),Object.freeze(s)),s};function Rr(e,r,n,o,f){{var c,u={},s=null,_=null;n!==void 0&&(Se(n),s=""+n),pr(r)&&(Se(r.key),s=""+r.key),vr(r)&&(_=r.ref,gr(r,f));for(c in r)U.call(r,c)&&!dr.hasOwnProperty(c)&&(u[c]=r[c]);if(e&&e.defaultProps){var g=e.defaultProps;for(c in g)u[c]===void 0&&(u[c]=g[c])}if(s||_){var h=typeof e=="function"?e.displayName||e.name||"Unknown":e;s&&hr(u,h),_&&br(u,h)}return Er(e,s,_,f,o,ye.current,u)}}var Z=I.ReactCurrentOwner,Oe=I.ReactDebugCurrentFrame;function D(e){if(e){var r=e._owner,n=K(e.type,e._source,r?r.type:null);Oe.setExtraStackFrame(n)}else Oe.setExtraStackFrame(null)}var Q;Q=!1;function ee(e){return typeof e=="object"&&e!==null&&e.$$typeof===t}function Pe(){{if(Z.current){var e=A(Z.current.type);if(e)return`
|
|
29
|
+
|
|
30
|
+
Check the render method of \``+e+"`."}return""}}function _r(e){return""}var Ce={};function mr(e){{var r=Pe();if(!r){var n=typeof e=="string"?e:e.displayName||e.name;n&&(r=`
|
|
31
|
+
|
|
32
|
+
Check the top-level render call using <`+n+">.")}return r}}function we(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var n=mr(r);if(Ce[n])return;Ce[n]=!0;var o="";e&&e._owner&&e._owner!==Z.current&&(o=" It was passed a child from "+A(e._owner.type)+"."),D(e),R('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',n,o),D(null)}}function je(e,r){{if(typeof e!="object")return;if(H(e))for(var n=0;n<e.length;n++){var o=e[n];ee(o)&&we(o,r)}else if(ee(e))e._store&&(e._store.validated=!0);else if(e){var f=ze(e);if(typeof f=="function"&&f!==e.entries)for(var c=f.call(e),u;!(u=c.next()).done;)ee(u.value)&&we(u.value,r)}}}function Sr(e){{var r=e.type;if(r==null||typeof r=="string")return;var n;if(typeof r=="function")n=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===d||r.$$typeof===w))n=r.propTypes;else return;if(n){var o=A(r);ur(n,e.props,"prop",o,e)}else if(r.PropTypes!==void 0&&!Q){Q=!0;var f=A(r);R("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",f||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&R("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function yr(e){{for(var r=Object.keys(e.props),n=0;n<r.length;n++){var o=r[n];if(o!=="children"&&o!=="key"){D(e),R("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",o),D(null);break}}e.ref!==null&&(D(e),R("Invalid attribute `ref` supplied to `React.Fragment`."),D(null))}}var Ae={};function Fe(e,r,n,o,f,c){{var u=rr(e);if(!u){var s="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(s+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var _=_r();_?s+=_:s+=Pe();var g;e===null?g="null":H(e)?g="array":e!==void 0&&e.$$typeof===t?(g="<"+(A(e.type)||"Unknown")+" />",s=" Did you accidentally export a JSX literal instead of a component?"):g=typeof e,R("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",g,s)}var h=Rr(e,r,n,f,c);if(h==null)return h;if(u){var O=r.children;if(O!==void 0)if(o)if(H(O)){for(var W=0;W<O.length;W++)je(O[W],e);Object.freeze&&Object.freeze(O)}else R("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else je(O,e)}if(U.call(r,"key")){var V=A(e),y=Object.keys(r).filter(function(wr){return wr!=="key"}),re=y.length>0?"{key: someKey, "+y.join(": ..., ")+": ...}":"{key: someKey}";if(!Ae[V+re]){var Cr=y.length>0?"{"+y.join(": ..., ")+": ...}":"{}";R(`A props object containing a "key" prop is being spread into JSX:
|
|
33
|
+
let props = %s;
|
|
34
|
+
<%s {...props} />
|
|
35
|
+
React keys must be passed directly to JSX without using spread:
|
|
36
|
+
let props = %s;
|
|
37
|
+
<%s key={someKey} {...props} />`,re,V,Cr,V),Ae[V+re]=!0}}return e===a?yr(h):Sr(h),h}}function xr(e,r,n){return Fe(e,r,n,!0)}function Tr(e,r,n){return Fe(e,r,n,!1)}var Or=Tr,Pr=xr;M.Fragment=a,M.jsx=Or,M.jsxs=Pr}()),M}var ae;function Ie(){return ae||(ae=1,process.env.NODE_ENV==="production"?$.exports=Le():$.exports=Ve()),$.exports}var De=Ie();const ie=C.createContext(void 0),We=({children:l,scopeName:t})=>(t||(t=C.useMemo(()=>Math.random().toString(36).substring(2,15),[])),De.jsx(ie.Provider,{value:{scopeName:t},children:l})),Ye=()=>C.useContext(ie);class v{data=new Map;defaultValue(){return{}}addListener(t,i,a){this.data.has(v.prefix(t,i))||this.data.set(v.prefix(t,i),{...this.defaultValue,listeners:[]}),this.data.get(v.prefix(t,i)).listeners.push(a)}removeListener(t,i,a){this.data.has(v.prefix(t,i))&&(this.data.get(v.prefix(t,i)).listeners=this.data.get(v.prefix(t,i)).listeners.filter(E=>E!==a))}callListeners(t,i){this.data.has(v.prefix(t,i))&&this.data.get(v.prefix(t,i)).listeners.forEach(a=>a())}init(t,i,a){this.data.has(v.prefix(t,i))||this.data.set(v.prefix(t,i),{...a,listeners:[]})}clearAll(t=!1){t||this.data.forEach(i=>{i.listeners.forEach(a=>a())}),this.data.clear()}clear(t,i,a=!1){a||this.callListeners(t,i),this.data.delete(v.prefix(t,i))}get(t,i){let a=this.has(t,i);if(a)return this.data.get(a)}setValue(t,i,a){this.data.has(v.prefix(t,i))&&this.data.set(v.prefix(t,i),{...this.data.get(v.prefix(t,i)),...a})}has(t,i){return this.data.has(v.prefix(t,i))?v.prefix(t,i):this.data.has(v.prefix(t,"_global"))?v.prefix(t,"_global"):void 0}static prefix(t,i){return`${i}_${t}`}}const oe=l=>{const t=Ye();return{prefix:l??t?.scopeName??"_global"}};class Me extends v{defaultValue(){return{value:void 0}}init(t,i,a){super.init(t,i,{value:a})}setValue(t,i,a){super.setValue(t,i,{value:a})}}class ke{get(t,i="_global"){const a=i||"_global";return m.get(t,a)?.value}set(t,i,a="_global"){const E=a||"_global";m.setValue(t,E,{value:i})}clearAll(){m.clearAll()}clear(t,i="_global"){const a=i||"_global";m.clear(t,a)}has(t,i="_global"){const a=i||"_global";return!!m.has(t,a)}getAll(){return m.data}}const Ue=new ke,m=new Me,$e=(l,t,i)=>{const{prefix:a}=oe(i);m.init(l,a,t);const E=C.useSyncExternalStore(p=>(m.init(l,a,t),m.addListener(l,a,p),()=>{m.removeListener(l,a,p)}),()=>m.get(l,a)?.value);return[E,p=>{const T=typeof p=="function"?p(m.get(l,a)?.value):p;T!==E&&(m.setValue(l,a,T),m.callListeners(l,a))}]};class Be extends v{defaultValue(){return{fnState:{results:void 0,isLoading:!1,error:void 0}}}init(t,i){super.init(t,i,this.defaultValue())}setValue(t,i,a){super.setValue(t,i,a)}}class Je{get(t,i="_global"){const a=i||"_global";return b.get(t,a)?.fnState}set(t,i,a="_global"){const E=a||"_global";b.setValue(t,E,i)}clearAll(){b.clearAll()}clear(t,i="_global"){const a=i||"_global";b.clear(t,a)}has(t,i="_global"){const a=i||"_global";return!!b.has(t,a)}getAll(){return b.data}}const Ne=new Je,b=new Be,Ke=(l,t,i)=>{const{prefix:a}=oe(i);b.init(l,a);const E=C.useSyncExternalStore(p=>(b.init(l,a),b.addListener(l,a,p),()=>{b.removeListener(l,a,p)}),()=>b.get(l,a).fnState),j=async(p,...T)=>{const d=b.get(l,a);if(!p&&(d.fnState.isLoading||d.fnState.results!==void 0))return d.fnState;d.fnState={...d.fnState,isLoading:!0,error:void 0},console.log(b.get(l,a)?.fnState.isLoading),d.listeners.forEach(S=>S());try{const S=await t(...T);d.fnState={results:S,isLoading:!1,error:void 0}}catch(S){d.fnState={...d.fnState,isLoading:!1,error:S}}d.listeners.forEach(S=>S())};return{state:E,trigger:(...p)=>{j(!1,...p)},forceTrigger:(...p)=>{j(!0,...p)},clear:()=>{b.clear(l,a),b.init(l,a)}}};P.SharedStatesProvider=We,P.sharedFunctionsApi=Ne,P.sharedStatesApi=Ue,P.useSharedFunction=Ke,P.useSharedState=$e,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"})});
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type AFunction<R = unknown, Args extends unknown[] = unknown[]> = (...args: Args) => Promise<R> | R;
|
|
2
|
+
export type Prefix = "_global" | ({} & string);
|
|
3
|
+
export interface DataMapValue {
|
|
4
|
+
listeners: AFunction[];
|
|
5
|
+
}
|
|
6
|
+
export type NonEmptyString<T extends string> = '' extends T ? never : T;
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-shared-states",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Global state made as simple as useState, with zero config, built-in async caching, and automatic scoping.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"react",
|
|
8
|
+
"shared-states",
|
|
9
|
+
"react-states",
|
|
10
|
+
"react-store",
|
|
11
|
+
"react-shared-store",
|
|
12
|
+
"react-package",
|
|
13
|
+
"react-library"
|
|
14
|
+
],
|
|
15
|
+
"main": "dist/main.js",
|
|
16
|
+
"module": "dist/main.esm.js",
|
|
17
|
+
"types": "dist/index.d.ts",
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"react": "^18.3.1",
|
|
20
|
+
"react-dom": "^18.3.1"
|
|
21
|
+
},
|
|
22
|
+
"author": "Hichem Taboukouyout <hichem.taboukouyout@hichemtab-tech.me>",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/HichemTab-tech/react-shared-states.git"
|
|
26
|
+
},
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/HichemTab-tech/react-shared-states/issues"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/HichemTab-tech/react-shared-states#readme",
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "^24.3.0",
|
|
34
|
+
"@types/react": "^19.1.11",
|
|
35
|
+
"@types/react-dom": "^19.1.7",
|
|
36
|
+
"@vitejs/plugin-react": "^5.0.1",
|
|
37
|
+
"typescript": "^5.9.2",
|
|
38
|
+
"vite": "^7.1.3",
|
|
39
|
+
"vite-plugin-banner": "^0.8.1",
|
|
40
|
+
"vite-plugin-dts": "^4.5.4",
|
|
41
|
+
"vitest": "^3.2.4"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "vite build",
|
|
45
|
+
"test": "vitest",
|
|
46
|
+
"preview": "vite preview",
|
|
47
|
+
"dev:demo": "vite --config demo/vite.config.demo.ts",
|
|
48
|
+
"build:demo": "vite build --config demo/vite.config.demo.ts"
|
|
49
|
+
}
|
|
50
|
+
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
import banner from 'vite-plugin-banner';
|
|
3
|
+
import react from '@vitejs/plugin-react';
|
|
4
|
+
import { resolve } from 'path';
|
|
5
|
+
import dts from 'vite-plugin-dts';
|
|
6
|
+
|
|
7
|
+
const version = require('./package.json').version;
|
|
8
|
+
const bannerContent = `/*!
|
|
9
|
+
* react-shared-states v${version}
|
|
10
|
+
* (c) Hichem Taboukouyout
|
|
11
|
+
* Released under the MIT License.
|
|
12
|
+
* Github: github.com/HichemTab-tech/react-shared-states
|
|
13
|
+
*/
|
|
14
|
+
`;
|
|
15
|
+
|
|
16
|
+
export default defineConfig({
|
|
17
|
+
build: {
|
|
18
|
+
lib: {
|
|
19
|
+
entry: resolve(__dirname, 'src/index.ts'), // Library entry point
|
|
20
|
+
name: 'ReactSharedStates',
|
|
21
|
+
fileName: (format: string) => `main${format === 'es' ? '' : '.min'}.js`,
|
|
22
|
+
formats: ['es', 'umd']
|
|
23
|
+
},
|
|
24
|
+
rollupOptions: {
|
|
25
|
+
external: ['react', 'react-dom'], // Mark React, ReactDOM as external
|
|
26
|
+
output: {
|
|
27
|
+
globals: {
|
|
28
|
+
react: 'React',
|
|
29
|
+
'react-dom': 'ReactDOM'
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
plugins: [
|
|
35
|
+
react(),
|
|
36
|
+
banner(bannerContent.replace("{{VERSION}}", "")),
|
|
37
|
+
dts({
|
|
38
|
+
entryRoot: 'src', // Base folder for type generation
|
|
39
|
+
outDir: 'dist', // Ensures types go into `dist/`
|
|
40
|
+
insertTypesEntry: true, // Adds the `types` field in package.json
|
|
41
|
+
exclude: ['node_modules', 'dist'], // Exclude unnecessary files
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
]
|
|
45
|
+
});
|