UNPKG

@quantajs/react

Version:

React integration for QuantaJS - A compact, scalable, and developer-friendly state management library for React applications.

45 lines (40 loc) 9.94 kB
/*! MIT License Copyright (c) 2025 QuantaJS Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("react"),u=require("@quantajs/core");function k(o,s){try{return p.useSyncExternalStore(o.subscribe,()=>{try{return s?s(o):o}catch(r){throw u.logger.error(`useQuantaStore: Failed to get store snapshot: ${r instanceof Error?r.message:String(r)}`),r}},()=>{try{return s?s(o):o}catch(r){throw u.logger.error(`useQuantaStore: Failed to get server snapshot: ${r instanceof Error?r.message:String(r)}`),r}})}catch(r){throw u.logger.error(`useQuantaStore: Hook execution failed: ${r instanceof Error?r.message:String(r)}`),r}}const y=p.createContext({stores:{}});function q(){try{const o=p.useContext(y);if(!o){const s="useQuantaContext must be used within a QuantaProvider";throw u.logger.error(`QuantaContext: ${s}`),new Error(s)}return o}catch(o){throw u.logger.error(`QuantaContext: Failed to access context: ${o instanceof Error?o.message:String(o)}`),o}}function ae(o,s){try{const{stores:r}=q(),f=r[o];if(!f){const n=`Store with name "${o}" does not exist in the context.`;throw u.logger.error(`useStore: ${n}`),new Error(n)}return s?k(f,s):k(f)}catch(r){throw u.logger.error(`useStore: Failed to access store "${o}": ${r instanceof Error?r.message:String(r)}`),r}}function se(o,s,r,f){try{const n=p.useRef(void 0);if(!n.current)try{n.current=u.createStore(o,{state:s,getters:r,actions:f})}catch(l){throw u.logger.error(`useCreateStore: Failed to create store "${o}": ${l instanceof Error?l.message:String(l)}`),l}return n.current}catch(n){throw u.logger.error(`useCreateStore: Hook execution failed: ${n instanceof Error?n.message:String(n)}`),n}}var _={exports:{}},v={};/** * @license React * react-jsx-runtime.production.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var D;function ue(){if(D)return v;D=1;var o=Symbol.for("react.transitional.element"),s=Symbol.for("react.fragment");function r(f,n,l){var E=null;if(l!==void 0&&(E=""+l),n.key!==void 0&&(E=""+n.key),"key"in n){l={};for(var b in n)b!=="key"&&(l[b]=n[b])}else l=n;return n=l.ref,{$$typeof:o,type:f,key:E,ref:n!==void 0?n:null,props:l}}return v.Fragment=s,v.jsx=r,v.jsxs=r,v}var R={};/** * @license React * react-jsx-runtime.development.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var L;function ce(){return L||(L=1,process.env.NODE_ENV!=="production"&&function(){function o(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===te?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case h:return"Fragment";case G:return"Profiler";case V:return"StrictMode";case Z:return"Suspense";case K:return"SuspenseList";case re:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case z:return"Portal";case H:return(e.displayName||"Context")+".Provider";case X:return(e._context.displayName||"Context")+".Consumer";case B:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case ee:return t=e.displayName||null,t!==null?t:o(e.type)||"Memo";case N:t=e._payload,e=e._init;try{return o(e(t))}catch{}}return null}function s(e){return""+e}function r(e){try{s(e);var t=!1}catch{t=!0}if(t){t=console;var a=t.error,c=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return a.call(t,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",c),s(e)}}function f(e){if(e===h)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===N)return"<...>";try{var t=o(e);return t?"<"+t+">":"<...>"}catch{return"<...>"}}function n(){var e=T.A;return e===null?null:e.getOwner()}function l(){return Error("react-stack-top-frame")}function E(e){if($.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function b(e,t){function a(){F||(F=!0,console.error("%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://react.dev/link/special-props)",t))}a.isReactWarning=!0,Object.defineProperty(e,"key",{get:a,configurable:!0})}function U(){var e=o(this.type);return Y[e]||(Y[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function J(e,t,a,c,m,d,x,P){return a=d.ref,e={$$typeof:C,type:e,key:t,props:d,_owner:m},(a!==void 0?a:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:U}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:x}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:P}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function j(e,t,a,c,m,d,x,P){var i=t.children;if(i!==void 0)if(c)if(oe(i)){for(c=0;c<i.length;c++)A(i[c]);Object.freeze&&Object.freeze(i)}else console.error("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 A(i);if($.call(t,"key")){i=o(e);var g=Object.keys(t).filter(function(ne){return ne!=="key"});c=0<g.length?"{key: someKey, "+g.join(": ..., ")+": ...}":"{key: someKey}",M[i+c]||(g=0<g.length?"{"+g.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX: let props = %s; <%s {...props} /> React keys must be passed directly to JSX without using spread: let props = %s; <%s key={someKey} {...props} />`,c,i,g,i),M[i+c]=!0)}if(i=null,a!==void 0&&(r(a),i=""+a),E(t)&&(r(t.key),i=""+t.key),"key"in t){a={};for(var O in t)O!=="key"&&(a[O]=t[O])}else a=t;return i&&b(a,typeof e=="function"?e.displayName||e.name||"Unknown":e),J(e,i,d,m,n(),a,x,P)}function A(e){typeof e=="object"&&e!==null&&e.$$typeof===C&&e._store&&(e._store.validated=1)}var S=p,C=Symbol.for("react.transitional.element"),z=Symbol.for("react.portal"),h=Symbol.for("react.fragment"),V=Symbol.for("react.strict_mode"),G=Symbol.for("react.profiler"),X=Symbol.for("react.consumer"),H=Symbol.for("react.context"),B=Symbol.for("react.forward_ref"),Z=Symbol.for("react.suspense"),K=Symbol.for("react.suspense_list"),ee=Symbol.for("react.memo"),N=Symbol.for("react.lazy"),re=Symbol.for("react.activity"),te=Symbol.for("react.client.reference"),T=S.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,$=Object.prototype.hasOwnProperty,oe=Array.isArray,w=console.createTask?console.createTask:function(){return null};S={react_stack_bottom_frame:function(e){return e()}};var F,Y={},Q=S.react_stack_bottom_frame.bind(S,l)(),I=w(f(l)),M={};R.Fragment=h,R.jsx=function(e,t,a,c,m){var d=1e4>T.recentlyCreatedOwnerStacks++;return j(e,t,a,!1,c,m,d?Error("react-stack-top-frame"):Q,d?w(f(e)):I)},R.jsxs=function(e,t,a,c,m){var d=1e4>T.recentlyCreatedOwnerStacks++;return j(e,t,a,!0,c,m,d?Error("react-stack-top-frame"):Q,d?w(f(e)):I)}}()),R}var W;function ie(){return W||(W=1,process.env.NODE_ENV==="production"?_.exports=ue():_.exports=ce()),_.exports}var le=ie();function fe({stores:o,children:s}){try{if(!o||typeof o!="object"){const r="QuantaProvider: Invalid stores prop provided";throw u.logger.error(r),new Error(r)}for(const[r,f]of Object.entries(o))if(!f||typeof f!="object"){const n=`QuantaProvider: Invalid store "${r}" provided`;throw u.logger.error(n),new Error(n)}return le.jsx(y.Provider,{value:{stores:o},children:s})}catch(r){throw u.logger.error(`QuantaProvider: Failed to render provider: ${r instanceof Error?r.message:String(r)}`),r}}Object.defineProperty(exports,"computed",{enumerable:!0,get:()=>u.computed});Object.defineProperty(exports,"createStore",{enumerable:!0,get:()=>u.createStore});Object.defineProperty(exports,"logger",{enumerable:!0,get:()=>u.logger});Object.defineProperty(exports,"reactive",{enumerable:!0,get:()=>u.reactive});Object.defineProperty(exports,"watch",{enumerable:!0,get:()=>u.watch});exports.QuantaContext=y;exports.QuantaProvider=fe;exports.useCreateStore=se;exports.useQuantaContext=q;exports.useQuantaStore=k;exports.useStore=ae;