@preact/signals-react 1.2.0 → 1.2.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @preact/signals-react
2
2
 
3
+ ## 1.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#238](https://github.com/preactjs/signals/pull/238) [`bcf4b0b`](https://github.com/preactjs/signals/commit/bcf4b0b25d774483ddafa29c2fa133c467668b8c) Thanks [@eddyw](https://github.com/eddyw)! - Fix ERR_UNSUPPORTED_DIR_IMPORT error when importing `use-sync-external-store/shim` from ESM build
8
+
3
9
  ## 1.2.0
4
10
 
5
11
  ### Minor Changes
package/dist/signals.js CHANGED
@@ -1 +1 @@
1
- var r=require("react"),n=require("react/jsx-runtime"),t=require("react/jsx-dev-runtime"),e=require("use-sync-external-store/shim"),u=require("@preact/signals-core");function o(r){return r&&"object"==typeof r&&"default"in r?r.default:r}var i=/*#__PURE__*/o(r),f=/*#__PURE__*/o(n),c=/*#__PURE__*/o(t),a=[],s=Symbol.for("react.element"),p=Symbol.for("react.memo"),l=new Map,v="function"==typeof Proxy,y={apply:function(n,t,u){var o=r.useMemo(b,a);e.useSyncExternalStore(o.subscribe,o.getSnapshot,o.getSnapshot);var i=o.updater.S();try{return n.apply(t,u)}catch(r){throw r}finally{i()}}};function x(r){return l.get(r)||function(r){if(v){var n=new Proxy(r,y);l.set(r,n);l.set(n,n);return n}var t=function(){return y.apply(r,void 0,arguments)};l.set(r,t);l.set(t,t);return t}(r)}function b(){var r,n,t=0,e=u.effect(function(){r=this});r.c=function(){t=t+1|0;if(n)n()};return{updater:r,subscribe:function(r){n=r;return function(){t=t+1|0;n=void 0;e()}},getSnapshot:function(){return t}}}function g(n){if("function"!=typeof n)return n;else return function(t,e){var o=[].slice.call(arguments,2);if("function"==typeof t&&!(t instanceof r.Component))return n.call.apply(n,[n,x(t),e].concat(o));if(t&&"object"==typeof t&&t.$$typeof===p){t.type=x(t.type);return n.call.apply(n,[n,t,e].concat(o))}if("string"==typeof t&&e)for(var i in e){var f=e[i];if("children"!==i&&f instanceof u.Signal)e[i]=f.value}return n.call.apply(n,[n,t,e].concat(o))}}var m=f,d=c;i.createElement=g(i.createElement);d.jsx&&(d.jsx=g(d.jsx));m.jsx&&(m.jsx=g(m.jsx));d.jsxs&&(d.jsxs=g(d.jsxs));m.jsxs&&(m.jsxs=g(m.jsxs));d.jsxDEV&&(d.jsxDEV=g(d.jsxDEV));m.jsxDEV&&(m.jsxDEV=g(m.jsxDEV));Object.defineProperties(u.Signal.prototype,{$$typeof:{configurable:!0,value:s},type:{configurable:!0,value:x(function(r){return r.data.value})},props:{configurable:!0,get:function(){return{data:this}}},ref:{configurable:!0,value:null}});exports.Signal=u.Signal;exports.batch=u.batch;exports.computed=u.computed;exports.effect=u.effect;exports.signal=u.signal;exports.useComputed=function(n){var t=r.useRef(n);t.current=n;return r.useMemo(function(){return u.computed(function(){return t.current()})},a)};exports.useSignal=function(n){return r.useMemo(function(){return u.signal(n)},a)};exports.useSignalEffect=function(n){var t=r.useRef(n);t.current=n;r.useEffect(function(){return u.effect(function(){return t.current()})},a)};//# sourceMappingURL=signals.js.map
1
+ var r=require("react"),n=require("react/jsx-runtime"),t=require("react/jsx-dev-runtime"),e=require("use-sync-external-store/shim/index.js"),u=require("@preact/signals-core");function o(r){return r&&"object"==typeof r&&"default"in r?r.default:r}var i=/*#__PURE__*/o(r),f=/*#__PURE__*/o(n),c=/*#__PURE__*/o(t),a=[],s=Symbol.for("react.element"),p=Symbol.for("react.memo"),l=new Map,v="function"==typeof Proxy,y={apply:function(n,t,u){var o=r.useMemo(b,a);e.useSyncExternalStore(o.subscribe,o.getSnapshot,o.getSnapshot);var i=o.updater.S();try{return n.apply(t,u)}catch(r){throw r}finally{i()}}};function x(r){return l.get(r)||function(r){if(v){var n=new Proxy(r,y);l.set(r,n);l.set(n,n);return n}var t=function(){return y.apply(r,void 0,arguments)};l.set(r,t);l.set(t,t);return t}(r)}function b(){var r,n,t=0,e=u.effect(function(){r=this});r.c=function(){t=t+1|0;if(n)n()};return{updater:r,subscribe:function(r){n=r;return function(){t=t+1|0;n=void 0;e()}},getSnapshot:function(){return t}}}function d(n){if("function"!=typeof n)return n;else return function(t,e){var o=[].slice.call(arguments,2);if("function"==typeof t&&!(t instanceof r.Component))return n.call.apply(n,[n,x(t),e].concat(o));if(t&&"object"==typeof t&&t.$$typeof===p){t.type=x(t.type);return n.call.apply(n,[n,t,e].concat(o))}if("string"==typeof t&&e)for(var i in e){var f=e[i];if("children"!==i&&f instanceof u.Signal)e[i]=f.value}return n.call.apply(n,[n,t,e].concat(o))}}var g=f,m=c;i.createElement=d(i.createElement);m.jsx&&(m.jsx=d(m.jsx));g.jsx&&(g.jsx=d(g.jsx));m.jsxs&&(m.jsxs=d(m.jsxs));g.jsxs&&(g.jsxs=d(g.jsxs));m.jsxDEV&&(m.jsxDEV=d(m.jsxDEV));g.jsxDEV&&(g.jsxDEV=d(g.jsxDEV));Object.defineProperties(u.Signal.prototype,{$$typeof:{configurable:!0,value:s},type:{configurable:!0,value:x(function(r){return r.data.value})},props:{configurable:!0,get:function(){return{data:this}}},ref:{configurable:!0,value:null}});exports.Signal=u.Signal;exports.batch=u.batch;exports.computed=u.computed;exports.effect=u.effect;exports.signal=u.signal;exports.useComputed=function(n){var t=r.useRef(n);t.current=n;return r.useMemo(function(){return u.computed(function(){return t.current()})},a)};exports.useSignal=function(n){return r.useMemo(function(){return u.signal(n)},a)};exports.useSignalEffect=function(n){var t=r.useRef(n);t.current=n;r.useEffect(function(){return u.effect(function(){return t.current()})},a)};//# sourceMappingURL=signals.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"signals.js","sources":["../src/index.ts"],"sourcesContent":["import {\n\tuseRef,\n\tuseMemo,\n\tuseEffect,\n\tComponent,\n\ttype FunctionComponent,\n} from \"react\";\nimport React from \"react\";\nimport jsxRuntime from \"react/jsx-runtime\";\nimport jsxRuntimeDev from \"react/jsx-dev-runtime\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n} from \"@preact/signals-core\";\nimport type { Effect, JsxRuntimeModule } from \"./internal\";\n\nexport { signal, computed, batch, effect, Signal, type ReadonlySignal };\n\nconst Empty = [] as const;\nconst ReactElemType = Symbol.for(\"react.element\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L15\nconst ReactMemoType = Symbol.for(\"react.memo\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L30\nconst ProxyInstance = new Map<FunctionComponent<any>, FunctionComponent<any>>();\nconst SupportsProxy = typeof Proxy === \"function\";\n\nconst ProxyHandlers = {\n\t/**\n\t * This is a function call trap for functional components.\n\t * When this is called, we know it means React did run 'Component()',\n\t * that means we can use any hooks here to setup our effect and store.\n\t *\n\t * With the native Proxy, all other calls such as access/setting to/of properties will\n\t * be forwarded to the target Component, so we don't need to copy the Component's\n\t * own or inherited properties.\n\t *\n\t * @see https://github.com/facebook/react/blob/2d80a0cd690bb5650b6c8a6c079a87b5dc42bd15/packages/react-reconciler/src/ReactFiberHooks.old.js#L460\n\t */\n\tapply(Component: FunctionComponent, thisArg: any, argumentsList: any) {\n\t\tconst store = useMemo(createEffectStore, Empty);\n\n\t\tuseSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n\n\t\tconst stop = store.updater._start();\n\n\t\ttry {\n\t\t\tconst children = Component.apply(thisArg, argumentsList);\n\t\t\treturn children;\n\t\t} catch (e) {\n\t\t\t// Re-throwing promises that'll be handled by suspense\n\t\t\t// or an actual error.\n\t\t\tthrow e;\n\t\t} finally {\n\t\t\t// Stop effects in either case before return or throw,\n\t\t\t// Otherwise the effect will leak.\n\t\t\tstop();\n\t\t}\n\t},\n};\n\nfunction ProxyFunctionalComponent(Component: FunctionComponent<any>) {\n\treturn ProxyInstance.get(Component) || WrapWithProxy(Component);\n}\nfunction WrapWithProxy(Component: FunctionComponent<any>) {\n\tif (SupportsProxy) {\n\t\tconst ProxyComponent = new Proxy(Component, ProxyHandlers);\n\n\t\tProxyInstance.set(Component, ProxyComponent);\n\t\tProxyInstance.set(ProxyComponent, ProxyComponent);\n\n\t\treturn ProxyComponent;\n\t}\n\n\t/**\n\t * Emulate a Proxy if environment doesn't support it.\n\t *\n\t * @TODO - unlike Proxy, it's not possible to access the type/Component's\n\t * static properties this way. Not sure if we want to copy all statics here.\n\t * Omitting this for now.\n\t *\n\t * @example - works with Proxy, doesn't with wrapped function.\n\t * ```\n\t * const el = <SomeFunctionalComponent />\n\t * el.type.someOwnOrInheritedProperty;\n\t * el.type.defaultProps;\n\t * ```\n\t */\n\tconst WrappedComponent = function () {\n\t\treturn ProxyHandlers.apply(Component, undefined, arguments);\n\t};\n\tProxyInstance.set(Component, WrappedComponent);\n\tProxyInstance.set(WrappedComponent, WrappedComponent);\n\n\treturn WrappedComponent;\n}\n\n/**\n * A redux-like store whose store value is a positive 32bit integer (a 'version').\n *\n * React subscribes to this store and gets a snapshot of the current 'version',\n * whenever the 'version' changes, we tell React it's time to update the component (call 'onStoreChange').\n *\n * How we achieve this is by creating a binding with an 'effect', when the `effect._callback' is called,\n * we update our store version and tell React to re-render the component ([1] We don't really care when/how React does it).\n *\n * [1]\n * @see https://reactjs.org/docs/hooks-reference.html#usesyncexternalstore\n * @see https://github.com/reactjs/rfcs/blob/main/text/0214-use-sync-external-store.md\n */\nfunction createEffectStore() {\n\tlet updater!: Effect;\n\tlet version = 0;\n\tlet onChangeNotifyReact: (() => void) | undefined;\n\n\tlet unsubscribe = effect(function (this: Effect) {\n\t\tupdater = this;\n\t});\n\tupdater._callback = function () {\n\t\tversion = (version + 1) | 0;\n\t\tif (onChangeNotifyReact) onChangeNotifyReact();\n\t};\n\n\treturn {\n\t\tupdater,\n\t\tsubscribe(onStoreChange: () => void) {\n\t\t\tonChangeNotifyReact = onStoreChange;\n\n\t\t\treturn function () {\n\t\t\t\t/**\n\t\t\t\t * Rotate to next version when unsubscribing to ensure that components are re-run\n\t\t\t\t * when subscribing again.\n\t\t\t\t *\n\t\t\t\t * In StrictMode, 'memo'-ed components seem to keep a stale snapshot version, so\n\t\t\t\t * don't re-run after subscribing again if the version is the same as last time.\n\t\t\t\t *\n\t\t\t\t * Because we unsubscribe from the effect, the version may not change. We simply\n\t\t\t\t * set a new initial version in case of stale snapshots here.\n\t\t\t\t */\n\t\t\t\tversion = (version + 1) | 0;\n\t\t\t\tonChangeNotifyReact = undefined;\n\t\t\t\tunsubscribe();\n\t\t\t};\n\t\t},\n\t\tgetSnapshot() {\n\t\t\treturn version;\n\t\t},\n\t};\n}\n\nfunction WrapJsx<T>(jsx: T): T {\n\tif (typeof jsx !== \"function\") return jsx;\n\n\treturn function (type: any, props: any, ...rest: any[]) {\n\t\tif (typeof type === \"function\" && !(type instanceof Component)) {\n\t\t\treturn jsx.call(jsx, ProxyFunctionalComponent(type), props, ...rest);\n\t\t}\n\n\t\tif (type && typeof type === \"object\" && type.$$typeof === ReactMemoType) {\n\t\t\ttype.type = ProxyFunctionalComponent(type.type);\n\t\t\treturn jsx.call(jsx, type, props, ...rest);\n\t\t}\n\n\t\tif (typeof type === \"string\" && props) {\n\t\t\tfor (let i in props) {\n\t\t\t\tlet v = props[i];\n\t\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t\tprops[i] = v.value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn jsx.call(jsx, type, props, ...rest);\n\t} as any as T;\n}\n\nconst JsxPro: JsxRuntimeModule = jsxRuntime;\nconst JsxDev: JsxRuntimeModule = jsxRuntimeDev;\n\n/**\n * createElement _may_ be called by jsx runtime as a fallback in certain cases,\n * so we need to wrap it regardless.\n *\n * The jsx exports depend on the `NODE_ENV` var to ensure the users' bundler doesn't\n * include both, so one of them will be set with `undefined` values.\n */\nReact.createElement = WrapJsx(React.createElement);\nJsxDev.jsx && /* */ (JsxDev.jsx = WrapJsx(JsxDev.jsx));\nJsxPro.jsx && /* */ (JsxPro.jsx = WrapJsx(JsxPro.jsx));\nJsxDev.jsxs && /* */ (JsxDev.jsxs = WrapJsx(JsxDev.jsxs));\nJsxPro.jsxs && /* */ (JsxPro.jsxs = WrapJsx(JsxPro.jsxs));\nJsxDev.jsxDEV && /**/ (JsxDev.jsxDEV = WrapJsx(JsxDev.jsxDEV));\nJsxPro.jsxDEV && /**/ (JsxPro.jsxDEV = WrapJsx(JsxPro.jsxDEV));\n\n/**\n * A wrapper component that renders a Signal's value directly as a Text node.\n */\nfunction Text({ data }: { data: Signal }) {\n\treturn data.value;\n}\n\n// Decorate Signals so React renders them as <Text> components.\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: ReactElemType },\n\ttype: { configurable: true, value: ProxyFunctionalComponent(Text) },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { configurable: true, value: null },\n});\n\nexport function useSignal<T>(value: T) {\n\treturn useMemo(() => signal<T>(value), Empty);\n}\n\nexport function useComputed<T>(compute: () => T) {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\treturn useMemo(() => computed<T>(() => $compute.current()), Empty);\n}\n\nexport function useSignalEffect(cb: () => void | (() => void)) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(() => {\n\t\t\treturn callback.current();\n\t\t});\n\t}, Empty);\n}\n"],"names":["Empty","Symbol","ReactMemoType","ProxyInstance","Map","SupportsProxy","Proxy","apply","Component","thisArg","argumentsList","useMemo","createEffectStore","useSyncExternalStore","store","subscribe","getSnapshot","updater","_start","e","stop","ProxyFunctionalComponent","get","ProxyComponent","ProxyHandlers","set","WrappedComponent","undefined","arguments","WrapWithProxy","onChangeNotifyReact","version","unsubscribe","effect","this","_callback","onStoreChange","WrapJsx","jsx","type","props","slice","call","rest","$$typeof","i","v","Signal","value","concat","JsxPro","jsxRuntime","JsxDev","jsxRuntimeDev","React","createElement","jsxs","jsxDEV","Object","defineProperties","prototype","configurable","ReactElemType","_ref","data","ref","exports","signalsCore","batch","computed","signal","useComputed","compute","$compute","useRef","current","useSignal","useSignalEffect","cb","callback","useEffect"],"mappings":"2SAuBWA,EAAG,KACQC,WAAW,iBACdC,EAAGD,OAAM,IAAK,cAC3BE,EAAgB,IAAIC,IACPC,EAAoB,mBAAjBC,QAEA,CAYrBC,MAZqB,SAYfC,EAA8BC,EAAcC,GACjD,MAAcC,EAAAA,QAAQC,EAAmBZ,GAEzCa,EAAoBA,qBAACC,EAAMC,UAAWD,EAAME,YAAaF,EAAME,aAE/D,MAAaF,EAAMG,QAAQC,IAE3B,IAEC,OADiBV,EAAUD,MAAME,EAASC,EAU1C,CARC,MAAOS,GAGR,MAAMA,CACN,CAPD,QAUCC,GACA,CACD,GAGF,SAASC,EAAyBb,GACjC,SAAqBc,IAAId,IAE1B,SAAuBA,GACtB,GAAIH,EAAe,CAClB,IAAMkB,EAAiB,IAAIjB,MAAME,EAAWgB,GAE5CrB,EAAcsB,IAAIjB,EAAWe,GAC7BpB,EAAcsB,IAAIF,EAAgBA,GAElC,OACAA,CAAA,CAgBD,IAAsBG,EAAG,WACxB,OAAoBF,EAACjB,MAAMC,OAAWmB,EAAWC,UACjD,EACDzB,EAAcsB,IAAIjB,EAAWkB,GAC7BvB,EAAcsB,IAAIC,EAAkBA,GAEpC,OAAOA,CACP,CAjCuCG,CAAcrB,EACrD,CA+CD,SAASI,IACR,IAAAK,EAEAa,EADIC,EAAU,EAGCC,EAAGC,SAAO,WACxBhB,EAAUiB,IACV,GACDjB,EAAQkB,EAAY,WACnBJ,EAAWA,EAAU,EAAK,EAC1B,GAAID,EAAqBA,GACzB,EAED,MAAO,CACNb,QAAAA,EACAF,UAAUqB,SAAAA,GACTN,E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AU,CAAEiB,cAAc,EAAMb,MAAOc,GACvCvB,KAAM,CAAEsB,cAAc,EAAMb,MAAO3B,EAPpC,SAAA0C,GACC,OADuCA,EAAxBC,KACHhB,KACZ,IAMAR,MAAO,CACNqB,cAAc,EACdvC,eACC,MAAO,CAAE0C,KAAM9B,KACf,GAEF+B,IAAK,CAAEJ,cAAc,EAAMb,MAAO,QAsBlCkB,QAAAnB,OAAAoB,EAAApB,OAAAmB,QAAAE,MAAAD,EAAAC,MAAAF,QAAAG,SAAAF,EAAAE,SAAAH,QAAAjC,OAAAkC,EAAAlC,OAAAiC,QAAAI,OAAAH,EAAAG,OAAAJ,QAAAK,YAfK,SAAyBC,GAC9B,IAAcC,EAAGC,EAAMA,OAACF,GACxBC,EAASE,QAAUH,EACnB,OAAO7D,UAAQ,WAAM0D,OAAAA,EAAAA,SAAY,WAAA,OAAcI,EAACE,SAAf,EAAlB,EAA6C3E,EAC5D,EAWAkE,QAAAU,UAnBK,SAAuB5B,GAC5B,SAAcrC,QAAC,WAAA,gBAAgBqC,EAAhB,EAAwBhD,EACvC,EAiBAkE,QAAAW,gBATeA,SAAgBC,GAC/B,IAAMC,EAAWL,EAAMA,OAACI,GACxBC,EAASJ,QAAUG,EAEnBE,EAAAA,UAAU,WACT,OAAO/C,EAAAA,OAAO,WACb,OAAO8C,EAASJ,SAChB,EACD,EAAE3E,EACH"}
1
+ {"version":3,"file":"signals.js","sources":["../src/index.ts"],"sourcesContent":["import {\n\tuseRef,\n\tuseMemo,\n\tuseEffect,\n\tComponent,\n\ttype FunctionComponent,\n} from \"react\";\nimport React from \"react\";\nimport jsxRuntime from \"react/jsx-runtime\";\nimport jsxRuntimeDev from \"react/jsx-dev-runtime\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n} from \"@preact/signals-core\";\nimport type { Effect, JsxRuntimeModule } from \"./internal\";\n\nexport { signal, computed, batch, effect, Signal, type ReadonlySignal };\n\nconst Empty = [] as const;\nconst ReactElemType = Symbol.for(\"react.element\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L15\nconst ReactMemoType = Symbol.for(\"react.memo\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L30\nconst ProxyInstance = new Map<FunctionComponent<any>, FunctionComponent<any>>();\nconst SupportsProxy = typeof Proxy === \"function\";\n\nconst ProxyHandlers = {\n\t/**\n\t * This is a function call trap for functional components.\n\t * When this is called, we know it means React did run 'Component()',\n\t * that means we can use any hooks here to setup our effect and store.\n\t *\n\t * With the native Proxy, all other calls such as access/setting to/of properties will\n\t * be forwarded to the target Component, so we don't need to copy the Component's\n\t * own or inherited properties.\n\t *\n\t * @see https://github.com/facebook/react/blob/2d80a0cd690bb5650b6c8a6c079a87b5dc42bd15/packages/react-reconciler/src/ReactFiberHooks.old.js#L460\n\t */\n\tapply(Component: FunctionComponent, thisArg: any, argumentsList: any) {\n\t\tconst store = useMemo(createEffectStore, Empty);\n\n\t\tuseSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n\n\t\tconst stop = store.updater._start();\n\n\t\ttry {\n\t\t\tconst children = Component.apply(thisArg, argumentsList);\n\t\t\treturn children;\n\t\t} catch (e) {\n\t\t\t// Re-throwing promises that'll be handled by suspense\n\t\t\t// or an actual error.\n\t\t\tthrow e;\n\t\t} finally {\n\t\t\t// Stop effects in either case before return or throw,\n\t\t\t// Otherwise the effect will leak.\n\t\t\tstop();\n\t\t}\n\t},\n};\n\nfunction ProxyFunctionalComponent(Component: FunctionComponent<any>) {\n\treturn ProxyInstance.get(Component) || WrapWithProxy(Component);\n}\nfunction WrapWithProxy(Component: FunctionComponent<any>) {\n\tif (SupportsProxy) {\n\t\tconst ProxyComponent = new Proxy(Component, ProxyHandlers);\n\n\t\tProxyInstance.set(Component, ProxyComponent);\n\t\tProxyInstance.set(ProxyComponent, ProxyComponent);\n\n\t\treturn ProxyComponent;\n\t}\n\n\t/**\n\t * Emulate a Proxy if environment doesn't support it.\n\t *\n\t * @TODO - unlike Proxy, it's not possible to access the type/Component's\n\t * static properties this way. Not sure if we want to copy all statics here.\n\t * Omitting this for now.\n\t *\n\t * @example - works with Proxy, doesn't with wrapped function.\n\t * ```\n\t * const el = <SomeFunctionalComponent />\n\t * el.type.someOwnOrInheritedProperty;\n\t * el.type.defaultProps;\n\t * ```\n\t */\n\tconst WrappedComponent = function () {\n\t\treturn ProxyHandlers.apply(Component, undefined, arguments);\n\t};\n\tProxyInstance.set(Component, WrappedComponent);\n\tProxyInstance.set(WrappedComponent, WrappedComponent);\n\n\treturn WrappedComponent;\n}\n\n/**\n * A redux-like store whose store value is a positive 32bit integer (a 'version').\n *\n * React subscribes to this store and gets a snapshot of the current 'version',\n * whenever the 'version' changes, we tell React it's time to update the component (call 'onStoreChange').\n *\n * How we achieve this is by creating a binding with an 'effect', when the `effect._callback' is called,\n * we update our store version and tell React to re-render the component ([1] We don't really care when/how React does it).\n *\n * [1]\n * @see https://reactjs.org/docs/hooks-reference.html#usesyncexternalstore\n * @see https://github.com/reactjs/rfcs/blob/main/text/0214-use-sync-external-store.md\n */\nfunction createEffectStore() {\n\tlet updater!: Effect;\n\tlet version = 0;\n\tlet onChangeNotifyReact: (() => void) | undefined;\n\n\tlet unsubscribe = effect(function (this: Effect) {\n\t\tupdater = this;\n\t});\n\tupdater._callback = function () {\n\t\tversion = (version + 1) | 0;\n\t\tif (onChangeNotifyReact) onChangeNotifyReact();\n\t};\n\n\treturn {\n\t\tupdater,\n\t\tsubscribe(onStoreChange: () => void) {\n\t\t\tonChangeNotifyReact = onStoreChange;\n\n\t\t\treturn function () {\n\t\t\t\t/**\n\t\t\t\t * Rotate to next version when unsubscribing to ensure that components are re-run\n\t\t\t\t * when subscribing again.\n\t\t\t\t *\n\t\t\t\t * In StrictMode, 'memo'-ed components seem to keep a stale snapshot version, so\n\t\t\t\t * don't re-run after subscribing again if the version is the same as last time.\n\t\t\t\t *\n\t\t\t\t * Because we unsubscribe from the effect, the version may not change. We simply\n\t\t\t\t * set a new initial version in case of stale snapshots here.\n\t\t\t\t */\n\t\t\t\tversion = (version + 1) | 0;\n\t\t\t\tonChangeNotifyReact = undefined;\n\t\t\t\tunsubscribe();\n\t\t\t};\n\t\t},\n\t\tgetSnapshot() {\n\t\t\treturn version;\n\t\t},\n\t};\n}\n\nfunction WrapJsx<T>(jsx: T): T {\n\tif (typeof jsx !== \"function\") return jsx;\n\n\treturn function (type: any, props: any, ...rest: any[]) {\n\t\tif (typeof type === \"function\" && !(type instanceof Component)) {\n\t\t\treturn jsx.call(jsx, ProxyFunctionalComponent(type), props, ...rest);\n\t\t}\n\n\t\tif (type && typeof type === \"object\" && type.$$typeof === ReactMemoType) {\n\t\t\ttype.type = ProxyFunctionalComponent(type.type);\n\t\t\treturn jsx.call(jsx, type, props, ...rest);\n\t\t}\n\n\t\tif (typeof type === \"string\" && props) {\n\t\t\tfor (let i in props) {\n\t\t\t\tlet v = props[i];\n\t\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t\tprops[i] = v.value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn jsx.call(jsx, type, props, ...rest);\n\t} as any as T;\n}\n\nconst JsxPro: JsxRuntimeModule = jsxRuntime;\nconst JsxDev: JsxRuntimeModule = jsxRuntimeDev;\n\n/**\n * createElement _may_ be called by jsx runtime as a fallback in certain cases,\n * so we need to wrap it regardless.\n *\n * The jsx exports depend on the `NODE_ENV` var to ensure the users' bundler doesn't\n * include both, so one of them will be set with `undefined` values.\n */\nReact.createElement = WrapJsx(React.createElement);\nJsxDev.jsx && /* */ (JsxDev.jsx = WrapJsx(JsxDev.jsx));\nJsxPro.jsx && /* */ (JsxPro.jsx = WrapJsx(JsxPro.jsx));\nJsxDev.jsxs && /* */ (JsxDev.jsxs = WrapJsx(JsxDev.jsxs));\nJsxPro.jsxs && /* */ (JsxPro.jsxs = WrapJsx(JsxPro.jsxs));\nJsxDev.jsxDEV && /**/ (JsxDev.jsxDEV = WrapJsx(JsxDev.jsxDEV));\nJsxPro.jsxDEV && /**/ (JsxPro.jsxDEV = WrapJsx(JsxPro.jsxDEV));\n\n/**\n * A wrapper component that renders a Signal's value directly as a Text node.\n */\nfunction Text({ data }: { data: Signal }) {\n\treturn data.value;\n}\n\n// Decorate Signals so React renders them as <Text> components.\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: ReactElemType },\n\ttype: { configurable: true, value: ProxyFunctionalComponent(Text) },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { configurable: true, value: null },\n});\n\nexport function useSignal<T>(value: T) {\n\treturn useMemo(() => signal<T>(value), Empty);\n}\n\nexport function useComputed<T>(compute: () => T) {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\treturn useMemo(() => computed<T>(() => $compute.current()), Empty);\n}\n\nexport function useSignalEffect(cb: () => void | (() => void)) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(() => {\n\t\t\treturn callback.current();\n\t\t});\n\t}, Empty);\n}\n"],"names":["Empty","Symbol","ReactMemoType","ProxyInstance","Map","SupportsProxy","Proxy","apply","Component","thisArg","argumentsList","useMemo","createEffectStore","useSyncExternalStore","store","subscribe","getSnapshot","updater","_start","e","stop","ProxyFunctionalComponent","get","ProxyComponent","ProxyHandlers","set","WrappedComponent","undefined","arguments","WrapWithProxy","onChangeNotifyReact","version","unsubscribe","effect","this","_callback","onStoreChange","WrapJsx","jsx","type","props","slice","call","rest","$$typeof","i","v","Signal","value","concat","JsxPro","jsxRuntime","JsxDev","jsxRuntimeDev","React","createElement","jsxs","jsxDEV","Object","defineProperties","prototype","configurable","ReactElemType","_ref","data","ref","exports","signalsCore","batch","computed","signal","useComputed","compute","$compute","useRef","current","useSignal","useSignalEffect","cb","callback","useEffect"],"mappings":"oTAuBWA,EAAG,KACQC,WAAW,iBACdC,EAAGD,OAAM,IAAK,cAC3BE,EAAgB,IAAIC,IACPC,EAAoB,mBAAjBC,QAEA,CAYrBC,MAZqB,SAYfC,EAA8BC,EAAcC,GACjD,MAAcC,EAAAA,QAAQC,EAAmBZ,GAEzCa,EAAoBA,qBAACC,EAAMC,UAAWD,EAAME,YAAaF,EAAME,aAE/D,MAAaF,EAAMG,QAAQC,IAE3B,IAEC,OADiBV,EAAUD,MAAME,EAASC,EAU1C,CARC,MAAOS,GAGR,MAAMA,CACN,CAPD,QAUCC,GACA,CACD,GAGF,SAASC,EAAyBb,GACjC,SAAqBc,IAAId,IAE1B,SAAuBA,GACtB,GAAIH,EAAe,CAClB,IAAMkB,EAAiB,IAAIjB,MAAME,EAAWgB,GAE5CrB,EAAcsB,IAAIjB,EAAWe,GAC7BpB,EAAcsB,IAAIF,EAAgBA,GAElC,OACAA,CAAA,CAgBD,IAAsBG,EAAG,WACxB,OAAoBF,EAACjB,MAAMC,OAAWmB,EAAWC,UACjD,EACDzB,EAAcsB,IAAIjB,EAAWkB,GAC7BvB,EAAcsB,IAAIC,EAAkBA,GAEpC,OAAOA,CACP,CAjCuCG,CAAcrB,EACrD,CA+CD,SAASI,IACR,IAAAK,EAEAa,EADIC,EAAU,EAGCC,EAAGC,SAAO,WACxBhB,EAAUiB,IACV,GACDjB,EAAQkB,EAAY,WACnBJ,EAAWA,EAAU,EAAK,EAC1B,GAAID,EAAqBA,GACzB,EAED,MAAO,CACNb,QAAAA,EACAF,UAAUqB,SAAAA,GACTN,EAAsBM,EAEtB,OAAO,WAWNL,EAAWA,EAAU,EAAK,EAC1BD,OAAsBH,EACtBK,GACA,CACD,EACDhB,YArBM,WAsBL,OAAOe,CACP,EAEF,CAED,SAAAM,EAAoBC,GACnB,GAAmB,mBAARA,EAAoB,OAAAA,OAE/B,OAAO,SAAUC,EAAW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,IAAK,CAAEJ,cAAc,EAAMb,MAAO,QAsBlCkB,QAAAnB,OAAAoB,EAAApB,OAAAmB,QAAAE,MAAAD,EAAAC,MAAAF,QAAAG,SAAAF,EAAAE,SAAAH,QAAAjC,OAAAkC,EAAAlC,OAAAiC,QAAAI,OAAAH,EAAAG,OAAAJ,QAAAK,YAfK,SAAyBC,GAC9B,IAAcC,EAAGC,EAAMA,OAACF,GACxBC,EAASE,QAAUH,EACnB,OAAO7D,UAAQ,WAAM0D,OAAAA,EAAAA,SAAY,WAAA,OAAcI,EAACE,SAAf,EAAlB,EAA6C3E,EAC5D,EAWAkE,QAAAU,UAnBK,SAAuB5B,GAC5B,SAAcrC,QAAC,WAAA,gBAAgBqC,EAAhB,EAAwBhD,EACvC,EAiBAkE,QAAAW,gBATeA,SAAgBC,GAC/B,IAAMC,EAAWL,EAAMA,OAACI,GACxBC,EAASJ,QAAUG,EAEnBE,EAAAA,UAAU,WACT,OAAO/C,EAAAA,OAAO,WACb,OAAO8C,EAASJ,SAChB,EACD,EAAE3E,EACH"}
@@ -1 +1 @@
1
- !function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("react/jsx-runtime"),require("react/jsx-dev-runtime"),require("use-sync-external-store/shim"),require("@preact/signals-core")):"function"==typeof define&&define.amd?define(["exports","react","react/jsx-runtime","react/jsx-dev-runtime","use-sync-external-store/shim","@preact/signals-core"],e):e((n||self).reactSignals={},n.react,n.jsxRuntime,n.jsxRuntimeDev,n.shim,n.signalsCore)}(this,function(n,e,r,t,u,i){function o(n){return n&&"object"==typeof n&&"default"in n?n.default:n}var f=/*#__PURE__*/o(e),c=/*#__PURE__*/o(r),a=/*#__PURE__*/o(t),s=[],l=Symbol.for("react.element"),p=Symbol.for("react.memo"),y=new Map,v="function"==typeof Proxy,d={apply:function(n,r,t){var i=e.useMemo(m,s);u.useSyncExternalStore(i.subscribe,i.getSnapshot,i.getSnapshot);var o=i.updater.S();try{return n.apply(r,t)}catch(n){throw n}finally{o()}}};function b(n){return y.get(n)||function(n){if(v){var e=new Proxy(n,d);y.set(n,e);y.set(e,e);return e}var r=function(){return d.apply(n,void 0,arguments)};y.set(n,r);y.set(r,r);return r}(n)}function m(){var n,e,r=0,t=i.effect(function(){n=this});n.c=function(){r=r+1|0;if(e)e()};return{updater:n,subscribe:function(n){e=n;return function(){r=r+1|0;e=void 0;t()}},getSnapshot:function(){return r}}}function g(n){if("function"!=typeof n)return n;else return function(r,t){var u=[].slice.call(arguments,2);if("function"==typeof r&&!(r instanceof e.Component))return n.call.apply(n,[n,b(r),t].concat(u));if(r&&"object"==typeof r&&r.$$typeof===p){r.type=b(r.type);return n.call.apply(n,[n,r,t].concat(u))}if("string"==typeof r&&t)for(var o in t){var f=t[o];if("children"!==o&&f instanceof i.Signal)t[o]=f.value}return n.call.apply(n,[n,r,t].concat(u))}}var h=c,x=a;f.createElement=g(f.createElement);x.jsx&&(x.jsx=g(x.jsx));h.jsx&&(h.jsx=g(h.jsx));x.jsxs&&(x.jsxs=g(x.jsxs));h.jsxs&&(h.jsxs=g(h.jsxs));x.jsxDEV&&(x.jsxDEV=g(x.jsxDEV));h.jsxDEV&&(h.jsxDEV=g(h.jsxDEV));Object.defineProperties(i.Signal.prototype,{$$typeof:{configurable:!0,value:l},type:{configurable:!0,value:b(function(n){return n.data.value})},props:{configurable:!0,get:function(){return{data:this}}},ref:{configurable:!0,value:null}});n.Signal=i.Signal;n.batch=i.batch;n.computed=i.computed;n.effect=i.effect;n.signal=i.signal;n.useComputed=function(n){var r=e.useRef(n);r.current=n;return e.useMemo(function(){return i.computed(function(){return r.current()})},s)};n.useSignal=function(n){return e.useMemo(function(){return i.signal(n)},s)};n.useSignalEffect=function(n){var r=e.useRef(n);r.current=n;e.useEffect(function(){return i.effect(function(){return r.current()})},s)}});//# sourceMappingURL=signals.min.js.map
1
+ !function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("react/jsx-runtime"),require("react/jsx-dev-runtime"),require("use-sync-external-store/shim/index.js"),require("@preact/signals-core")):"function"==typeof define&&define.amd?define(["exports","react","react/jsx-runtime","react/jsx-dev-runtime","use-sync-external-store/shim/index.js","@preact/signals-core"],e):e((n||self).reactSignals={},n.react,n.jsxRuntime,n.jsxRuntimeDev,n.index_js,n.signalsCore)}(this,function(n,e,r,t,u,i){function o(n){return n&&"object"==typeof n&&"default"in n?n.default:n}var f=/*#__PURE__*/o(e),c=/*#__PURE__*/o(r),a=/*#__PURE__*/o(t),s=[],l=Symbol.for("react.element"),p=Symbol.for("react.memo"),y=new Map,v="function"==typeof Proxy,d={apply:function(n,r,t){var i=e.useMemo(x,s);u.useSyncExternalStore(i.subscribe,i.getSnapshot,i.getSnapshot);var o=i.updater.S();try{return n.apply(r,t)}catch(n){throw n}finally{o()}}};function b(n){return y.get(n)||function(n){if(v){var e=new Proxy(n,d);y.set(n,e);y.set(e,e);return e}var r=function(){return d.apply(n,void 0,arguments)};y.set(n,r);y.set(r,r);return r}(n)}function x(){var n,e,r=0,t=i.effect(function(){n=this});n.c=function(){r=r+1|0;if(e)e()};return{updater:n,subscribe:function(n){e=n;return function(){r=r+1|0;e=void 0;t()}},getSnapshot:function(){return r}}}function m(n){if("function"!=typeof n)return n;else return function(r,t){var u=[].slice.call(arguments,2);if("function"==typeof r&&!(r instanceof e.Component))return n.call.apply(n,[n,b(r),t].concat(u));if(r&&"object"==typeof r&&r.$$typeof===p){r.type=b(r.type);return n.call.apply(n,[n,r,t].concat(u))}if("string"==typeof r&&t)for(var o in t){var f=t[o];if("children"!==o&&f instanceof i.Signal)t[o]=f.value}return n.call.apply(n,[n,r,t].concat(u))}}var g=c,h=a;f.createElement=m(f.createElement);h.jsx&&(h.jsx=m(h.jsx));g.jsx&&(g.jsx=m(g.jsx));h.jsxs&&(h.jsxs=m(h.jsxs));g.jsxs&&(g.jsxs=m(g.jsxs));h.jsxDEV&&(h.jsxDEV=m(h.jsxDEV));g.jsxDEV&&(g.jsxDEV=m(g.jsxDEV));Object.defineProperties(i.Signal.prototype,{$$typeof:{configurable:!0,value:l},type:{configurable:!0,value:b(function(n){return n.data.value})},props:{configurable:!0,get:function(){return{data:this}}},ref:{configurable:!0,value:null}});n.Signal=i.Signal;n.batch=i.batch;n.computed=i.computed;n.effect=i.effect;n.signal=i.signal;n.useComputed=function(n){var r=e.useRef(n);r.current=n;return e.useMemo(function(){return i.computed(function(){return r.current()})},s)};n.useSignal=function(n){return e.useMemo(function(){return i.signal(n)},s)};n.useSignalEffect=function(n){var r=e.useRef(n);r.current=n;e.useEffect(function(){return i.effect(function(){return r.current()})},s)}});//# sourceMappingURL=signals.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"signals.min.js","sources":["../src/index.ts"],"sourcesContent":["import {\n\tuseRef,\n\tuseMemo,\n\tuseEffect,\n\tComponent,\n\ttype FunctionComponent,\n} from \"react\";\nimport React from \"react\";\nimport jsxRuntime from \"react/jsx-runtime\";\nimport jsxRuntimeDev from \"react/jsx-dev-runtime\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n} from \"@preact/signals-core\";\nimport type { Effect, JsxRuntimeModule } from \"./internal\";\n\nexport { signal, computed, batch, effect, Signal, type ReadonlySignal };\n\nconst Empty = [] as const;\nconst ReactElemType = Symbol.for(\"react.element\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L15\nconst ReactMemoType = Symbol.for(\"react.memo\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L30\nconst ProxyInstance = new Map<FunctionComponent<any>, FunctionComponent<any>>();\nconst SupportsProxy = typeof Proxy === \"function\";\n\nconst ProxyHandlers = {\n\t/**\n\t * This is a function call trap for functional components.\n\t * When this is called, we know it means React did run 'Component()',\n\t * that means we can use any hooks here to setup our effect and store.\n\t *\n\t * With the native Proxy, all other calls such as access/setting to/of properties will\n\t * be forwarded to the target Component, so we don't need to copy the Component's\n\t * own or inherited properties.\n\t *\n\t * @see https://github.com/facebook/react/blob/2d80a0cd690bb5650b6c8a6c079a87b5dc42bd15/packages/react-reconciler/src/ReactFiberHooks.old.js#L460\n\t */\n\tapply(Component: FunctionComponent, thisArg: any, argumentsList: any) {\n\t\tconst store = useMemo(createEffectStore, Empty);\n\n\t\tuseSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n\n\t\tconst stop = store.updater._start();\n\n\t\ttry {\n\t\t\tconst children = Component.apply(thisArg, argumentsList);\n\t\t\treturn children;\n\t\t} catch (e) {\n\t\t\t// Re-throwing promises that'll be handled by suspense\n\t\t\t// or an actual error.\n\t\t\tthrow e;\n\t\t} finally {\n\t\t\t// Stop effects in either case before return or throw,\n\t\t\t// Otherwise the effect will leak.\n\t\t\tstop();\n\t\t}\n\t},\n};\n\nfunction ProxyFunctionalComponent(Component: FunctionComponent<any>) {\n\treturn ProxyInstance.get(Component) || WrapWithProxy(Component);\n}\nfunction WrapWithProxy(Component: FunctionComponent<any>) {\n\tif (SupportsProxy) {\n\t\tconst ProxyComponent = new Proxy(Component, ProxyHandlers);\n\n\t\tProxyInstance.set(Component, ProxyComponent);\n\t\tProxyInstance.set(ProxyComponent, ProxyComponent);\n\n\t\treturn ProxyComponent;\n\t}\n\n\t/**\n\t * Emulate a Proxy if environment doesn't support it.\n\t *\n\t * @TODO - unlike Proxy, it's not possible to access the type/Component's\n\t * static properties this way. Not sure if we want to copy all statics here.\n\t * Omitting this for now.\n\t *\n\t * @example - works with Proxy, doesn't with wrapped function.\n\t * ```\n\t * const el = <SomeFunctionalComponent />\n\t * el.type.someOwnOrInheritedProperty;\n\t * el.type.defaultProps;\n\t * ```\n\t */\n\tconst WrappedComponent = function () {\n\t\treturn ProxyHandlers.apply(Component, undefined, arguments);\n\t};\n\tProxyInstance.set(Component, WrappedComponent);\n\tProxyInstance.set(WrappedComponent, WrappedComponent);\n\n\treturn WrappedComponent;\n}\n\n/**\n * A redux-like store whose store value is a positive 32bit integer (a 'version').\n *\n * React subscribes to this store and gets a snapshot of the current 'version',\n * whenever the 'version' changes, we tell React it's time to update the component (call 'onStoreChange').\n *\n * How we achieve this is by creating a binding with an 'effect', when the `effect._callback' is called,\n * we update our store version and tell React to re-render the component ([1] We don't really care when/how React does it).\n *\n * [1]\n * @see https://reactjs.org/docs/hooks-reference.html#usesyncexternalstore\n * @see https://github.com/reactjs/rfcs/blob/main/text/0214-use-sync-external-store.md\n */\nfunction createEffectStore() {\n\tlet updater!: Effect;\n\tlet version = 0;\n\tlet onChangeNotifyReact: (() => void) | undefined;\n\n\tlet unsubscribe = effect(function (this: Effect) {\n\t\tupdater = this;\n\t});\n\tupdater._callback = function () {\n\t\tversion = (version + 1) | 0;\n\t\tif (onChangeNotifyReact) onChangeNotifyReact();\n\t};\n\n\treturn {\n\t\tupdater,\n\t\tsubscribe(onStoreChange: () => void) {\n\t\t\tonChangeNotifyReact = onStoreChange;\n\n\t\t\treturn function () {\n\t\t\t\t/**\n\t\t\t\t * Rotate to next version when unsubscribing to ensure that components are re-run\n\t\t\t\t * when subscribing again.\n\t\t\t\t *\n\t\t\t\t * In StrictMode, 'memo'-ed components seem to keep a stale snapshot version, so\n\t\t\t\t * don't re-run after subscribing again if the version is the same as last time.\n\t\t\t\t *\n\t\t\t\t * Because we unsubscribe from the effect, the version may not change. We simply\n\t\t\t\t * set a new initial version in case of stale snapshots here.\n\t\t\t\t */\n\t\t\t\tversion = (version + 1) | 0;\n\t\t\t\tonChangeNotifyReact = undefined;\n\t\t\t\tunsubscribe();\n\t\t\t};\n\t\t},\n\t\tgetSnapshot() {\n\t\t\treturn version;\n\t\t},\n\t};\n}\n\nfunction WrapJsx<T>(jsx: T): T {\n\tif (typeof jsx !== \"function\") return jsx;\n\n\treturn function (type: any, props: any, ...rest: any[]) {\n\t\tif (typeof type === \"function\" && !(type instanceof Component)) {\n\t\t\treturn jsx.call(jsx, ProxyFunctionalComponent(type), props, ...rest);\n\t\t}\n\n\t\tif (type && typeof type === \"object\" && type.$$typeof === ReactMemoType) {\n\t\t\ttype.type = ProxyFunctionalComponent(type.type);\n\t\t\treturn jsx.call(jsx, type, props, ...rest);\n\t\t}\n\n\t\tif (typeof type === \"string\" && props) {\n\t\t\tfor (let i in props) {\n\t\t\t\tlet v = props[i];\n\t\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t\tprops[i] = v.value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn jsx.call(jsx, type, props, ...rest);\n\t} as any as T;\n}\n\nconst JsxPro: JsxRuntimeModule = jsxRuntime;\nconst JsxDev: JsxRuntimeModule = jsxRuntimeDev;\n\n/**\n * createElement _may_ be called by jsx runtime as a fallback in certain cases,\n * so we need to wrap it regardless.\n *\n * The jsx exports depend on the `NODE_ENV` var to ensure the users' bundler doesn't\n * include both, so one of them will be set with `undefined` values.\n */\nReact.createElement = WrapJsx(React.createElement);\nJsxDev.jsx && /* */ (JsxDev.jsx = WrapJsx(JsxDev.jsx));\nJsxPro.jsx && /* */ (JsxPro.jsx = WrapJsx(JsxPro.jsx));\nJsxDev.jsxs && /* */ (JsxDev.jsxs = WrapJsx(JsxDev.jsxs));\nJsxPro.jsxs && /* */ (JsxPro.jsxs = WrapJsx(JsxPro.jsxs));\nJsxDev.jsxDEV && /**/ (JsxDev.jsxDEV = WrapJsx(JsxDev.jsxDEV));\nJsxPro.jsxDEV && /**/ (JsxPro.jsxDEV = WrapJsx(JsxPro.jsxDEV));\n\n/**\n * A wrapper component that renders a Signal's value directly as a Text node.\n */\nfunction Text({ data }: { data: Signal }) {\n\treturn data.value;\n}\n\n// Decorate Signals so React renders them as <Text> components.\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: ReactElemType },\n\ttype: { configurable: true, value: ProxyFunctionalComponent(Text) },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { configurable: true, value: null },\n});\n\nexport function useSignal<T>(value: T) {\n\treturn useMemo(() => signal<T>(value), Empty);\n}\n\nexport function useComputed<T>(compute: () => T) {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\treturn useMemo(() => computed<T>(() => $compute.current()), Empty);\n}\n\nexport function useSignalEffect(cb: () => void | (() => void)) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(() => {\n\t\t\treturn callback.current();\n\t\t});\n\t}, Empty);\n}\n"],"names":["Empty","Symbol","ReactMemoType","ProxyInstance","Map","SupportsProxy","Proxy","apply","Component","thisArg","argumentsList","useMemo","createEffectStore","useSyncExternalStore","store","subscribe","getSnapshot","updater","_start","e","stop","ProxyFunctionalComponent","get","ProxyComponent","ProxyHandlers","set","WrappedComponent","undefined","arguments","WrapWithProxy","onChangeNotifyReact","version","unsubscribe","effect","this","_callback","onStoreChange","WrapJsx","jsx","type","props","slice","call","rest","$$typeof","i","v","Signal","value","concat","JsxPro","jsxRuntime","JsxDev","jsxRuntimeDev","React","createElement","jsxs","jsxDEV","Object","defineProperties","prototype","configurable","ReactElemType","_ref","data","ref","exports","signalsCore","batch","computed","signal","useComputed","compute","$compute","useRef","current","useSignal","useSignalEffect","cb","callback","useEffect"],"mappings":"irBAuBWA,EAAG,KACQC,WAAW,iBACdC,EAAGD,OAAM,IAAK,cAC3BE,EAAgB,IAAIC,IACPC,EAAoB,mBAAjBC,QAEA,CAYrBC,MAZqB,SAYfC,EAA8BC,EAAcC,GACjD,MAAcC,EAAAA,QAAQC,EAAmBZ,GAEzCa,EAAoBA,qBAACC,EAAMC,UAAWD,EAAME,YAAaF,EAAME,aAE/D,MAAaF,EAAMG,QAAQC,IAE3B,IAEC,OADiBV,EAAUD,MAAME,EAASC,EAU1C,CARC,MAAOS,GAGR,MAAMA,CACN,CAPD,QAUCC,GACA,CACD,GAGF,SAASC,EAAyBb,GAC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hB,EAAwBhD,EACvC,EAiBAkE,EAAAW,gBATeA,SAAgBC,GAC/B,IAAMC,EAAWL,EAAMA,OAACI,GACxBC,EAASJ,QAAUG,EAEnBE,EAAAA,UAAU,WACT,OAAO/C,EAAAA,OAAO,WACb,OAAO8C,EAASJ,SAChB,EACD,EAAE3E,EACH,CAAA"}
1
+ {"version":3,"file":"signals.min.js","sources":["../src/index.ts"],"sourcesContent":["import {\n\tuseRef,\n\tuseMemo,\n\tuseEffect,\n\tComponent,\n\ttype FunctionComponent,\n} from \"react\";\nimport React from \"react\";\nimport jsxRuntime from \"react/jsx-runtime\";\nimport jsxRuntimeDev from \"react/jsx-dev-runtime\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n} from \"@preact/signals-core\";\nimport type { Effect, JsxRuntimeModule } from \"./internal\";\n\nexport { signal, computed, batch, effect, Signal, type ReadonlySignal };\n\nconst Empty = [] as const;\nconst ReactElemType = Symbol.for(\"react.element\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L15\nconst ReactMemoType = Symbol.for(\"react.memo\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L30\nconst ProxyInstance = new Map<FunctionComponent<any>, FunctionComponent<any>>();\nconst SupportsProxy = typeof Proxy === \"function\";\n\nconst ProxyHandlers = {\n\t/**\n\t * This is a function call trap for functional components.\n\t * When this is called, we know it means React did run 'Component()',\n\t * that means we can use any hooks here to setup our effect and store.\n\t *\n\t * With the native Proxy, all other calls such as access/setting to/of properties will\n\t * be forwarded to the target Component, so we don't need to copy the Component's\n\t * own or inherited properties.\n\t *\n\t * @see https://github.com/facebook/react/blob/2d80a0cd690bb5650b6c8a6c079a87b5dc42bd15/packages/react-reconciler/src/ReactFiberHooks.old.js#L460\n\t */\n\tapply(Component: FunctionComponent, thisArg: any, argumentsList: any) {\n\t\tconst store = useMemo(createEffectStore, Empty);\n\n\t\tuseSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n\n\t\tconst stop = store.updater._start();\n\n\t\ttry {\n\t\t\tconst children = Component.apply(thisArg, argumentsList);\n\t\t\treturn children;\n\t\t} catch (e) {\n\t\t\t// Re-throwing promises that'll be handled by suspense\n\t\t\t// or an actual error.\n\t\t\tthrow e;\n\t\t} finally {\n\t\t\t// Stop effects in either case before return or throw,\n\t\t\t// Otherwise the effect will leak.\n\t\t\tstop();\n\t\t}\n\t},\n};\n\nfunction ProxyFunctionalComponent(Component: FunctionComponent<any>) {\n\treturn ProxyInstance.get(Component) || WrapWithProxy(Component);\n}\nfunction WrapWithProxy(Component: FunctionComponent<any>) {\n\tif (SupportsProxy) {\n\t\tconst ProxyComponent = new Proxy(Component, ProxyHandlers);\n\n\t\tProxyInstance.set(Component, ProxyComponent);\n\t\tProxyInstance.set(ProxyComponent, ProxyComponent);\n\n\t\treturn ProxyComponent;\n\t}\n\n\t/**\n\t * Emulate a Proxy if environment doesn't support it.\n\t *\n\t * @TODO - unlike Proxy, it's not possible to access the type/Component's\n\t * static properties this way. Not sure if we want to copy all statics here.\n\t * Omitting this for now.\n\t *\n\t * @example - works with Proxy, doesn't with wrapped function.\n\t * ```\n\t * const el = <SomeFunctionalComponent />\n\t * el.type.someOwnOrInheritedProperty;\n\t * el.type.defaultProps;\n\t * ```\n\t */\n\tconst WrappedComponent = function () {\n\t\treturn ProxyHandlers.apply(Component, undefined, arguments);\n\t};\n\tProxyInstance.set(Component, WrappedComponent);\n\tProxyInstance.set(WrappedComponent, WrappedComponent);\n\n\treturn WrappedComponent;\n}\n\n/**\n * A redux-like store whose store value is a positive 32bit integer (a 'version').\n *\n * React subscribes to this store and gets a snapshot of the current 'version',\n * whenever the 'version' changes, we tell React it's time to update the component (call 'onStoreChange').\n *\n * How we achieve this is by creating a binding with an 'effect', when the `effect._callback' is called,\n * we update our store version and tell React to re-render the component ([1] We don't really care when/how React does it).\n *\n * [1]\n * @see https://reactjs.org/docs/hooks-reference.html#usesyncexternalstore\n * @see https://github.com/reactjs/rfcs/blob/main/text/0214-use-sync-external-store.md\n */\nfunction createEffectStore() {\n\tlet updater!: Effect;\n\tlet version = 0;\n\tlet onChangeNotifyReact: (() => void) | undefined;\n\n\tlet unsubscribe = effect(function (this: Effect) {\n\t\tupdater = this;\n\t});\n\tupdater._callback = function () {\n\t\tversion = (version + 1) | 0;\n\t\tif (onChangeNotifyReact) onChangeNotifyReact();\n\t};\n\n\treturn {\n\t\tupdater,\n\t\tsubscribe(onStoreChange: () => void) {\n\t\t\tonChangeNotifyReact = onStoreChange;\n\n\t\t\treturn function () {\n\t\t\t\t/**\n\t\t\t\t * Rotate to next version when unsubscribing to ensure that components are re-run\n\t\t\t\t * when subscribing again.\n\t\t\t\t *\n\t\t\t\t * In StrictMode, 'memo'-ed components seem to keep a stale snapshot version, so\n\t\t\t\t * don't re-run after subscribing again if the version is the same as last time.\n\t\t\t\t *\n\t\t\t\t * Because we unsubscribe from the effect, the version may not change. We simply\n\t\t\t\t * set a new initial version in case of stale snapshots here.\n\t\t\t\t */\n\t\t\t\tversion = (version + 1) | 0;\n\t\t\t\tonChangeNotifyReact = undefined;\n\t\t\t\tunsubscribe();\n\t\t\t};\n\t\t},\n\t\tgetSnapshot() {\n\t\t\treturn version;\n\t\t},\n\t};\n}\n\nfunction WrapJsx<T>(jsx: T): T {\n\tif (typeof jsx !== \"function\") return jsx;\n\n\treturn function (type: any, props: any, ...rest: any[]) {\n\t\tif (typeof type === \"function\" && !(type instanceof Component)) {\n\t\t\treturn jsx.call(jsx, ProxyFunctionalComponent(type), props, ...rest);\n\t\t}\n\n\t\tif (type && typeof type === \"object\" && type.$$typeof === ReactMemoType) {\n\t\t\ttype.type = ProxyFunctionalComponent(type.type);\n\t\t\treturn jsx.call(jsx, type, props, ...rest);\n\t\t}\n\n\t\tif (typeof type === \"string\" && props) {\n\t\t\tfor (let i in props) {\n\t\t\t\tlet v = props[i];\n\t\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t\tprops[i] = v.value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn jsx.call(jsx, type, props, ...rest);\n\t} as any as T;\n}\n\nconst JsxPro: JsxRuntimeModule = jsxRuntime;\nconst JsxDev: JsxRuntimeModule = jsxRuntimeDev;\n\n/**\n * createElement _may_ be called by jsx runtime as a fallback in certain cases,\n * so we need to wrap it regardless.\n *\n * The jsx exports depend on the `NODE_ENV` var to ensure the users' bundler doesn't\n * include both, so one of them will be set with `undefined` values.\n */\nReact.createElement = WrapJsx(React.createElement);\nJsxDev.jsx && /* */ (JsxDev.jsx = WrapJsx(JsxDev.jsx));\nJsxPro.jsx && /* */ (JsxPro.jsx = WrapJsx(JsxPro.jsx));\nJsxDev.jsxs && /* */ (JsxDev.jsxs = WrapJsx(JsxDev.jsxs));\nJsxPro.jsxs && /* */ (JsxPro.jsxs = WrapJsx(JsxPro.jsxs));\nJsxDev.jsxDEV && /**/ (JsxDev.jsxDEV = WrapJsx(JsxDev.jsxDEV));\nJsxPro.jsxDEV && /**/ (JsxPro.jsxDEV = WrapJsx(JsxPro.jsxDEV));\n\n/**\n * A wrapper component that renders a Signal's value directly as a Text node.\n */\nfunction Text({ data }: { data: Signal }) {\n\treturn data.value;\n}\n\n// Decorate Signals so React renders them as <Text> components.\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: ReactElemType },\n\ttype: { configurable: true, value: ProxyFunctionalComponent(Text) },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { configurable: true, value: null },\n});\n\nexport function useSignal<T>(value: T) {\n\treturn useMemo(() => signal<T>(value), Empty);\n}\n\nexport function useComputed<T>(compute: () => T) {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\treturn useMemo(() => computed<T>(() => $compute.current()), Empty);\n}\n\nexport function useSignalEffect(cb: () => void | (() => void)) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(() => {\n\t\t\treturn callback.current();\n\t\t});\n\t}, Empty);\n}\n"],"names":["Empty","Symbol","ReactMemoType","ProxyInstance","Map","SupportsProxy","Proxy","apply","Component","thisArg","argumentsList","useMemo","createEffectStore","useSyncExternalStore","store","subscribe","getSnapshot","updater","_start","e","stop","ProxyFunctionalComponent","get","ProxyComponent","ProxyHandlers","set","WrappedComponent","undefined","arguments","WrapWithProxy","onChangeNotifyReact","version","unsubscribe","effect","this","_callback","onStoreChange","WrapJsx","jsx","type","props","slice","call","rest","$$typeof","i","v","Signal","value","concat","JsxPro","jsxRuntime","JsxDev","jsxRuntimeDev","React","createElement","jsxs","jsxDEV","Object","defineProperties","prototype","configurable","ReactElemType","_ref","data","ref","exports","signalsCore","batch","computed","signal","useComputed","compute","$compute","useRef","current","useSignal","useSignalEffect","cb","callback","useEffect"],"mappings":"usBAuBWA,EAAG,KACQC,WAAW,iBACdC,EAAGD,OAAM,IAAK,cAC3BE,EAAgB,IAAIC,IACPC,EAAoB,mBAAjBC,QAEA,CAYrBC,MAZqB,SAYfC,EAA8BC,EAAcC,GACjD,MAAcC,EAAAA,QAAQC,EAAmBZ,GAEzCa,EAAoBA,qBAACC,EAAMC,UAAWD,EAAME,YAAaF,EAAME,aAE/D,MAAaF,EAAMG,QAAQC,IAE3B,IAEC,OADiBV,EAAUD,MAAME,EAASC,EAU1C,CARC,MAAOS,GAGR,MAAMA,CACN,CAPD,QAUCC,GACA,CACD,GAGF,SAASC,EAAyBb,GACjC,SAAqBc,IAAId,IAE1B,SAAuBA,GACtB,GAAIH,EAAe,CAClB,IAAMkB,EAAiB,IAAIjB,MAAME,EAAWgB,GAE5CrB,EAAcsB,IAAIjB,EAAWe,GAC7BpB,EAAcsB,IAAIF,EAAgBA,GAElC,OACAA,CAAA,CAgBD,I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E3E,EACH,CAAA"}
package/dist/signals.mjs CHANGED
@@ -1 +1 @@
1
- import t,{Component as n,useMemo as r,useRef as e,useEffect as o}from"react";import i from"react/jsx-runtime";import c from"react/jsx-dev-runtime";import{useSyncExternalStore as f}from"use-sync-external-store/shim";import{Signal as u,signal as a,computed as s,effect as l}from"@preact/signals-core";export{Signal,batch,computed,effect,signal}from"@preact/signals-core";const p=[],m=Symbol.for("react.element"),y=Symbol.for("react.memo"),b=new Map,g="function"==typeof Proxy,d={apply(t,n,e){const o=r(x,p);f(o.subscribe,o.getSnapshot,o.getSnapshot);const i=o.updater.S();try{return t.apply(n,e)}catch(t){throw t}finally{i()}}};function h(t){return b.get(t)||function(t){if(g){const n=new Proxy(t,d);b.set(t,n);b.set(n,n);return n}const n=function(){return d.apply(t,void 0,arguments)};b.set(t,n);b.set(n,n);return n}(t)}function x(){let t,n,r=0,e=l(function(){t=this});t.c=function(){r=r+1|0;if(n)n()};return{updater:t,subscribe(t){n=t;return function(){r=r+1|0;n=void 0;e()}},getSnapshot:()=>r}}function v(t){if("function"!=typeof t)return t;else return function(r,e,...o){if("function"==typeof r&&!(r instanceof n))return t.call(t,h(r),e,...o);if(r&&"object"==typeof r&&r.$$typeof===y){r.type=h(r.type);return t.call(t,r,e,...o)}if("string"==typeof r&&e)for(let t in e){let n=e[t];if("children"!==t&&n instanceof u)e[t]=n.value}return t.call(t,r,e,...o)}}const j=i,S=c;t.createElement=v(t.createElement);S.jsx&&(S.jsx=v(S.jsx));j.jsx&&(j.jsx=v(j.jsx));S.jsxs&&(S.jsxs=v(S.jsxs));j.jsxs&&(j.jsxs=v(j.jsxs));S.jsxDEV&&(S.jsxDEV=v(S.jsxDEV));j.jsxDEV&&(j.jsxDEV=v(j.jsxDEV));Object.defineProperties(u.prototype,{$$typeof:{configurable:!0,value:m},type:{configurable:!0,value:h(function({data:t}){return t.value})},props:{configurable:!0,get(){return{data:this}}},ref:{configurable:!0,value:null}});function useSignal(t){return r(()=>a(t),p)}function useComputed(t){const n=e(t);n.current=t;return r(()=>s(()=>n.current()),p)}function useSignalEffect(t){const n=e(t);n.current=t;o(()=>l(()=>n.current()),p)}export{useComputed,useSignal,useSignalEffect};//# sourceMappingURL=signals.mjs.map
1
+ import t,{Component as n,useMemo as e,useRef as r,useEffect as o}from"react";import i from"react/jsx-runtime";import c from"react/jsx-dev-runtime";import{useSyncExternalStore as f}from"use-sync-external-store/shim/index.js";import{Signal as u,signal as a,computed as s,effect as l}from"@preact/signals-core";export{Signal,batch,computed,effect,signal}from"@preact/signals-core";const p=[],m=Symbol.for("react.element"),y=Symbol.for("react.memo"),b=new Map,g="function"==typeof Proxy,d={apply(t,n,r){const o=e(x,p);f(o.subscribe,o.getSnapshot,o.getSnapshot);const i=o.updater.S();try{return t.apply(n,r)}catch(t){throw t}finally{i()}}};function h(t){return b.get(t)||function(t){if(g){const n=new Proxy(t,d);b.set(t,n);b.set(n,n);return n}const n=function(){return d.apply(t,void 0,arguments)};b.set(t,n);b.set(n,n);return n}(t)}function x(){let t,n,e=0,r=l(function(){t=this});t.c=function(){e=e+1|0;if(n)n()};return{updater:t,subscribe(t){n=t;return function(){e=e+1|0;n=void 0;r()}},getSnapshot:()=>e}}function v(t){if("function"!=typeof t)return t;else return function(e,r,...o){if("function"==typeof e&&!(e instanceof n))return t.call(t,h(e),r,...o);if(e&&"object"==typeof e&&e.$$typeof===y){e.type=h(e.type);return t.call(t,e,r,...o)}if("string"==typeof e&&r)for(let t in r){let n=r[t];if("children"!==t&&n instanceof u)r[t]=n.value}return t.call(t,e,r,...o)}}const j=i,S=c;t.createElement=v(t.createElement);S.jsx&&(S.jsx=v(S.jsx));j.jsx&&(j.jsx=v(j.jsx));S.jsxs&&(S.jsxs=v(S.jsxs));j.jsxs&&(j.jsxs=v(j.jsxs));S.jsxDEV&&(S.jsxDEV=v(S.jsxDEV));j.jsxDEV&&(j.jsxDEV=v(j.jsxDEV));Object.defineProperties(u.prototype,{$$typeof:{configurable:!0,value:m},type:{configurable:!0,value:h(function({data:t}){return t.value})},props:{configurable:!0,get(){return{data:this}}},ref:{configurable:!0,value:null}});function useSignal(t){return e(()=>a(t),p)}function useComputed(t){const n=r(t);n.current=t;return e(()=>s(()=>n.current()),p)}function useSignalEffect(t){const n=r(t);n.current=t;o(()=>l(()=>n.current()),p)}export{useComputed,useSignal,useSignalEffect};//# sourceMappingURL=signals.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"signals.mjs","sources":["../src/index.ts"],"sourcesContent":["import {\n\tuseRef,\n\tuseMemo,\n\tuseEffect,\n\tComponent,\n\ttype FunctionComponent,\n} from \"react\";\nimport React from \"react\";\nimport jsxRuntime from \"react/jsx-runtime\";\nimport jsxRuntimeDev from \"react/jsx-dev-runtime\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n} from \"@preact/signals-core\";\nimport type { Effect, JsxRuntimeModule } from \"./internal\";\n\nexport { signal, computed, batch, effect, Signal, type ReadonlySignal };\n\nconst Empty = [] as const;\nconst ReactElemType = Symbol.for(\"react.element\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L15\nconst ReactMemoType = Symbol.for(\"react.memo\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L30\nconst ProxyInstance = new Map<FunctionComponent<any>, FunctionComponent<any>>();\nconst SupportsProxy = typeof Proxy === \"function\";\n\nconst ProxyHandlers = {\n\t/**\n\t * This is a function call trap for functional components.\n\t * When this is called, we know it means React did run 'Component()',\n\t * that means we can use any hooks here to setup our effect and store.\n\t *\n\t * With the native Proxy, all other calls such as access/setting to/of properties will\n\t * be forwarded to the target Component, so we don't need to copy the Component's\n\t * own or inherited properties.\n\t *\n\t * @see https://github.com/facebook/react/blob/2d80a0cd690bb5650b6c8a6c079a87b5dc42bd15/packages/react-reconciler/src/ReactFiberHooks.old.js#L460\n\t */\n\tapply(Component: FunctionComponent, thisArg: any, argumentsList: any) {\n\t\tconst store = useMemo(createEffectStore, Empty);\n\n\t\tuseSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n\n\t\tconst stop = store.updater._start();\n\n\t\ttry {\n\t\t\tconst children = Component.apply(thisArg, argumentsList);\n\t\t\treturn children;\n\t\t} catch (e) {\n\t\t\t// Re-throwing promises that'll be handled by suspense\n\t\t\t// or an actual error.\n\t\t\tthrow e;\n\t\t} finally {\n\t\t\t// Stop effects in either case before return or throw,\n\t\t\t// Otherwise the effect will leak.\n\t\t\tstop();\n\t\t}\n\t},\n};\n\nfunction ProxyFunctionalComponent(Component: FunctionComponent<any>) {\n\treturn ProxyInstance.get(Component) || WrapWithProxy(Component);\n}\nfunction WrapWithProxy(Component: FunctionComponent<any>) {\n\tif (SupportsProxy) {\n\t\tconst ProxyComponent = new Proxy(Component, ProxyHandlers);\n\n\t\tProxyInstance.set(Component, ProxyComponent);\n\t\tProxyInstance.set(ProxyComponent, ProxyComponent);\n\n\t\treturn ProxyComponent;\n\t}\n\n\t/**\n\t * Emulate a Proxy if environment doesn't support it.\n\t *\n\t * @TODO - unlike Proxy, it's not possible to access the type/Component's\n\t * static properties this way. Not sure if we want to copy all statics here.\n\t * Omitting this for now.\n\t *\n\t * @example - works with Proxy, doesn't with wrapped function.\n\t * ```\n\t * const el = <SomeFunctionalComponent />\n\t * el.type.someOwnOrInheritedProperty;\n\t * el.type.defaultProps;\n\t * ```\n\t */\n\tconst WrappedComponent = function () {\n\t\treturn ProxyHandlers.apply(Component, undefined, arguments);\n\t};\n\tProxyInstance.set(Component, WrappedComponent);\n\tProxyInstance.set(WrappedComponent, WrappedComponent);\n\n\treturn WrappedComponent;\n}\n\n/**\n * A redux-like store whose store value is a positive 32bit integer (a 'version').\n *\n * React subscribes to this store and gets a snapshot of the current 'version',\n * whenever the 'version' changes, we tell React it's time to update the component (call 'onStoreChange').\n *\n * How we achieve this is by creating a binding with an 'effect', when the `effect._callback' is called,\n * we update our store version and tell React to re-render the component ([1] We don't really care when/how React does it).\n *\n * [1]\n * @see https://reactjs.org/docs/hooks-reference.html#usesyncexternalstore\n * @see https://github.com/reactjs/rfcs/blob/main/text/0214-use-sync-external-store.md\n */\nfunction createEffectStore() {\n\tlet updater!: Effect;\n\tlet version = 0;\n\tlet onChangeNotifyReact: (() => void) | undefined;\n\n\tlet unsubscribe = effect(function (this: Effect) {\n\t\tupdater = this;\n\t});\n\tupdater._callback = function () {\n\t\tversion = (version + 1) | 0;\n\t\tif (onChangeNotifyReact) onChangeNotifyReact();\n\t};\n\n\treturn {\n\t\tupdater,\n\t\tsubscribe(onStoreChange: () => void) {\n\t\t\tonChangeNotifyReact = onStoreChange;\n\n\t\t\treturn function () {\n\t\t\t\t/**\n\t\t\t\t * Rotate to next version when unsubscribing to ensure that components are re-run\n\t\t\t\t * when subscribing again.\n\t\t\t\t *\n\t\t\t\t * In StrictMode, 'memo'-ed components seem to keep a stale snapshot version, so\n\t\t\t\t * don't re-run after subscribing again if the version is the same as last time.\n\t\t\t\t *\n\t\t\t\t * Because we unsubscribe from the effect, the version may not change. We simply\n\t\t\t\t * set a new initial version in case of stale snapshots here.\n\t\t\t\t */\n\t\t\t\tversion = (version + 1) | 0;\n\t\t\t\tonChangeNotifyReact = undefined;\n\t\t\t\tunsubscribe();\n\t\t\t};\n\t\t},\n\t\tgetSnapshot() {\n\t\t\treturn version;\n\t\t},\n\t};\n}\n\nfunction WrapJsx<T>(jsx: T): T {\n\tif (typeof jsx !== \"function\") return jsx;\n\n\treturn function (type: any, props: any, ...rest: any[]) {\n\t\tif (typeof type === \"function\" && !(type instanceof Component)) {\n\t\t\treturn jsx.call(jsx, ProxyFunctionalComponent(type), props, ...rest);\n\t\t}\n\n\t\tif (type && typeof type === \"object\" && type.$$typeof === ReactMemoType) {\n\t\t\ttype.type = ProxyFunctionalComponent(type.type);\n\t\t\treturn jsx.call(jsx, type, props, ...rest);\n\t\t}\n\n\t\tif (typeof type === \"string\" && props) {\n\t\t\tfor (let i in props) {\n\t\t\t\tlet v = props[i];\n\t\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t\tprops[i] = v.value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn jsx.call(jsx, type, props, ...rest);\n\t} as any as T;\n}\n\nconst JsxPro: JsxRuntimeModule = jsxRuntime;\nconst JsxDev: JsxRuntimeModule = jsxRuntimeDev;\n\n/**\n * createElement _may_ be called by jsx runtime as a fallback in certain cases,\n * so we need to wrap it regardless.\n *\n * The jsx exports depend on the `NODE_ENV` var to ensure the users' bundler doesn't\n * include both, so one of them will be set with `undefined` values.\n */\nReact.createElement = WrapJsx(React.createElement);\nJsxDev.jsx && /* */ (JsxDev.jsx = WrapJsx(JsxDev.jsx));\nJsxPro.jsx && /* */ (JsxPro.jsx = WrapJsx(JsxPro.jsx));\nJsxDev.jsxs && /* */ (JsxDev.jsxs = WrapJsx(JsxDev.jsxs));\nJsxPro.jsxs && /* */ (JsxPro.jsxs = WrapJsx(JsxPro.jsxs));\nJsxDev.jsxDEV && /**/ (JsxDev.jsxDEV = WrapJsx(JsxDev.jsxDEV));\nJsxPro.jsxDEV && /**/ (JsxPro.jsxDEV = WrapJsx(JsxPro.jsxDEV));\n\n/**\n * A wrapper component that renders a Signal's value directly as a Text node.\n */\nfunction Text({ data }: { data: Signal }) {\n\treturn data.value;\n}\n\n// Decorate Signals so React renders them as <Text> components.\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: ReactElemType },\n\ttype: { configurable: true, value: ProxyFunctionalComponent(Text) },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { configurable: true, value: null },\n});\n\nexport function useSignal<T>(value: T) {\n\treturn useMemo(() => signal<T>(value), Empty);\n}\n\nexport function useComputed<T>(compute: () => T) {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\treturn useMemo(() => computed<T>(() => $compute.current()), Empty);\n}\n\nexport function useSignalEffect(cb: () => void | (() => void)) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(() => {\n\t\t\treturn callback.current();\n\t\t});\n\t}, Empty);\n}\n"],"names":["React","Component","useMemo","useRef","useEffect","jsxRuntime","jsxRuntimeDev","useSyncExternalStore","Signal","signal","computed","effect","batch","Empty","Symbol","for","ReactMemoType","ProxyInstance","Map","ProxyHandlers","apply","thisArg","argumentsList","store","createEffectStore","subscribe","getSnapshot","stop","updater","_start","e","get","SupportsProxy","ProxyComponent","Proxy","set","WrappedComponent","undefined","arguments","WrapWithProxy","onChangeNotifyReact","unsubscribe","this","_callback","version","onStoreChange","jsx","type","props","rest","call","ProxyFunctionalComponent","$$typeof","v","i","value","JsxDev","createElement","WrapJsx","JsxPro","jsxs","jsxDEV","Object","defineProperties","prototype","configurable","ReactElemType","data","ref","compute","$compute","current","useSignalEffect","cb","callback","useComputed","useSignal"],"mappings":"OAuBAA,gBAAAC,aAAAC,YAAAC,eAAAC,MAAA,eAAAC,MAAA,2BAAAC,MAAA,uDAAAC,MAAA,gDAAAC,YAAAC,cAAAC,YAAAC,MAAA,8BAAAH,OAAAI,MAAAF,SAAAC,OAAAF,WAAA,uBAAA,MAAWI,EAAG,KACQC,OAAOC,IAAI,iBAC3BC,EAAgBF,OAAOC,IAAI,cACdE,EAAG,IAAIC,MACa,yBAEjCC,EAAgB,CAYrBC,MAAMnB,EAA8BoB,EAAcC,GACjD,MAAMC,EAAQrB,EAAQsB,EAAmBX,GAEzCN,EAAqBgB,EAAME,UAAWF,EAAMG,YAAaH,EAAMG,aAE/D,MAAMC,EAAOJ,EAAMK,QAAQC,IAE3B,IAEC,OADiB5B,EAAUmB,MAAMC,EAASC,EAU1C,CARC,MAAOQ,GAGR,MAAMA,CACN,CAPD,QAUCH,GACA,CACD,GAGF,WAAkC1B,G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AAMyD,cAAgBC,EAAQ1D,EAAMyD,eACpCD,EAAOV,MAAgBU,EAAOV,IAAMY,EAAQF,EAAOV,MACnDa,EAAOb,MAAgBa,EAAOb,IAAMY,EAAQC,EAAOb,MACnDU,EAAOI,OAAgBJ,EAAOI,KAAOF,EAAQF,EAAOI,OACpDD,EAAOC,OAAgBD,EAAOC,KAAOF,EAAQC,EAAOC,OACpDJ,EAAOK,SAAgBL,EAAOK,OAASH,EAAQF,EAAOK,SACtDF,EAAOE,SAAgBF,EAAOE,OAASH,EAAQC,EAAOE,SAUtDC,OAAOC,iBAAiBvD,EAAOwD,UAAW,CACzCZ,SAAU,CAAEa,cAAc,EAAMV,MAAOW,GACvCnB,KAAM,CAAEkB,cAAc,EAAMV,MAAOJ,EAPpC,UAAcgB,KAAEA,IACf,OAAOA,EAAKZ,KACZ,IAMAP,MAAO,CACNiB,cAAc,EACdlC,MACC,MAAO,CAAEoC,KAAMzB,KACf,GAEF0B,IAAK,CAAEH,cAAc,EAAMV,MAAO,QAG7B,mBAAuBA,GAC5B,SAAe,IAAM9C,EAAU8C,GAAQ1C,EACvC,CAEK,qBAAyBwD,GAC9B,QAAiBlE,EAAOkE,GACxBC,EAASC,QAAUF,EACnB,OAAcnE,EAAC,IAAMQ,EAAY,IAAM4D,EAASC,WAAY1D,EAC5D,CAEe2D,SAAAA,gBAAgBC,GAC/B,MAAMC,EAAWvE,EAAOsE,GACxBC,EAASH,QAAUE,EAEnBrE,EAAU,IACFO,EAAO,IACN+D,EAASH,WAEf1D,EACH,QAAA8D,YAAAC,UAAAJ"}
1
+ {"version":3,"file":"signals.mjs","sources":["../src/index.ts"],"sourcesContent":["import {\n\tuseRef,\n\tuseMemo,\n\tuseEffect,\n\tComponent,\n\ttype FunctionComponent,\n} from \"react\";\nimport React from \"react\";\nimport jsxRuntime from \"react/jsx-runtime\";\nimport jsxRuntimeDev from \"react/jsx-dev-runtime\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n} from \"@preact/signals-core\";\nimport type { Effect, JsxRuntimeModule } from \"./internal\";\n\nexport { signal, computed, batch, effect, Signal, type ReadonlySignal };\n\nconst Empty = [] as const;\nconst ReactElemType = Symbol.for(\"react.element\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L15\nconst ReactMemoType = Symbol.for(\"react.memo\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L30\nconst ProxyInstance = new Map<FunctionComponent<any>, FunctionComponent<any>>();\nconst SupportsProxy = typeof Proxy === \"function\";\n\nconst ProxyHandlers = {\n\t/**\n\t * This is a function call trap for functional components.\n\t * When this is called, we know it means React did run 'Component()',\n\t * that means we can use any hooks here to setup our effect and store.\n\t *\n\t * With the native Proxy, all other calls such as access/setting to/of properties will\n\t * be forwarded to the target Component, so we don't need to copy the Component's\n\t * own or inherited properties.\n\t *\n\t * @see https://github.com/facebook/react/blob/2d80a0cd690bb5650b6c8a6c079a87b5dc42bd15/packages/react-reconciler/src/ReactFiberHooks.old.js#L460\n\t */\n\tapply(Component: FunctionComponent, thisArg: any, argumentsList: any) {\n\t\tconst store = useMemo(createEffectStore, Empty);\n\n\t\tuseSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n\n\t\tconst stop = store.updater._start();\n\n\t\ttry {\n\t\t\tconst children = Component.apply(thisArg, argumentsList);\n\t\t\treturn children;\n\t\t} catch (e) {\n\t\t\t// Re-throwing promises that'll be handled by suspense\n\t\t\t// or an actual error.\n\t\t\tthrow e;\n\t\t} finally {\n\t\t\t// Stop effects in either case before return or throw,\n\t\t\t// Otherwise the effect will leak.\n\t\t\tstop();\n\t\t}\n\t},\n};\n\nfunction ProxyFunctionalComponent(Component: FunctionComponent<any>) {\n\treturn ProxyInstance.get(Component) || WrapWithProxy(Component);\n}\nfunction WrapWithProxy(Component: FunctionComponent<any>) {\n\tif (SupportsProxy) {\n\t\tconst ProxyComponent = new Proxy(Component, ProxyHandlers);\n\n\t\tProxyInstance.set(Component, ProxyComponent);\n\t\tProxyInstance.set(ProxyComponent, ProxyComponent);\n\n\t\treturn ProxyComponent;\n\t}\n\n\t/**\n\t * Emulate a Proxy if environment doesn't support it.\n\t *\n\t * @TODO - unlike Proxy, it's not possible to access the type/Component's\n\t * static properties this way. Not sure if we want to copy all statics here.\n\t * Omitting this for now.\n\t *\n\t * @example - works with Proxy, doesn't with wrapped function.\n\t * ```\n\t * const el = <SomeFunctionalComponent />\n\t * el.type.someOwnOrInheritedProperty;\n\t * el.type.defaultProps;\n\t * ```\n\t */\n\tconst WrappedComponent = function () {\n\t\treturn ProxyHandlers.apply(Component, undefined, arguments);\n\t};\n\tProxyInstance.set(Component, WrappedComponent);\n\tProxyInstance.set(WrappedComponent, WrappedComponent);\n\n\treturn WrappedComponent;\n}\n\n/**\n * A redux-like store whose store value is a positive 32bit integer (a 'version').\n *\n * React subscribes to this store and gets a snapshot of the current 'version',\n * whenever the 'version' changes, we tell React it's time to update the component (call 'onStoreChange').\n *\n * How we achieve this is by creating a binding with an 'effect', when the `effect._callback' is called,\n * we update our store version and tell React to re-render the component ([1] We don't really care when/how React does it).\n *\n * [1]\n * @see https://reactjs.org/docs/hooks-reference.html#usesyncexternalstore\n * @see https://github.com/reactjs/rfcs/blob/main/text/0214-use-sync-external-store.md\n */\nfunction createEffectStore() {\n\tlet updater!: Effect;\n\tlet version = 0;\n\tlet onChangeNotifyReact: (() => void) | undefined;\n\n\tlet unsubscribe = effect(function (this: Effect) {\n\t\tupdater = this;\n\t});\n\tupdater._callback = function () {\n\t\tversion = (version + 1) | 0;\n\t\tif (onChangeNotifyReact) onChangeNotifyReact();\n\t};\n\n\treturn {\n\t\tupdater,\n\t\tsubscribe(onStoreChange: () => void) {\n\t\t\tonChangeNotifyReact = onStoreChange;\n\n\t\t\treturn function () {\n\t\t\t\t/**\n\t\t\t\t * Rotate to next version when unsubscribing to ensure that components are re-run\n\t\t\t\t * when subscribing again.\n\t\t\t\t *\n\t\t\t\t * In StrictMode, 'memo'-ed components seem to keep a stale snapshot version, so\n\t\t\t\t * don't re-run after subscribing again if the version is the same as last time.\n\t\t\t\t *\n\t\t\t\t * Because we unsubscribe from the effect, the version may not change. We simply\n\t\t\t\t * set a new initial version in case of stale snapshots here.\n\t\t\t\t */\n\t\t\t\tversion = (version + 1) | 0;\n\t\t\t\tonChangeNotifyReact = undefined;\n\t\t\t\tunsubscribe();\n\t\t\t};\n\t\t},\n\t\tgetSnapshot() {\n\t\t\treturn version;\n\t\t},\n\t};\n}\n\nfunction WrapJsx<T>(jsx: T): T {\n\tif (typeof jsx !== \"function\") return jsx;\n\n\treturn function (type: any, props: any, ...rest: any[]) {\n\t\tif (typeof type === \"function\" && !(type instanceof Component)) {\n\t\t\treturn jsx.call(jsx, ProxyFunctionalComponent(type), props, ...rest);\n\t\t}\n\n\t\tif (type && typeof type === \"object\" && type.$$typeof === ReactMemoType) {\n\t\t\ttype.type = ProxyFunctionalComponent(type.type);\n\t\t\treturn jsx.call(jsx, type, props, ...rest);\n\t\t}\n\n\t\tif (typeof type === \"string\" && props) {\n\t\t\tfor (let i in props) {\n\t\t\t\tlet v = props[i];\n\t\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t\tprops[i] = v.value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn jsx.call(jsx, type, props, ...rest);\n\t} as any as T;\n}\n\nconst JsxPro: JsxRuntimeModule = jsxRuntime;\nconst JsxDev: JsxRuntimeModule = jsxRuntimeDev;\n\n/**\n * createElement _may_ be called by jsx runtime as a fallback in certain cases,\n * so we need to wrap it regardless.\n *\n * The jsx exports depend on the `NODE_ENV` var to ensure the users' bundler doesn't\n * include both, so one of them will be set with `undefined` values.\n */\nReact.createElement = WrapJsx(React.createElement);\nJsxDev.jsx && /* */ (JsxDev.jsx = WrapJsx(JsxDev.jsx));\nJsxPro.jsx && /* */ (JsxPro.jsx = WrapJsx(JsxPro.jsx));\nJsxDev.jsxs && /* */ (JsxDev.jsxs = WrapJsx(JsxDev.jsxs));\nJsxPro.jsxs && /* */ (JsxPro.jsxs = WrapJsx(JsxPro.jsxs));\nJsxDev.jsxDEV && /**/ (JsxDev.jsxDEV = WrapJsx(JsxDev.jsxDEV));\nJsxPro.jsxDEV && /**/ (JsxPro.jsxDEV = WrapJsx(JsxPro.jsxDEV));\n\n/**\n * A wrapper component that renders a Signal's value directly as a Text node.\n */\nfunction Text({ data }: { data: Signal }) {\n\treturn data.value;\n}\n\n// Decorate Signals so React renders them as <Text> components.\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: ReactElemType },\n\ttype: { configurable: true, value: ProxyFunctionalComponent(Text) },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { configurable: true, value: null },\n});\n\nexport function useSignal<T>(value: T) {\n\treturn useMemo(() => signal<T>(value), Empty);\n}\n\nexport function useComputed<T>(compute: () => T) {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\treturn useMemo(() => computed<T>(() => $compute.current()), Empty);\n}\n\nexport function useSignalEffect(cb: () => void | (() => void)) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(() => {\n\t\t\treturn callback.current();\n\t\t});\n\t}, Empty);\n}\n"],"names":["React","Component","useMemo","useRef","useEffect","jsxRuntime","jsxRuntimeDev","useSyncExternalStore","Signal","signal","computed","effect","batch","Empty","Symbol","for","ReactMemoType","ProxyInstance","Map","ProxyHandlers","apply","thisArg","argumentsList","store","createEffectStore","subscribe","getSnapshot","stop","updater","_start","e","get","SupportsProxy","ProxyComponent","Proxy","set","WrappedComponent","undefined","arguments","WrapWithProxy","onChangeNotifyReact","unsubscribe","this","_callback","version","onStoreChange","jsx","type","props","rest","call","ProxyFunctionalComponent","$$typeof","v","i","value","JsxDev","createElement","WrapJsx","JsxPro","jsxs","jsxDEV","Object","defineProperties","prototype","configurable","ReactElemType","data","ref","compute","$compute","current","useSignalEffect","cb","callback","useComputed","useSignal"],"mappings":"OAuBAA,gBAAAC,aAAAC,YAAAC,eAAAC,MAAA,eAAAC,MAAA,2BAAAC,MAAA,uDAAAC,MAAA,yDAAAC,YAAAC,cAAAC,YAAAC,MAAA,8BAAAH,OAAAI,MAAAF,SAAAC,OAAAF,WAAA,uBAAA,MAAWI,EAAG,KACQC,OAAOC,IAAI,iBAC3BC,EAAgBF,OAAOC,IAAI,cACdE,EAAG,IAAIC,MACa,yBAEjCC,EAAgB,CAYrBC,MAAMnB,EAA8BoB,EAAcC,GACjD,MAAMC,EAAQrB,EAAQsB,EAAmBX,GAEzCN,EAAqBgB,EAAME,UAAWF,EAAMG,YAAaH,EAAMG,aAE/D,MAAMC,EAAOJ,EAAMK,QAAQC,IAE3B,IAEC,OADiB5B,EAAUmB,MAAMC,EAASC,EAU1C,CARC,MAAOQ,GAGR,MAAMA,CACN,CAPD,QAUCH,GACA,CACD,GAGF,WAAkC1B,GACjC,SAAqB8B,IAAI9B,IAE1B,SAAuBA,GACtB,GAAI+B,EAAe,CAClB,MAAMC,EAAiB,IAAIC,MAAMjC,EAAWkB,GAE5CF,EAAckB,IAAIlC,EAAWgC,GAC7BhB,EAAckB,IAAIF,EAAgBA,GAElC,OACAA,CAAA,CAgBD,MAAsBG,EAAG,WACxB,OAAOjB,EAAcC,MAAMnB,OAAWoC,EAAWC,UACjD,EACDrB,EAAckB,IAAIlC,EAAWmC,GAC7BnB,EAAckB,IAAIC,EAAkBA,GAEpC,QACA,CAjCuCG,CAActC,EACrD,CA+CD,SAAAuB,IACC,MAEIgB,IADU,EAGCC,EAAG9B,EAAO,WACxBiB,EAAUc,IACV,GACDd,EAAQe,EAAY,WACnBC,EAAWA,EAAU,EAAK,EAC1B,GAAIJ,EAAqBA,GACz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EAAKZ,KACZ,IAMAP,MAAO,CACNiB,cAAc,EACdlC,MACC,MAAO,CAAEoC,KAAMzB,KACf,GAEF0B,IAAK,CAAEH,cAAc,EAAMV,MAAO,QAG7B,mBAAuBA,GAC5B,SAAe,IAAM9C,EAAU8C,GAAQ1C,EACvC,CAEK,qBAAyBwD,GAC9B,QAAiBlE,EAAOkE,GACxBC,EAASC,QAAUF,EACnB,OAAcnE,EAAC,IAAMQ,EAAY,IAAM4D,EAASC,WAAY1D,EAC5D,CAEe2D,SAAAA,gBAAgBC,GAC/B,MAAMC,EAAWvE,EAAOsE,GACxBC,EAASH,QAAUE,EAEnBrE,EAAU,IACFO,EAAO,IACN+D,EAASH,WAEf1D,EACH,QAAA8D,YAAAC,UAAAJ"}
@@ -1 +1 @@
1
- import n,{Component as r,useMemo as t,useRef as e,useEffect as o}from"react";import u from"react/jsx-runtime";import i from"react/jsx-dev-runtime";import{useSyncExternalStore as f}from"use-sync-external-store/shim";import{Signal as c,signal as a,computed as p,effect as l}from"@preact/signals-core";export{Signal,batch,computed,effect,signal}from"@preact/signals-core";var s=[],m=Symbol.for("react.element"),v=Symbol.for("react.memo"),y=new Map,b="function"==typeof Proxy,g={apply:function(n,r,e){var o=t(d,s);f(o.subscribe,o.getSnapshot,o.getSnapshot);var u=o.updater.S();try{return n.apply(r,e)}catch(n){throw n}finally{u()}}};function h(n){return y.get(n)||function(n){if(b){var r=new Proxy(n,g);y.set(n,r);y.set(r,r);return r}var t=function(){return g.apply(n,void 0,arguments)};y.set(n,t);y.set(t,t);return t}(n)}function d(){var n,r,t=0,e=l(function(){n=this});n.c=function(){t=t+1|0;if(r)r()};return{updater:n,subscribe:function(n){r=n;return function(){t=t+1|0;r=void 0;e()}},getSnapshot:function(){return t}}}function x(n){if("function"!=typeof n)return n;else return function(t,e){var o=[].slice.call(arguments,2);if("function"==typeof t&&!(t instanceof r))return n.call.apply(n,[n,h(t),e].concat(o));if(t&&"object"==typeof t&&t.$$typeof===v){t.type=h(t.type);return n.call.apply(n,[n,t,e].concat(o))}if("string"==typeof t&&e)for(var u in e){var i=e[u];if("children"!==u&&i instanceof c)e[u]=i.value}return n.call.apply(n,[n,t,e].concat(o))}}var j=u,S=i;n.createElement=x(n.createElement);S.jsx&&(S.jsx=x(S.jsx));j.jsx&&(j.jsx=x(j.jsx));S.jsxs&&(S.jsxs=x(S.jsxs));j.jsxs&&(j.jsxs=x(j.jsxs));S.jsxDEV&&(S.jsxDEV=x(S.jsxDEV));j.jsxDEV&&(j.jsxDEV=x(j.jsxDEV));Object.defineProperties(c.prototype,{$$typeof:{configurable:!0,value:m},type:{configurable:!0,value:h(function(n){return n.data.value})},props:{configurable:!0,get:function(){return{data:this}}},ref:{configurable:!0,value:null}});function useSignal(n){return t(function(){return a(n)},s)}function useComputed(n){var r=e(n);r.current=n;return t(function(){return p(function(){return r.current()})},s)}function useSignalEffect(n){var r=e(n);r.current=n;o(function(){return l(function(){return r.current()})},s)}export{useComputed,useSignal,useSignalEffect};//# sourceMappingURL=signals.module.js.map
1
+ import n,{Component as r,useMemo as t,useRef as e,useEffect as o}from"react";import u from"react/jsx-runtime";import i from"react/jsx-dev-runtime";import{useSyncExternalStore as f}from"use-sync-external-store/shim/index.js";import{Signal as c,signal as a,computed as p,effect as l}from"@preact/signals-core";export{Signal,batch,computed,effect,signal}from"@preact/signals-core";var s=[],m=Symbol.for("react.element"),v=Symbol.for("react.memo"),y=new Map,b="function"==typeof Proxy,g={apply:function(n,r,e){var o=t(h,s);f(o.subscribe,o.getSnapshot,o.getSnapshot);var u=o.updater.S();try{return n.apply(r,e)}catch(n){throw n}finally{u()}}};function d(n){return y.get(n)||function(n){if(b){var r=new Proxy(n,g);y.set(n,r);y.set(r,r);return r}var t=function(){return g.apply(n,void 0,arguments)};y.set(n,t);y.set(t,t);return t}(n)}function h(){var n,r,t=0,e=l(function(){n=this});n.c=function(){t=t+1|0;if(r)r()};return{updater:n,subscribe:function(n){r=n;return function(){t=t+1|0;r=void 0;e()}},getSnapshot:function(){return t}}}function x(n){if("function"!=typeof n)return n;else return function(t,e){var o=[].slice.call(arguments,2);if("function"==typeof t&&!(t instanceof r))return n.call.apply(n,[n,d(t),e].concat(o));if(t&&"object"==typeof t&&t.$$typeof===v){t.type=d(t.type);return n.call.apply(n,[n,t,e].concat(o))}if("string"==typeof t&&e)for(var u in e){var i=e[u];if("children"!==u&&i instanceof c)e[u]=i.value}return n.call.apply(n,[n,t,e].concat(o))}}var j=u,S=i;n.createElement=x(n.createElement);S.jsx&&(S.jsx=x(S.jsx));j.jsx&&(j.jsx=x(j.jsx));S.jsxs&&(S.jsxs=x(S.jsxs));j.jsxs&&(j.jsxs=x(j.jsxs));S.jsxDEV&&(S.jsxDEV=x(S.jsxDEV));j.jsxDEV&&(j.jsxDEV=x(j.jsxDEV));Object.defineProperties(c.prototype,{$$typeof:{configurable:!0,value:m},type:{configurable:!0,value:d(function(n){return n.data.value})},props:{configurable:!0,get:function(){return{data:this}}},ref:{configurable:!0,value:null}});function useSignal(n){return t(function(){return a(n)},s)}function useComputed(n){var r=e(n);r.current=n;return t(function(){return p(function(){return r.current()})},s)}function useSignalEffect(n){var r=e(n);r.current=n;o(function(){return l(function(){return r.current()})},s)}export{useComputed,useSignal,useSignalEffect};//# sourceMappingURL=signals.module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"signals.module.js","sources":["../src/index.ts"],"sourcesContent":["import {\n\tuseRef,\n\tuseMemo,\n\tuseEffect,\n\tComponent,\n\ttype FunctionComponent,\n} from \"react\";\nimport React from \"react\";\nimport jsxRuntime from \"react/jsx-runtime\";\nimport jsxRuntimeDev from \"react/jsx-dev-runtime\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n} from \"@preact/signals-core\";\nimport type { Effect, JsxRuntimeModule } from \"./internal\";\n\nexport { signal, computed, batch, effect, Signal, type ReadonlySignal };\n\nconst Empty = [] as const;\nconst ReactElemType = Symbol.for(\"react.element\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L15\nconst ReactMemoType = Symbol.for(\"react.memo\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L30\nconst ProxyInstance = new Map<FunctionComponent<any>, FunctionComponent<any>>();\nconst SupportsProxy = typeof Proxy === \"function\";\n\nconst ProxyHandlers = {\n\t/**\n\t * This is a function call trap for functional components.\n\t * When this is called, we know it means React did run 'Component()',\n\t * that means we can use any hooks here to setup our effect and store.\n\t *\n\t * With the native Proxy, all other calls such as access/setting to/of properties will\n\t * be forwarded to the target Component, so we don't need to copy the Component's\n\t * own or inherited properties.\n\t *\n\t * @see https://github.com/facebook/react/blob/2d80a0cd690bb5650b6c8a6c079a87b5dc42bd15/packages/react-reconciler/src/ReactFiberHooks.old.js#L460\n\t */\n\tapply(Component: FunctionComponent, thisArg: any, argumentsList: any) {\n\t\tconst store = useMemo(createEffectStore, Empty);\n\n\t\tuseSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n\n\t\tconst stop = store.updater._start();\n\n\t\ttry {\n\t\t\tconst children = Component.apply(thisArg, argumentsList);\n\t\t\treturn children;\n\t\t} catch (e) {\n\t\t\t// Re-throwing promises that'll be handled by suspense\n\t\t\t// or an actual error.\n\t\t\tthrow e;\n\t\t} finally {\n\t\t\t// Stop effects in either case before return or throw,\n\t\t\t// Otherwise the effect will leak.\n\t\t\tstop();\n\t\t}\n\t},\n};\n\nfunction ProxyFunctionalComponent(Component: FunctionComponent<any>) {\n\treturn ProxyInstance.get(Component) || WrapWithProxy(Component);\n}\nfunction WrapWithProxy(Component: FunctionComponent<any>) {\n\tif (SupportsProxy) {\n\t\tconst ProxyComponent = new Proxy(Component, ProxyHandlers);\n\n\t\tProxyInstance.set(Component, ProxyComponent);\n\t\tProxyInstance.set(ProxyComponent, ProxyComponent);\n\n\t\treturn ProxyComponent;\n\t}\n\n\t/**\n\t * Emulate a Proxy if environment doesn't support it.\n\t *\n\t * @TODO - unlike Proxy, it's not possible to access the type/Component's\n\t * static properties this way. Not sure if we want to copy all statics here.\n\t * Omitting this for now.\n\t *\n\t * @example - works with Proxy, doesn't with wrapped function.\n\t * ```\n\t * const el = <SomeFunctionalComponent />\n\t * el.type.someOwnOrInheritedProperty;\n\t * el.type.defaultProps;\n\t * ```\n\t */\n\tconst WrappedComponent = function () {\n\t\treturn ProxyHandlers.apply(Component, undefined, arguments);\n\t};\n\tProxyInstance.set(Component, WrappedComponent);\n\tProxyInstance.set(WrappedComponent, WrappedComponent);\n\n\treturn WrappedComponent;\n}\n\n/**\n * A redux-like store whose store value is a positive 32bit integer (a 'version').\n *\n * React subscribes to this store and gets a snapshot of the current 'version',\n * whenever the 'version' changes, we tell React it's time to update the component (call 'onStoreChange').\n *\n * How we achieve this is by creating a binding with an 'effect', when the `effect._callback' is called,\n * we update our store version and tell React to re-render the component ([1] We don't really care when/how React does it).\n *\n * [1]\n * @see https://reactjs.org/docs/hooks-reference.html#usesyncexternalstore\n * @see https://github.com/reactjs/rfcs/blob/main/text/0214-use-sync-external-store.md\n */\nfunction createEffectStore() {\n\tlet updater!: Effect;\n\tlet version = 0;\n\tlet onChangeNotifyReact: (() => void) | undefined;\n\n\tlet unsubscribe = effect(function (this: Effect) {\n\t\tupdater = this;\n\t});\n\tupdater._callback = function () {\n\t\tversion = (version + 1) | 0;\n\t\tif (onChangeNotifyReact) onChangeNotifyReact();\n\t};\n\n\treturn {\n\t\tupdater,\n\t\tsubscribe(onStoreChange: () => void) {\n\t\t\tonChangeNotifyReact = onStoreChange;\n\n\t\t\treturn function () {\n\t\t\t\t/**\n\t\t\t\t * Rotate to next version when unsubscribing to ensure that components are re-run\n\t\t\t\t * when subscribing again.\n\t\t\t\t *\n\t\t\t\t * In StrictMode, 'memo'-ed components seem to keep a stale snapshot version, so\n\t\t\t\t * don't re-run after subscribing again if the version is the same as last time.\n\t\t\t\t *\n\t\t\t\t * Because we unsubscribe from the effect, the version may not change. We simply\n\t\t\t\t * set a new initial version in case of stale snapshots here.\n\t\t\t\t */\n\t\t\t\tversion = (version + 1) | 0;\n\t\t\t\tonChangeNotifyReact = undefined;\n\t\t\t\tunsubscribe();\n\t\t\t};\n\t\t},\n\t\tgetSnapshot() {\n\t\t\treturn version;\n\t\t},\n\t};\n}\n\nfunction WrapJsx<T>(jsx: T): T {\n\tif (typeof jsx !== \"function\") return jsx;\n\n\treturn function (type: any, props: any, ...rest: any[]) {\n\t\tif (typeof type === \"function\" && !(type instanceof Component)) {\n\t\t\treturn jsx.call(jsx, ProxyFunctionalComponent(type), props, ...rest);\n\t\t}\n\n\t\tif (type && typeof type === \"object\" && type.$$typeof === ReactMemoType) {\n\t\t\ttype.type = ProxyFunctionalComponent(type.type);\n\t\t\treturn jsx.call(jsx, type, props, ...rest);\n\t\t}\n\n\t\tif (typeof type === \"string\" && props) {\n\t\t\tfor (let i in props) {\n\t\t\t\tlet v = props[i];\n\t\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t\tprops[i] = v.value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn jsx.call(jsx, type, props, ...rest);\n\t} as any as T;\n}\n\nconst JsxPro: JsxRuntimeModule = jsxRuntime;\nconst JsxDev: JsxRuntimeModule = jsxRuntimeDev;\n\n/**\n * createElement _may_ be called by jsx runtime as a fallback in certain cases,\n * so we need to wrap it regardless.\n *\n * The jsx exports depend on the `NODE_ENV` var to ensure the users' bundler doesn't\n * include both, so one of them will be set with `undefined` values.\n */\nReact.createElement = WrapJsx(React.createElement);\nJsxDev.jsx && /* */ (JsxDev.jsx = WrapJsx(JsxDev.jsx));\nJsxPro.jsx && /* */ (JsxPro.jsx = WrapJsx(JsxPro.jsx));\nJsxDev.jsxs && /* */ (JsxDev.jsxs = WrapJsx(JsxDev.jsxs));\nJsxPro.jsxs && /* */ (JsxPro.jsxs = WrapJsx(JsxPro.jsxs));\nJsxDev.jsxDEV && /**/ (JsxDev.jsxDEV = WrapJsx(JsxDev.jsxDEV));\nJsxPro.jsxDEV && /**/ (JsxPro.jsxDEV = WrapJsx(JsxPro.jsxDEV));\n\n/**\n * A wrapper component that renders a Signal's value directly as a Text node.\n */\nfunction Text({ data }: { data: Signal }) {\n\treturn data.value;\n}\n\n// Decorate Signals so React renders them as <Text> components.\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: ReactElemType },\n\ttype: { configurable: true, value: ProxyFunctionalComponent(Text) },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { configurable: true, value: null },\n});\n\nexport function useSignal<T>(value: T) {\n\treturn useMemo(() => signal<T>(value), Empty);\n}\n\nexport function useComputed<T>(compute: () => T) {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\treturn useMemo(() => computed<T>(() => $compute.current()), Empty);\n}\n\nexport function useSignalEffect(cb: () => void | (() => void)) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(() => {\n\t\t\treturn callback.current();\n\t\t});\n\t}, Empty);\n}\n"],"names":["Empty","Symbol","ReactMemoType","ProxyInstance","Map","SupportsProxy","Proxy","apply","Component","thisArg","argumentsList","useMemo","createEffectStore","useSyncExternalStore","store","subscribe","getSnapshot","updater","_start","e","stop","ProxyFunctionalComponent","get","ProxyComponent","ProxyHandlers","set","WrappedComponent","undefined","arguments","WrapWithProxy","onChangeNotifyReact","version","unsubscribe","effect","this","_callback","onStoreChange","WrapJsx","jsx","type","props","slice","call","rest","$$typeof","i","v","Signal","value","concat","JsxPro","jsxRuntime","JsxDev","jsxRuntimeDev","React","createElement","jsxs","jsxDEV","Object","defineProperties","prototype","configurable","ReactElemType","_ref","data","ref","useComputed","compute","$compute","useRef","current","computed","useSignalEffect","cb","callback","useEffect","useSignal"],"mappings":"iXA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D,EACvC,CAEK,SAAAkE,YAAyBC,GAC9B,IAAcC,EAAGC,EAAOF,GACxBC,EAASE,QAAUH,EACnB,OAAOxD,EAAQ,WAAM4D,OAAAA,EAAY,WAAA,OAAcH,EAACE,SAAf,EAAlB,EAA6CtE,EAC5D,CAEewE,SAAAA,gBAAgBC,GAC/B,IAAMC,EAAWL,EAAOI,GACxBC,EAASJ,QAAUG,EAEnBE,EAAU,WACT,OAAO1C,EAAO,WACb,OAAOyC,EAASJ,SAChB,EACD,EAAEtE,EACH,QAAAkE,YAAAU,UAAAJ"}
1
+ {"version":3,"file":"signals.module.js","sources":["../src/index.ts"],"sourcesContent":["import {\n\tuseRef,\n\tuseMemo,\n\tuseEffect,\n\tComponent,\n\ttype FunctionComponent,\n} from \"react\";\nimport React from \"react\";\nimport jsxRuntime from \"react/jsx-runtime\";\nimport jsxRuntimeDev from \"react/jsx-dev-runtime\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n} from \"@preact/signals-core\";\nimport type { Effect, JsxRuntimeModule } from \"./internal\";\n\nexport { signal, computed, batch, effect, Signal, type ReadonlySignal };\n\nconst Empty = [] as const;\nconst ReactElemType = Symbol.for(\"react.element\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L15\nconst ReactMemoType = Symbol.for(\"react.memo\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L30\nconst ProxyInstance = new Map<FunctionComponent<any>, FunctionComponent<any>>();\nconst SupportsProxy = typeof Proxy === \"function\";\n\nconst ProxyHandlers = {\n\t/**\n\t * This is a function call trap for functional components.\n\t * When this is called, we know it means React did run 'Component()',\n\t * that means we can use any hooks here to setup our effect and store.\n\t *\n\t * With the native Proxy, all other calls such as access/setting to/of properties will\n\t * be forwarded to the target Component, so we don't need to copy the Component's\n\t * own or inherited properties.\n\t *\n\t * @see https://github.com/facebook/react/blob/2d80a0cd690bb5650b6c8a6c079a87b5dc42bd15/packages/react-reconciler/src/ReactFiberHooks.old.js#L460\n\t */\n\tapply(Component: FunctionComponent, thisArg: any, argumentsList: any) {\n\t\tconst store = useMemo(createEffectStore, Empty);\n\n\t\tuseSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n\n\t\tconst stop = store.updater._start();\n\n\t\ttry {\n\t\t\tconst children = Component.apply(thisArg, argumentsList);\n\t\t\treturn children;\n\t\t} catch (e) {\n\t\t\t// Re-throwing promises that'll be handled by suspense\n\t\t\t// or an actual error.\n\t\t\tthrow e;\n\t\t} finally {\n\t\t\t// Stop effects in either case before return or throw,\n\t\t\t// Otherwise the effect will leak.\n\t\t\tstop();\n\t\t}\n\t},\n};\n\nfunction ProxyFunctionalComponent(Component: FunctionComponent<any>) {\n\treturn ProxyInstance.get(Component) || WrapWithProxy(Component);\n}\nfunction WrapWithProxy(Component: FunctionComponent<any>) {\n\tif (SupportsProxy) {\n\t\tconst ProxyComponent = new Proxy(Component, ProxyHandlers);\n\n\t\tProxyInstance.set(Component, ProxyComponent);\n\t\tProxyInstance.set(ProxyComponent, ProxyComponent);\n\n\t\treturn ProxyComponent;\n\t}\n\n\t/**\n\t * Emulate a Proxy if environment doesn't support it.\n\t *\n\t * @TODO - unlike Proxy, it's not possible to access the type/Component's\n\t * static properties this way. Not sure if we want to copy all statics here.\n\t * Omitting this for now.\n\t *\n\t * @example - works with Proxy, doesn't with wrapped function.\n\t * ```\n\t * const el = <SomeFunctionalComponent />\n\t * el.type.someOwnOrInheritedProperty;\n\t * el.type.defaultProps;\n\t * ```\n\t */\n\tconst WrappedComponent = function () {\n\t\treturn ProxyHandlers.apply(Component, undefined, arguments);\n\t};\n\tProxyInstance.set(Component, WrappedComponent);\n\tProxyInstance.set(WrappedComponent, WrappedComponent);\n\n\treturn WrappedComponent;\n}\n\n/**\n * A redux-like store whose store value is a positive 32bit integer (a 'version').\n *\n * React subscribes to this store and gets a snapshot of the current 'version',\n * whenever the 'version' changes, we tell React it's time to update the component (call 'onStoreChange').\n *\n * How we achieve this is by creating a binding with an 'effect', when the `effect._callback' is called,\n * we update our store version and tell React to re-render the component ([1] We don't really care when/how React does it).\n *\n * [1]\n * @see https://reactjs.org/docs/hooks-reference.html#usesyncexternalstore\n * @see https://github.com/reactjs/rfcs/blob/main/text/0214-use-sync-external-store.md\n */\nfunction createEffectStore() {\n\tlet updater!: Effect;\n\tlet version = 0;\n\tlet onChangeNotifyReact: (() => void) | undefined;\n\n\tlet unsubscribe = effect(function (this: Effect) {\n\t\tupdater = this;\n\t});\n\tupdater._callback = function () {\n\t\tversion = (version + 1) | 0;\n\t\tif (onChangeNotifyReact) onChangeNotifyReact();\n\t};\n\n\treturn {\n\t\tupdater,\n\t\tsubscribe(onStoreChange: () => void) {\n\t\t\tonChangeNotifyReact = onStoreChange;\n\n\t\t\treturn function () {\n\t\t\t\t/**\n\t\t\t\t * Rotate to next version when unsubscribing to ensure that components are re-run\n\t\t\t\t * when subscribing again.\n\t\t\t\t *\n\t\t\t\t * In StrictMode, 'memo'-ed components seem to keep a stale snapshot version, so\n\t\t\t\t * don't re-run after subscribing again if the version is the same as last time.\n\t\t\t\t *\n\t\t\t\t * Because we unsubscribe from the effect, the version may not change. We simply\n\t\t\t\t * set a new initial version in case of stale snapshots here.\n\t\t\t\t */\n\t\t\t\tversion = (version + 1) | 0;\n\t\t\t\tonChangeNotifyReact = undefined;\n\t\t\t\tunsubscribe();\n\t\t\t};\n\t\t},\n\t\tgetSnapshot() {\n\t\t\treturn version;\n\t\t},\n\t};\n}\n\nfunction WrapJsx<T>(jsx: T): T {\n\tif (typeof jsx !== \"function\") return jsx;\n\n\treturn function (type: any, props: any, ...rest: any[]) {\n\t\tif (typeof type === \"function\" && !(type instanceof Component)) {\n\t\t\treturn jsx.call(jsx, ProxyFunctionalComponent(type), props, ...rest);\n\t\t}\n\n\t\tif (type && typeof type === \"object\" && type.$$typeof === ReactMemoType) {\n\t\t\ttype.type = ProxyFunctionalComponent(type.type);\n\t\t\treturn jsx.call(jsx, type, props, ...rest);\n\t\t}\n\n\t\tif (typeof type === \"string\" && props) {\n\t\t\tfor (let i in props) {\n\t\t\t\tlet v = props[i];\n\t\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t\tprops[i] = v.value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn jsx.call(jsx, type, props, ...rest);\n\t} as any as T;\n}\n\nconst JsxPro: JsxRuntimeModule = jsxRuntime;\nconst JsxDev: JsxRuntimeModule = jsxRuntimeDev;\n\n/**\n * createElement _may_ be called by jsx runtime as a fallback in certain cases,\n * so we need to wrap it regardless.\n *\n * The jsx exports depend on the `NODE_ENV` var to ensure the users' bundler doesn't\n * include both, so one of them will be set with `undefined` values.\n */\nReact.createElement = WrapJsx(React.createElement);\nJsxDev.jsx && /* */ (JsxDev.jsx = WrapJsx(JsxDev.jsx));\nJsxPro.jsx && /* */ (JsxPro.jsx = WrapJsx(JsxPro.jsx));\nJsxDev.jsxs && /* */ (JsxDev.jsxs = WrapJsx(JsxDev.jsxs));\nJsxPro.jsxs && /* */ (JsxPro.jsxs = WrapJsx(JsxPro.jsxs));\nJsxDev.jsxDEV && /**/ (JsxDev.jsxDEV = WrapJsx(JsxDev.jsxDEV));\nJsxPro.jsxDEV && /**/ (JsxPro.jsxDEV = WrapJsx(JsxPro.jsxDEV));\n\n/**\n * A wrapper component that renders a Signal's value directly as a Text node.\n */\nfunction Text({ data }: { data: Signal }) {\n\treturn data.value;\n}\n\n// Decorate Signals so React renders them as <Text> components.\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: ReactElemType },\n\ttype: { configurable: true, value: ProxyFunctionalComponent(Text) },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { configurable: true, value: null },\n});\n\nexport function useSignal<T>(value: T) {\n\treturn useMemo(() => signal<T>(value), Empty);\n}\n\nexport function useComputed<T>(compute: () => T) {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\treturn useMemo(() => computed<T>(() => $compute.current()), Empty);\n}\n\nexport function useSignalEffect(cb: () => void | (() => void)) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(() => {\n\t\t\treturn callback.current();\n\t\t});\n\t}, Empty);\n}\n"],"names":["Empty","Symbol","ReactMemoType","ProxyInstance","Map","SupportsProxy","Proxy","apply","Component","thisArg","argumentsList","useMemo","createEffectStore","useSyncExternalStore","store","subscribe","getSnapshot","updater","_start","e","stop","ProxyFunctionalComponent","get","ProxyComponent","ProxyHandlers","set","WrappedComponent","undefined","arguments","WrapWithProxy","onChangeNotifyReact","version","unsubscribe","effect","this","_callback","onStoreChange","WrapJsx","jsx","type","props","slice","call","rest","$$typeof","i","v","Signal","value","concat","JsxPro","jsxRuntime","JsxDev","jsxRuntimeDev","React","createElement","jsxs","jsxDEV","Object","defineProperties","prototype","configurable","ReactElemType","_ref","data","ref","useComputed","compute","$compute","useRef","current","computed","useSignalEffect","cb","callback","useEffect","useSignal"],"mappings":"0XAuBA,IAAWA,EAAG,KACQC,WAAW,iBACdC,EAAGD,OAAM,IAAK,cAC3BE,EAAgB,IAAIC,IACPC,EAAoB,mBAAjBC,QAEA,CAYrBC,MAZqB,SAYfC,EAA8BC,EAAcC,GACjD,MAAcC,EAAQC,EAAmBZ,GAEzCa,EAAqBC,EAAMC,UAAWD,EAAME,YAAaF,EAAME,aAE/D,MAAaF,EAAMG,QAAQC,IAE3B,IAEC,OADiBV,EAAUD,MAAME,EAASC,EAU1C,CARC,MAAOS,GAGR,MAAMA,CACN,CAPD,QAUCC,GACA,CACD,GAGF,SAASC,EAAyBb,GACjC,SAAqBc,IAAId,IAE1B,SAAuBA,GACtB,GAAIH,EAAe,CAClB,IAAMkB,EAAiB,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4
  "license": "MIT",
5
5
  "description": "",
6
6
  "keywords": [],
package/src/index.ts CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  import React from "react";
9
9
  import jsxRuntime from "react/jsx-runtime";
10
10
  import jsxRuntimeDev from "react/jsx-dev-runtime";
11
- import { useSyncExternalStore } from "use-sync-external-store/shim";
11
+ import { useSyncExternalStore } from "use-sync-external-store/shim/index.js";
12
12
  import {
13
13
  signal,
14
14
  computed,