New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@arancini/react

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arancini/react - npm Package Compare versions

Comparing version 4.0.2 to 4.1.0

45

dist/index.d.ts
import * as A from '@arancini/core';
import React, { ForwardedRef, PropsWithRef, ReactElement, ReactNode } from 'react';
type EntityProviderContext<Entity extends A.AnyEntity> = Entity | undefined;
export type WorldProps = {
children?: React.ReactNode;
};
type Children = ReactNode | JSX.Element;
export type EntityProps<Entity extends A.AnyEntity> = {
entity?: Entity;
children?: React.ReactNode;
children?: Children;
} & ({
[C in keyof Entity]?: Entity[C];
} | {});
export type EntitiesProps<Entity extends A.AnyEntity> = {
entities: Entity[];
children: ReactNode | ((entity: Entity) => ReactNode);
};
export type QueryEntitiesProps<E extends A.AnyEntity, QueryResult> = {
query: A.QueryDescription<E, QueryResult>;
children: ReactNode | ((entity: QueryResult) => ReactNode);
};
export type ComponentProps<E, C extends keyof E> = {
name: C;
data?: E[C];
children?: ReactNode;
value?: E[C];
children?: Children;
};
export type ECS<E extends A.AnyEntity> = ReturnType<typeof createECS<E>>;
export declare const createECS: <E extends A.AnyEntity>(world: A.World<E>) => {
Entity: <D extends E>(props: React.PropsWithRef<EntityProps<D> & {
ref?: React.ForwardedRef<D> | undefined;
export type ReactAPI<E extends A.AnyEntity> = ReturnType<typeof createReactAPI<E>>;
export declare const createReactAPI: <E extends A.AnyEntity>(world: A.World<E>) => {
Entity: <T extends E>(props: React.PropsWithRef<EntityProps<T> & {
ref?: React.ForwardedRef<T> | undefined;
}>) => ReactElement;
Entities: <T extends E>({ entities, children }: EntitiesProps<T>) => import("react/jsx-runtime").JSX.Element;
QueryEntities: <QueryResult extends E>({ query: q, children, }: QueryEntitiesProps<E, QueryResult>) => import("react/jsx-runtime").JSX.Element;
Component: <C extends keyof E>({ name, data, children, }: ComponentProps<E, C>) => React.ReactElement<any, string | React.JSXElementConstructor<any>> | null;
useQuery: <R extends E>(q: A.QueryDescription<E, R>) => A.Query<R>;
Entities: {
<T_1 extends E>(props: {
in: A.EntityContainer<T_1> | A.Query<T_1> | T_1[];
children: Children | ((entity: T_1) => Children);
}): ReactElement;
<T_2 extends E, QueryType>(props: {
where: A.QueryDescription<T_2, QueryType>;
children: Children | ((entity: QueryType) => Children);
}): ReactElement;
};
Component: <C extends keyof E>({ name, value, children, }: ComponentProps<E, C>) => React.ReactElement<any, string | React.JSXElementConstructor<any>> | null;
useCurrentEntity: () => E | undefined;
step: (delta: number) => void;
useQuery: <T_3 extends E>(query: A.QueryDescription<E, T_3> | A.Query<T_3>) => A.EntityContainer<T_3>;
world: A.World<E>;
entityContext: React.Context<EntityProviderContext<E>>;
};
export {};

@@ -10,3 +10,3 @@ import e,{useLayoutEffect as r,useEffect as t,createContext as n,memo as o,forwardRef as a,useContext as i,useState as c,useRef as s,useImperativeHandle as u,useMemo as l}from"react";import*as f from"@arancini/core";var p,y={exports:{}},d={};var v,m={};

* LICENSE file in the root directory of this source tree.
*/"production"===process.env.NODE_ENV?y.exports=function(){if(p)return d;p=1;var r=e,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,a=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function c(e,r,n){var c,s={},u=null,l=null;for(c in void 0!==n&&(u=""+n),void 0!==r.key&&(u=""+r.key),void 0!==r.ref&&(l=r.ref),r)o.call(r,c)&&!i.hasOwnProperty(c)&&(s[c]=r[c]);if(e&&e.defaultProps)for(c in r=e.defaultProps)void 0===s[c]&&(s[c]=r[c]);return{$$typeof:t,type:e,key:u,ref:l,props:s,_owner:a.current}}return d.Fragment=n,d.jsx=c,d.jsxs=c,d}():y.exports=(v||(v=1,"production"!==process.env.NODE_ENV&&function(){var r=e,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),o=Symbol.for("react.fragment"),a=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),c=Symbol.for("react.provider"),s=Symbol.for("react.context"),u=Symbol.for("react.forward_ref"),l=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),p=Symbol.for("react.memo"),y=Symbol.for("react.lazy"),d=Symbol.for("react.offscreen"),v=Symbol.iterator,g="@@iterator",b=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function h(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];!function(e,r,t){var n=b.ReactDebugCurrentFrame.getStackAddendum();""!==n&&(r+="%s",t=t.concat([n]));var o=t.map((function(e){return String(e)}));o.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,o)}("error",e,t)}var _,k=!1,w=!1,j=!1,O=!1,S=!1;function E(e){return e.displayName||"Context"}function R(e){if(null==e)return null;if("number"==typeof e.tag&&h("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof e)return e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case o:return"Fragment";case n:return"Portal";case i:return"Profiler";case a:return"StrictMode";case l:return"Suspense";case f:return"SuspenseList"}if("object"==typeof e)switch(e.$$typeof){case s:return E(e)+".Consumer";case c:return E(e._context)+".Provider";case u:return function(e,r,t){var n=e.displayName;if(n)return n;var o=r.displayName||r.name||"";return""!==o?t+"("+o+")":t}(e,e.render,"ForwardRef");case p:var r=e.displayName||null;return null!==r?r:R(e.type)||"Memo";case y:var t=e,d=t._payload,v=t._init;try{return R(v(d))}catch(e){return null}}return null}_=Symbol.for("react.module.reference");var x,P,T,C,$,N,D,F=Object.assign,I=0;function L(){}L.__reactDisabledLog=!0;var W,A=b.ReactCurrentDispatcher;function U(e,r,t){if(void 0===W)try{throw Error()}catch(e){var n=e.stack.trim().match(/\n( *(at )?)/);W=n&&n[1]||""}return"\n"+W+e}var z,M=!1,Y="function"==typeof WeakMap?WeakMap:Map;function q(e,r){if(!e||M)return"";var t,n=z.get(e);if(void 0!==n)return n;M=!0;var o,a=Error.prepareStackTrace;Error.prepareStackTrace=void 0,o=A.current,A.current=null,function(){if(0===I){x=console.log,P=console.info,T=console.warn,C=console.error,$=console.group,N=console.groupCollapsed,D=console.groupEnd;var e={configurable:!0,enumerable:!0,value:L,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}I++}();try{if(r){var i=function(){throw Error()};if(Object.defineProperty(i.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(i,[])}catch(e){t=e}Reflect.construct(e,[],i)}else{try{i.call()}catch(e){t=e}e.call(i.prototype)}}else{try{throw Error()}catch(e){t=e}e()}}catch(r){if(r&&t&&"string"==typeof r.stack){for(var c=r.stack.split("\n"),s=t.stack.split("\n"),u=c.length-1,l=s.length-1;u>=1&&l>=0&&c[u]!==s[l];)l--;for(;u>=1&&l>=0;u--,l--)if(c[u]!==s[l]){if(1!==u||1!==l)do{if(u--,--l<0||c[u]!==s[l]){var f="\n"+c[u].replace(" at new "," at ");return e.displayName&&f.includes("<anonymous>")&&(f=f.replace("<anonymous>",e.displayName)),"function"==typeof e&&z.set(e,f),f}}while(u>=1&&l>=0);break}}}finally{M=!1,A.current=o,function(){if(0==--I){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:F({},e,{value:x}),info:F({},e,{value:P}),warn:F({},e,{value:T}),error:F({},e,{value:C}),group:F({},e,{value:$}),groupCollapsed:F({},e,{value:N}),groupEnd:F({},e,{value:D})})}I<0&&h("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=a}var p=e?e.displayName||e.name:"",y=p?U(p):"";return"function"==typeof e&&z.set(e,y),y}function B(e,r,t){if(null==e)return"";if("function"==typeof e)return q(e,!(!(n=e.prototype)||!n.isReactComponent));var n;if("string"==typeof e)return U(e);switch(e){case l:return U("Suspense");case f:return U("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case u:return q(e.render,!1);case p:return B(e.type,r,t);case y:var o=e,a=o._payload,i=o._init;try{return B(i(a),r,t)}catch(e){}}return""}z=new Y;var V=Object.prototype.hasOwnProperty,Q={},H=b.ReactDebugCurrentFrame;function J(e){if(e){var r=e._owner,t=B(e.type,e._source,r?r.type:null);H.setExtraStackFrame(t)}else H.setExtraStackFrame(null)}var X=Array.isArray;function G(e){return X(e)}function K(e){return""+e}function Z(e){if(function(e){try{return K(e),!1}catch(e){return!0}}(e))return h("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(e){return"function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object"}(e)),K(e)}var ee,re,te,ne=b.ReactCurrentOwner,oe={key:!0,ref:!0,__self:!0,__source:!0};te={};var ae=function(e,r,n,o,a,i,c){var s={$$typeof:t,type:e,key:r,ref:n,props:c,_owner:i,_store:{}};return 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:a}),Object.freeze&&(Object.freeze(s.props),Object.freeze(s)),s};function ie(e,r,t,n,o){var a,i={},c=null,s=null;for(a in void 0!==t&&(Z(t),c=""+t),function(e){if(V.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return void 0!==e.key}(r)&&(Z(r.key),c=""+r.key),function(e){if(V.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return void 0!==e.ref}(r)&&(s=r.ref,function(e,r){if("string"==typeof e.ref&&ne.current&&r&&ne.current.stateNode!==r){var t=R(ne.current.type);te[t]||(h('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',R(ne.current.type),e.ref),te[t]=!0)}}(r,o)),r)V.call(r,a)&&!oe.hasOwnProperty(a)&&(i[a]=r[a]);if(e&&e.defaultProps){var u=e.defaultProps;for(a in u)void 0===i[a]&&(i[a]=u[a])}if(c||s){var l="function"==typeof e?e.displayName||e.name||"Unknown":e;c&&function(e,r){var t=function(){ee||(ee=!0,h("%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))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}(i,l),s&&function(e,r){var t=function(){re||(re=!0,h("%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))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}(i,l)}return ae(e,c,s,o,n,ne.current,i)}var ce,se=b.ReactCurrentOwner,ue=b.ReactDebugCurrentFrame;function le(e){if(e){var r=e._owner,t=B(e.type,e._source,r?r.type:null);ue.setExtraStackFrame(t)}else ue.setExtraStackFrame(null)}function fe(e){return"object"==typeof e&&null!==e&&e.$$typeof===t}function pe(){if(se.current){var e=R(se.current.type);if(e)return"\n\nCheck the render method of `"+e+"`."}return""}ce=!1;var ye={};function de(e,r){if(e._store&&!e._store.validated&&null==e.key){e._store.validated=!0;var t=function(e){var r=pe();if(!r){var t="string"==typeof e?e:e.displayName||e.name;t&&(r="\n\nCheck the top-level render call using <"+t+">.")}return r}(r);if(!ye[t]){ye[t]=!0;var n="";e&&e._owner&&e._owner!==se.current&&(n=" It was passed a child from "+R(e._owner.type)+"."),le(e),h('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),le(null)}}}function ve(e,r){if("object"==typeof e)if(G(e))for(var t=0;t<e.length;t++){var n=e[t];fe(n)&&de(n,r)}else if(fe(e))e._store&&(e._store.validated=!0);else if(e){var o=function(e){if(null===e||"object"!=typeof e)return null;var r=v&&e[v]||e[g];return"function"==typeof r?r:null}(e);if("function"==typeof o&&o!==e.entries)for(var a,i=o.call(e);!(a=i.next()).done;)fe(a.value)&&de(a.value,r)}}function me(e){var r,t=e.type;if(null!=t&&"string"!=typeof t){if("function"==typeof t)r=t.propTypes;else{if("object"!=typeof t||t.$$typeof!==u&&t.$$typeof!==p)return;r=t.propTypes}if(r){var n=R(t);!function(e,r,t,n,o){var a=Function.call.bind(V);for(var i in e)if(a(e,i)){var c=void 0;try{if("function"!=typeof e[i]){var s=Error((n||"React class")+": "+t+" type `"+i+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[i]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw s.name="Invariant Violation",s}c=e[i](r,i,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(e){c=e}!c||c instanceof Error||(J(o),h("%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).",n||"React class",t,i,typeof c),J(null)),c instanceof Error&&!(c.message in Q)&&(Q[c.message]=!0,J(o),h("Failed %s type: %s",t,c.message),J(null))}}(r,e.props,"prop",n,e)}else void 0===t.PropTypes||ce||(ce=!0,h("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",R(t)||"Unknown"));"function"!=typeof t.getDefaultProps||t.getDefaultProps.isReactClassApproved||h("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function ge(e,r,n,v,m,g){var b=function(e){return"string"==typeof e||"function"==typeof e||!!(e===o||e===i||S||e===a||e===l||e===f||O||e===d||k||w||j)||"object"==typeof e&&null!==e&&(e.$$typeof===y||e.$$typeof===p||e.$$typeof===c||e.$$typeof===s||e.$$typeof===u||e.$$typeof===_||void 0!==e.getModuleId)}(e);if(!b){var E="";(void 0===e||"object"==typeof e&&null!==e&&0===Object.keys(e).length)&&(E+=" 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 x,P=function(e){return void 0!==e?"\n\nCheck your code at "+e.fileName.replace(/^.*[\\\/]/,"")+":"+e.lineNumber+".":""}(m);E+=P||pe(),null===e?x="null":G(e)?x="array":void 0!==e&&e.$$typeof===t?(x="<"+(R(e.type)||"Unknown")+" />",E=" Did you accidentally export a JSX literal instead of a component?"):x=typeof e,h("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",x,E)}var T=ie(e,r,n,m,g);if(null==T)return T;if(b){var C=r.children;if(void 0!==C)if(v)if(G(C)){for(var $=0;$<C.length;$++)ve(C[$],e);Object.freeze&&Object.freeze(C)}else h("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 ve(C,e)}return e===o?function(e){for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if("children"!==n&&"key"!==n){le(e),h("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),le(null);break}}null!==e.ref&&(le(e),h("Invalid attribute `ref` supplied to `React.Fragment`."),le(null))}(T):me(T),T}var be=function(e,r,t){return ge(e,r,t,!1)},he=function(e,r,t){return ge(e,r,t,!0)};m.Fragment=o,m.jsx=be,m.jsxs=he}()),m);var g=y.exports;const b="undefined"!=typeof window?r:t,h=r=>{const p=n(null),y=o(a((({children:e,entity:n,...o},a)=>{const[i]=c((()=>({}))),l=n??i,[f,y]=c(!1);t((()=>{if(!r.has(l))return r.create(l),y(!0),()=>{y(!1),r.has(l)&&r.destroy(l)};y(!0)}),[l]);const d=s({});return t((()=>{const e=o,t=Object.keys(d.current).filter((r=>void 0===e[r]));return r.update(l,(r=>{for(const t in e)r[t]=e[t];for(const e of t)delete r[e];return l})),()=>{d.current=e}}),[o]),u(a,(()=>l)),g.jsx(p.Provider,{value:f?l:void 0,children:e})}))),d=({entities:e,children:t})=>g.jsx(g.Fragment,{children:e.map((e=>g.jsx(y,{entity:e,children:"function"==typeof t?t(e):t},r.id(e))))}),v=e=>{const t=l((()=>e),[]),n=l((()=>e instanceof f.Query?e:r.query(t)),[t]),[,o]=c(-1),a=()=>{o((e=>e+1))};return b((()=>(n.onEntityAdded.add(a),n.onEntityRemoved.add(a),()=>{n.onEntityAdded.remove(a),n.onEntityRemoved.remove(a)})),[]),b(a,[]),n};return{Entity:y,Entities:d,QueryEntities:({query:e,children:r})=>{const t=v(e);return g.jsx(d,{entities:[...t.entities],children:r})},Component:({name:t,data:n,children:o})=>{const[a,s]=c(null),u=i(p);if(b((()=>{if(!u)return;let e;return e=void 0!==o?a:n,r.add(u,t,e),()=>{u[t]&&r.remove(u,t)}}),[u,a,t,n]),o){const r=e.Children.only(o);return e.cloneElement(r,{ref:s})}return null},useQuery:v,useCurrentEntity:()=>{const e=i(p);return e||void 0},step:e=>{r.step(e)},world:r,entityContext:p}};export{h as createECS};
*/"production"===process.env.NODE_ENV?y.exports=function(){if(p)return d;p=1;var r=e,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,a=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function c(e,r,n){var c,s={},u=null,l=null;for(c in void 0!==n&&(u=""+n),void 0!==r.key&&(u=""+r.key),void 0!==r.ref&&(l=r.ref),r)o.call(r,c)&&!i.hasOwnProperty(c)&&(s[c]=r[c]);if(e&&e.defaultProps)for(c in r=e.defaultProps)void 0===s[c]&&(s[c]=r[c]);return{$$typeof:t,type:e,key:u,ref:l,props:s,_owner:a.current}}return d.Fragment=n,d.jsx=c,d.jsxs=c,d}():y.exports=(v||(v=1,"production"!==process.env.NODE_ENV&&function(){var r=e,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),o=Symbol.for("react.fragment"),a=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),c=Symbol.for("react.provider"),s=Symbol.for("react.context"),u=Symbol.for("react.forward_ref"),l=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),p=Symbol.for("react.memo"),y=Symbol.for("react.lazy"),d=Symbol.for("react.offscreen"),v=Symbol.iterator,h="@@iterator",g=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];!function(e,r,t){var n=g.ReactDebugCurrentFrame.getStackAddendum();""!==n&&(r+="%s",t=t.concat([n]));var o=t.map((function(e){return String(e)}));o.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,o)}("error",e,t)}var _,w=!1,k=!1,j=!1,O=!1,S=!1;function E(e){return e.displayName||"Context"}function R(e){if(null==e)return null;if("number"==typeof e.tag&&b("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof e)return e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case o:return"Fragment";case n:return"Portal";case i:return"Profiler";case a:return"StrictMode";case l:return"Suspense";case f:return"SuspenseList"}if("object"==typeof e)switch(e.$$typeof){case s:return E(e)+".Consumer";case c:return E(e._context)+".Provider";case u:return function(e,r,t){var n=e.displayName;if(n)return n;var o=r.displayName||r.name||"";return""!==o?t+"("+o+")":t}(e,e.render,"ForwardRef");case p:var r=e.displayName||null;return null!==r?r:R(e.type)||"Memo";case y:var t=e,d=t._payload,v=t._init;try{return R(v(d))}catch(e){return null}}return null}_=Symbol.for("react.module.reference");var x,P,T,$,C,N,D,F=Object.assign,I=0;function L(){}L.__reactDisabledLog=!0;var W,A=g.ReactCurrentDispatcher;function U(e,r,t){if(void 0===W)try{throw Error()}catch(e){var n=e.stack.trim().match(/\n( *(at )?)/);W=n&&n[1]||""}return"\n"+W+e}var z,M=!1,Y="function"==typeof WeakMap?WeakMap:Map;function q(e,r){if(!e||M)return"";var t,n=z.get(e);if(void 0!==n)return n;M=!0;var o,a=Error.prepareStackTrace;Error.prepareStackTrace=void 0,o=A.current,A.current=null,function(){if(0===I){x=console.log,P=console.info,T=console.warn,$=console.error,C=console.group,N=console.groupCollapsed,D=console.groupEnd;var e={configurable:!0,enumerable:!0,value:L,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}I++}();try{if(r){var i=function(){throw Error()};if(Object.defineProperty(i.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(i,[])}catch(e){t=e}Reflect.construct(e,[],i)}else{try{i.call()}catch(e){t=e}e.call(i.prototype)}}else{try{throw Error()}catch(e){t=e}e()}}catch(r){if(r&&t&&"string"==typeof r.stack){for(var c=r.stack.split("\n"),s=t.stack.split("\n"),u=c.length-1,l=s.length-1;u>=1&&l>=0&&c[u]!==s[l];)l--;for(;u>=1&&l>=0;u--,l--)if(c[u]!==s[l]){if(1!==u||1!==l)do{if(u--,--l<0||c[u]!==s[l]){var f="\n"+c[u].replace(" at new "," at ");return e.displayName&&f.includes("<anonymous>")&&(f=f.replace("<anonymous>",e.displayName)),"function"==typeof e&&z.set(e,f),f}}while(u>=1&&l>=0);break}}}finally{M=!1,A.current=o,function(){if(0==--I){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:F({},e,{value:x}),info:F({},e,{value:P}),warn:F({},e,{value:T}),error:F({},e,{value:$}),group:F({},e,{value:C}),groupCollapsed:F({},e,{value:N}),groupEnd:F({},e,{value:D})})}I<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=a}var p=e?e.displayName||e.name:"",y=p?U(p):"";return"function"==typeof e&&z.set(e,y),y}function B(e,r,t){if(null==e)return"";if("function"==typeof e)return q(e,!(!(n=e.prototype)||!n.isReactComponent));var n;if("string"==typeof e)return U(e);switch(e){case l:return U("Suspense");case f:return U("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case u:return q(e.render,!1);case p:return B(e.type,r,t);case y:var o=e,a=o._payload,i=o._init;try{return B(i(a),r,t)}catch(e){}}return""}z=new Y;var V=Object.prototype.hasOwnProperty,Q={},H=g.ReactDebugCurrentFrame;function J(e){if(e){var r=e._owner,t=B(e.type,e._source,r?r.type:null);H.setExtraStackFrame(t)}else H.setExtraStackFrame(null)}var X=Array.isArray;function G(e){return X(e)}function K(e){return""+e}function Z(e){if(function(e){try{return K(e),!1}catch(e){return!0}}(e))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(e){return"function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object"}(e)),K(e)}var ee,re,te,ne=g.ReactCurrentOwner,oe={key:!0,ref:!0,__self:!0,__source:!0};te={};var ae=function(e,r,n,o,a,i,c){var s={$$typeof:t,type:e,key:r,ref:n,props:c,_owner:i,_store:{}};return 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:a}),Object.freeze&&(Object.freeze(s.props),Object.freeze(s)),s};function ie(e,r,t,n,o){var a,i={},c=null,s=null;for(a in void 0!==t&&(Z(t),c=""+t),function(e){if(V.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return void 0!==e.key}(r)&&(Z(r.key),c=""+r.key),function(e){if(V.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return void 0!==e.ref}(r)&&(s=r.ref,function(e,r){if("string"==typeof e.ref&&ne.current&&r&&ne.current.stateNode!==r){var t=R(ne.current.type);te[t]||(b('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',R(ne.current.type),e.ref),te[t]=!0)}}(r,o)),r)V.call(r,a)&&!oe.hasOwnProperty(a)&&(i[a]=r[a]);if(e&&e.defaultProps){var u=e.defaultProps;for(a in u)void 0===i[a]&&(i[a]=u[a])}if(c||s){var l="function"==typeof e?e.displayName||e.name||"Unknown":e;c&&function(e,r){var t=function(){ee||(ee=!0,b("%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))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}(i,l),s&&function(e,r){var t=function(){re||(re=!0,b("%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))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}(i,l)}return ae(e,c,s,o,n,ne.current,i)}var ce,se=g.ReactCurrentOwner,ue=g.ReactDebugCurrentFrame;function le(e){if(e){var r=e._owner,t=B(e.type,e._source,r?r.type:null);ue.setExtraStackFrame(t)}else ue.setExtraStackFrame(null)}function fe(e){return"object"==typeof e&&null!==e&&e.$$typeof===t}function pe(){if(se.current){var e=R(se.current.type);if(e)return"\n\nCheck the render method of `"+e+"`."}return""}ce=!1;var ye={};function de(e,r){if(e._store&&!e._store.validated&&null==e.key){e._store.validated=!0;var t=function(e){var r=pe();if(!r){var t="string"==typeof e?e:e.displayName||e.name;t&&(r="\n\nCheck the top-level render call using <"+t+">.")}return r}(r);if(!ye[t]){ye[t]=!0;var n="";e&&e._owner&&e._owner!==se.current&&(n=" It was passed a child from "+R(e._owner.type)+"."),le(e),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),le(null)}}}function ve(e,r){if("object"==typeof e)if(G(e))for(var t=0;t<e.length;t++){var n=e[t];fe(n)&&de(n,r)}else if(fe(e))e._store&&(e._store.validated=!0);else if(e){var o=function(e){if(null===e||"object"!=typeof e)return null;var r=v&&e[v]||e[h];return"function"==typeof r?r:null}(e);if("function"==typeof o&&o!==e.entries)for(var a,i=o.call(e);!(a=i.next()).done;)fe(a.value)&&de(a.value,r)}}function me(e){var r,t=e.type;if(null!=t&&"string"!=typeof t){if("function"==typeof t)r=t.propTypes;else{if("object"!=typeof t||t.$$typeof!==u&&t.$$typeof!==p)return;r=t.propTypes}if(r){var n=R(t);!function(e,r,t,n,o){var a=Function.call.bind(V);for(var i in e)if(a(e,i)){var c=void 0;try{if("function"!=typeof e[i]){var s=Error((n||"React class")+": "+t+" type `"+i+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[i]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw s.name="Invariant Violation",s}c=e[i](r,i,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(e){c=e}!c||c instanceof Error||(J(o),b("%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).",n||"React class",t,i,typeof c),J(null)),c instanceof Error&&!(c.message in Q)&&(Q[c.message]=!0,J(o),b("Failed %s type: %s",t,c.message),J(null))}}(r,e.props,"prop",n,e)}else void 0===t.PropTypes||ce||(ce=!0,b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",R(t)||"Unknown"));"function"!=typeof t.getDefaultProps||t.getDefaultProps.isReactClassApproved||b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function he(e,r,n,v,m,h){var g=function(e){return"string"==typeof e||"function"==typeof e||!!(e===o||e===i||S||e===a||e===l||e===f||O||e===d||w||k||j)||"object"==typeof e&&null!==e&&(e.$$typeof===y||e.$$typeof===p||e.$$typeof===c||e.$$typeof===s||e.$$typeof===u||e.$$typeof===_||void 0!==e.getModuleId)}(e);if(!g){var E="";(void 0===e||"object"==typeof e&&null!==e&&0===Object.keys(e).length)&&(E+=" 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 x,P=function(e){return void 0!==e?"\n\nCheck your code at "+e.fileName.replace(/^.*[\\\/]/,"")+":"+e.lineNumber+".":""}(m);E+=P||pe(),null===e?x="null":G(e)?x="array":void 0!==e&&e.$$typeof===t?(x="<"+(R(e.type)||"Unknown")+" />",E=" Did you accidentally export a JSX literal instead of a component?"):x=typeof e,b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",x,E)}var T=ie(e,r,n,m,h);if(null==T)return T;if(g){var $=r.children;if(void 0!==$)if(v)if(G($)){for(var C=0;C<$.length;C++)ve($[C],e);Object.freeze&&Object.freeze($)}else b("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 ve($,e)}return e===o?function(e){for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if("children"!==n&&"key"!==n){le(e),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),le(null);break}}null!==e.ref&&(le(e),b("Invalid attribute `ref` supplied to `React.Fragment`."),le(null))}(T):me(T),T}var ge=function(e,r,t){return he(e,r,t,!1)},be=function(e,r,t){return he(e,r,t,!0)};m.Fragment=o,m.jsx=ge,m.jsxs=be}()),m);var h=y.exports;const g="undefined"!=typeof window?r:t,b=r=>{const p=n(null),y=o(a((({children:e,entity:n,...o},a)=>{const[i]=c((()=>({}))),l=n??i,[f,y]=c(!1);t((()=>{if(!r.has(l))return r.create(l),y(!0),()=>{y(!1),r.has(l)&&r.destroy(l)};y(!0)}),[l]);const d=s({});return t((()=>{const e=o,t=Object.keys(d.current).filter((r=>void 0===e[r]));return r.update(l,(r=>{for(const t in e)r[t]=e[t];for(const e of t)delete r[e];return l})),()=>{d.current=e}}),[o]),u(a,(()=>l)),h.jsx(p.Provider,{value:f?l:void 0,children:e})}))),d=e=>{const[,r]=c(-1),t=()=>{r((e=>e+1))};return g((()=>(e.onEntityAdded.add(t),e.onEntityRemoved.add(t),()=>{e.onEntityAdded.remove(t),e.onEntityRemoved.remove(t)})),[]),g(t,[]),e},v=e=>{const t=l((()=>e instanceof f.Query?e:r.query(e)),[]);return d(t)},m=({entities:e,children:t})=>h.jsx(h.Fragment,{children:e.map((e=>h.jsx(y,{entity:e,children:"function"==typeof t?t(e):t},r.id(e))))}),b=({container:e,children:r})=>{const t=d(e);return h.jsx(m,{entities:[...t.entities],children:r})},_=({queryDescription:e,children:r})=>{const t=v(e);return h.jsx(m,{entities:[...t.entities],children:r})};return{Entity:y,Entities:function(e){return e.in?"entities"in e.in?h.jsx(b,{container:e.in,children:e.children}):h.jsx(m,{entities:e.in,children:e.children}):e.where?h.jsx(_,{queryDescription:e.where,children:e.children}):null},Component:({name:t,value:n,children:o})=>{const[a,s]=c(null),u=i(p);if(g((()=>{if(!u)return;let e;return e=void 0!==o?a:n,r.add(u,t,e),()=>{u[t]&&r.remove(u,t)}}),[u,a,t,n]),o){const r=e.Children.only(o);return e.cloneElement(r,{ref:s})}return null},useCurrentEntity:()=>{const e=i(p);return e||void 0},useQuery:v,world:r}};export{b as createReactAPI};
//# sourceMappingURL=index.es.js.map

@@ -13,3 +13,3 @@ {

"license": "MIT",
"version": "4.0.2",
"version": "4.1.0",
"scripts": {

@@ -24,3 +24,3 @@ "test": "vitest run --coverage",

"dependencies": {
"@arancini/core": "4.0.2"
"@arancini/core": "4.1.0"
},

@@ -37,4 +37,4 @@ "peerDependencies": {

"@mdx-js/react": "^2.3.0",
"@react-three/drei": "^9.81.0",
"@react-three/fiber": "^8.13.7",
"@react-three/drei": "^9.88.13",
"@react-three/fiber": "^8.15.10",
"@rollup/plugin-commonjs": "^25.0.4",

@@ -53,4 +53,4 @@ "@rollup/plugin-node-resolve": "^15.0.1",

"@testing-library/react": "^14.0.0",
"@types/react": "^18.2.33",
"@types/react-dom": "^18.2.14",
"@types/react": "^18.2.36",
"@types/react-dom": "^18.2.15",
"@types/three": "^0.155.0",

@@ -57,0 +57,0 @@ "@vitejs/plugin-react": "^4.1.0",

@@ -13,7 +13,7 @@ # @arancini/react

To get started, use `createECS` to get glue components and hooks scoped to a given arancini world. Because the react glue is scoped, libraries can use @arancini/react without worrying about context conflicts.
To get started, use `createReactAPI` to get glue components and hooks scoped to a given arancini world. Because the react glue is scoped, libraries can use @arancini/react without worrying about context conflicts.
```ts
import { World } from '@arancini/core'
import { createECS } from '@arancini/react'
import { createReactAPI } from '@arancini/react'

@@ -33,3 +33,4 @@ type EntityType = {

const ECS = createECS(world)
const { Entity, Entities, Component, useQuery, step } =
createReactAPI(world)
```

@@ -42,3 +43,3 @@

```tsx
const Example = () => <ECS.Entity health={100} position={[0, 0]} />
const Example = () => <Entity health={100} position={[0, 0]} />
```

@@ -51,3 +52,3 @@

const Example = () => <ECS.Entity entity={entity} health={100} />
const Example = () => <Entity entity={entity} health={100} />
```

@@ -59,5 +60,5 @@

const Example = () => (
<ECS.Entity>
<ECS.Component name="health" data={100} />
</ECS.Entity>
<Entity>
<Component name="health" data={100} />
</Entity>
)

@@ -72,7 +73,7 @@ ```

const world = new A.World()
const ECS = createECS(world)
const ECS = createReactAPI(world)
const Example = () => (
<ECS.Entity>
<ECS.Component name="object3D">
<Entity>
<Component name="object3D">
<mesh>

@@ -82,4 +83,4 @@ <boxGeometry args={[1, 1, 1]} />

</mesh>
</ECS.Component>
</ECS.Entity>
</Component>
</Entity>
)

@@ -90,24 +91,37 @@ ```

`@arancini/react` also provides an `<Entities />` component that can be used to render a list of entities or add components to existing entities. `<Entities />` also supports [render props](https://reactjs.org/docs/render-props.html).
`@arancini/react` also provides an `<Entities />` component that can be used to render a collection of entities or add components to existing entities. `<Entities />` also supports [render props](https://reactjs.org/docs/render-props.html).
```tsx
const SimpleExample = () => (
<ECS.Entities entities={[entity1, entity2]}>{/* ... */}</ECS.Entities>
const Simple = () => (
<Entities in={[entity1, entity2]}>{/* ... */}</Entities>
)
const AddComponentToEntities = () => (
<ECS.Entities entities={[entity1, entity2]}>
<ECS.Component name="position" data={[0, 0]} />
</ECS.Entities>
<Entities in={[entity1, entity2]}>
<Component name="position" data={[0, 0]} />
</Entities>
)
const RenderProps = () => (
<ECS.Entities entities={[entity1, entity2]}>
<Entities in={[entity1, entity2]}>
{(entity) => {
// ...
}}
</ECS.Entities>
</Entities>
)
```
`Entities` also supports a `where` prop that takes a query description.
```tsx
const SimpleExample = () => (
<Entities where={(e) => e.with('exampleTag')}>
<mesh>
<boxGeometry args={[1, 1, 1]} />
<meshNormalMaterial />
</mesh>
</Entities>
)
```
## Querying the world

@@ -121,3 +135,3 @@

const Example = () => {
const entities = ECS.useQuery((e) => e.with('health'))
const entities = useQuery((e) => e.with('health'))

@@ -128,63 +142,5 @@ // ...

### `QueryEntities`
`QueryEntities` can be used to render entities, as well as enhance existing ones. It will re-render whenever the query results change. It also supports [render props](https://reactjs.org/docs/render-props.html).
```tsx
const world = new World()
const ECS = createECS(world)
const SimpleExample = () => (
<ECS.QueryEntities query={(e) => e.with('exampleTag')}>
<mesh>
<boxGeometry args={[1, 1, 1]} />
<meshNormalMaterial />
</mesh>
</ECS.QueryEntities>
)
const RenderProps = () => (
<ECS.QueryEntities query={(e) => e.with('exampleTag')}>
{(entity) => {
return (
<mesh>
<boxGeometry
position={[
(Math.random() - 0.5) * 2,
(Math.random() - 0.5) * 2,
(Math.random() - 0.5) * 2,
]}
/>
<meshNormalMaterial />
</mesh>
)
}}
</ECS.QueryEntities>
)
const EnhanceExistingEntities = () => (
<ECS.QueryEntities query={(e) => e.with('exampleTag')}>
{(entity) => {
return (
<ECS.Component name="object3D">
<mesh>
<boxGeometry
position={[
(Math.random() - 0.5) * 2,
(Math.random() - 0.5) * 2,
(Math.random() - 0.5) * 2,
]}
/>
<meshNormalMaterial />
</mesh>
</ECS.Component>
)
}}
</ECS.QueryEntities>
)
```
## Updating Systems
`@arancini/react` does not automatically update systems for you. If you are using arancini with `@react-three/fiber`, you can use the `useFrame` hook to update systems in the world.
`@arancini/react` does not automatically update systems for you. You will need to call `world.step` yourself. For example, if you are using arancini with `@react-three/fiber`, you can use the `useFrame` hook.

@@ -194,36 +150,11 @@ ```tsx

const Stepper = () => {
const Game = () => {
useFrame((_, delta) => {
ECS.step(delta)
world.step(delta)
})
return null
return (
// ...
)
}
```
## Advanced Usage
### Entity context
You can use the `useCurrentEntitiy` hook to access the current entity in a React component.
```tsx
import { Component } from '@arancini/core'
import { createECS } from '@arancini/react'
const ECS = createECS()
const Example = () => {
const entity = useCurrentEntity()
// ...
}
const App = () => (
<ECS.Entity>
<Example />
</ECS.Entity>
)
```
For extra advanced usage, `createECS` also returns the entity react context `entityContext`.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc