@stackflow/react
Advanced tools
Comparing version 0.19.2-alpha.1 to 0.19.2-alpha.2
@@ -1,2 +0,2 @@ | ||
"use strict";var wt=Object.create;var R=Object.defineProperty,Et=Object.defineProperties,It=Object.getOwnPropertyDescriptor,bt=Object.getOwnPropertyDescriptors,Ut=Object.getOwnPropertyNames,_=Object.getOwnPropertySymbols,Ot=Object.getPrototypeOf,et=Object.prototype.hasOwnProperty,Dt=Object.prototype.propertyIsEnumerable;var tt=(t,e,o)=>e in t?R(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,u=(t,e)=>{for(var o in e||(e={}))et.call(e,o)&&tt(t,o,e[o]);if(_)for(var o of _(e))Dt.call(e,o)&&tt(t,o,e[o]);return t},y=(t,e)=>Et(t,bt(e));var Mt=(t,e)=>{for(var o in e)R(t,o,{get:e[o],enumerable:!0})},ot=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Ut(e))!et.call(t,s)&&s!==o&&R(t,s,{get:()=>e[s],enumerable:!(n=It(e,s))||n.enumerable});return t};var m=(t,e,o)=>(o=t!=null?wt(Ot(t)):{},ot(e||!t||!t.__esModule?R(o,"default",{value:t,enumerable:!0}):o,t)),Nt=t=>ot(R({},"__esModule",{value:!0}),t);var zt={};Mt(zt,{stackflow:()=>jt,useActions:()=>J,useActiveEffect:()=>$t,useActivity:()=>W,useActivityParams:()=>Bt,useStack:()=>Ft,useStepActions:()=>L});module.exports=Nt(zt);var at=require("react");var b=m(require("react"));function it(){let t={value:null};function e(){return t.value}function o(n){t.value=n}return[e,o]}var E=require("react"),rt=m(require("react-fast-compare"));function I(t){let e=(0,E.useRef)(t),o=e.current,n=(0,rt.default)(o,t);return(0,E.useEffect)(()=>{n||(e.current=t)}),n?o:t}var w=(0,b.createContext)(null),nt=({children:t,value:e})=>b.default.createElement(w.Provider,{value:I(e)},t);var W=()=>(0,at.useContext)(w);var st=require("react");function Bt(){return(0,st.useContext)(w).params}var pt=require("react");var U=m(require("react"));var j=(0,U.createContext)(null),ct=({children:t,value:e})=>U.default.createElement(j.Provider,{value:I(e)},t);var Ft=()=>(0,pt.useContext)(j);var A=require("@stackflow/core"),l=m(require("react"));var mt=require("@stackflow/core");function d(){return(0,mt.id)()}var ut=require("@stackflow/core");function k(){return(0,ut.id)()}var C=m(require("react"));var ft=m(require("react")),lt,vt=(lt=ft.default.useDeferredValue)!=null?lt:t=>t;var x=m(require("react")),dt,yt=(dt=x.default.useSyncExternalStore)!=null?dt:(t,e)=>{let[o,n]=(0,x.useState)(()=>e());return(0,x.useEffect)(()=>t(()=>{n(()=>e())})),o};var $=(0,C.createContext)(null),z=(0,C.createContext)(null),St=({coreStore:t,children:e})=>{let o=yt(t.subscribe,t.actions.getStack,t.actions.getStack),n=vt(o);return C.default.createElement(z.Provider,{value:n},C.default.createElement($.Provider,{value:t.actions},e))};var At=m(require("react"));var O=()=>At.default.useContext($);var Pt=m(require("react"));var D=()=>Pt.default.useContext(z);var g=m(require("react"));var B=m(require("react"));var M=m(require("react")),G=(0,M.createContext)(null),kt=({children:t,value:e})=>M.default.createElement(G.Provider,{value:e},t);var xt=require("react");function N(){return(0,xt.useContext)(G)}var Kt=({activityComponentMap:t,plugin:e})=>{let o=D(),n=N();return e.render({stack:y(u({},o),{render(s){let p=u(u({},o),s);return{activities:p.activities.map(c=>y(u({},c),{key:c.id,render(f){let V=t[c.name],S=B.default.createElement(V,{params:c.params});return n.forEach(i=>{var r,a;S=(a=(r=i.wrapActivity)==null?void 0:r.call(i,{activity:y(u({},c),{render:()=>S})}))!=null?a:S}),B.default.createElement(ct,{value:p},B.default.createElement(nt,{key:c.id,value:u(u({},c),f)},S))}}))}}})})},Ct=Kt;var Vt=({activityComponentMap:t})=>{let e=D(),o=N(),n=o.filter(p=>!!p.render);(0,g.useEffect)(()=>{n.length===0&&console.warn(`Stackflow - There is no rendering plugin, so "<Stack />" doesn't render anything. If you want to render some UI, use "@stackflow/plugin-renderer-basic" or add another rendering plugin.`)},[n]);let s=g.default.createElement(g.default.Fragment,null,n.map(p=>g.default.createElement(Ct,{key:p.key,activityComponentMap:t,plugin:p})));return o.forEach(p=>{var c,f;s=(f=(c=p.wrapStack)==null?void 0:c.call(p,{stack:y(u({},e),{render(){return s}})}))!=null?f:s}),s},gt=Vt;var F=m(require("react"));function H(t){return t?t.animate===void 0||t.animate==null?{skipActiveState:!1}:{skipActiveState:!t.animate}:{skipActiveState:!1}}var Tt,qt=(Tt=F.default.useTransition)!=null?Tt:()=>[!1,t=>t()];function J(){let t=O(),[e,o]=qt();return(0,F.useMemo)(()=>({pending:e,push(n,s,p){let c=d();return t.push({activityId:c,activityName:n,activityParams:s,skipEnterActiveState:H(p).skipActiveState}),{activityId:c}},replace(n,s,p){var f;let c=d();return t.replace({activityId:(f=p==null?void 0:p.activityId)!=null?f:d(),activityName:n,activityParams:s,skipEnterActiveState:H(p).skipActiveState}),{activityId:c}},pop(n){t.pop({skipExitActiveState:H(n).skipActiveState})}}),[t.push,t.replace,t.pop,e,o])}var K=m(require("react"));var ht,Wt=(ht=K.default.useTransition)!=null?ht:()=>[!1,t=>t()],L=()=>{let t=O(),[e,o]=Wt();return(0,K.useMemo)(()=>({pending:e,stepPush(n){let s=k();t.stepPush({stepId:s,stepParams:n})},stepReplace(n){let s=k();t.stepReplace({stepId:s,stepParams:n})},stepPop(){t.stepPop({})}}),[t.stepPush,t.stepReplace,t.stepPop,e,o])};function Q(t){return t?t.animate===void 0||t.animate==null?{skipActiveState:!1}:{skipActiveState:!t.animate}:{skipActiveState:!1}}function jt(t){var S;typeof window!="undefined"&&window.document.documentElement.style.setProperty("--stackflow-transition-duration",`${t.transitionDuration}ms`);let e=((S=t.plugins)!=null?S:[]).flat(1/0).map(i=>i),o=e.map(i=>i()),n=Object.entries(t.activities).reduce((i,[r,a])=>y(u({},i),{[r]:"component"in a?l.default.memo(a.component):l.default.memo(a)}),{}),s=()=>new Date().getTime()-t.transitionDuration*2,p=(0,A.makeCoreStore)({initialEvents:[(0,A.makeEvent)("Initialized",{transitionDuration:t.transitionDuration,eventDate:s()}),...Object.entries(t.activities).map(([i,r])=>(0,A.makeEvent)("ActivityRegistered",u({activityName:i,eventDate:s()},"component"in r?{activityParamsSchema:r.paramsSchema}:null)))],plugins:[]}),[c,f]=it(),V=i=>{let r=(0,l.useMemo)(()=>{let a=t.initialActivity?[(0,A.makeEvent)("Pushed",{activityId:d(),activityName:t.initialActivity(),activityParams:{},eventDate:s(),skipEnterActiveState:!1})]:[],v=o.reduce((h,q)=>{var X,Y,Z;return(Z=(Y=q.overrideInitialEvents)==null?void 0:Y.call(q,{initialEvents:h,initialContext:(X=i.initialContext)!=null?X:{}}))!=null?Z:h},a);v.length>0&&a.length>0&&v!==a&&console.warn(`Stackflow - Some plugin overrides an "initialActivity" option. The "initialActivity" option you set to "${a[0].activityName}" in the "stackflow" is ignored.`),v.length===0&&console.warn("Stackflow - There is no initial activity. If you want to set the initial activity, add the `initialActivity` option of the `stackflow()` function or add a plugin that sets the initial activity. (e.g. `@stackflow/plugin-history-sync`)");let T=(0,A.makeCoreStore)({initialEvents:[...p.pullEvents(),...v],plugins:e});return f(T),T},[]);return(0,l.useEffect)(()=>{r.init()},[r]),l.default.createElement(kt,{value:o},l.default.createElement(St,{coreStore:r},l.default.createElement(gt,{activityComponentMap:n})))};return{activities:t.activities,Stack:V,useFlow:J,useStepFlow:L,addActivity(i){if(c()){console.warn("Stackflow - `addActivity()` API cannot be called after a `<Stack />` component has been rendered");return}n[i.name]=l.default.memo(i.component),p.actions.dispatchEvent("ActivityRegistered",{activityName:i.name,activityParamsSchema:i.paramsSchema,eventDate:s()})},addPlugin(i){if(c()){console.warn("Stackflow - `addPlugin()` API cannot be called after a `<Stack />` component has been rendered");return}[i].flat(1/0).map(r=>r).forEach(r=>{e.push(r),o.push(r())})},actions:{getStack(){var i,r;return(r=(i=c())==null?void 0:i.actions.getStack())!=null?r:p.actions.getStack()},dispatchEvent(i,r){var a;return(a=c())==null?void 0:a.actions.dispatchEvent(i,r)},push(i,r,a){var P;let v=d();return(P=c())==null||P.actions.push({activityId:v,activityName:i,activityParams:r,skipEnterActiveState:Q(a).skipActiveState}),{activityId:v}},replace(i,r,a){var P,T,h;let v=(P=a==null?void 0:a.activityId)!=null?P:d();return(h=c())==null||h.actions.replace({activityId:(T=a==null?void 0:a.activityId)!=null?T:d(),activityName:i,activityParams:r,skipEnterActiveState:Q(a).skipActiveState}),{activityId:v}},pop(i){var r;return(r=c())==null?void 0:r.actions.pop({skipExitActiveState:Q(i).skipActiveState})},stepPush(i){var a;let r=k();return(a=c())==null?void 0:a.actions.stepPush({stepId:r,stepParams:i})},stepReplace(i){var a;let r=k();return(a=c())==null?void 0:a.actions.stepReplace({stepId:r,stepParams:i})},stepPop(){var i;return(i=c())==null?void 0:i.actions.stepPop({})}}}}var Rt=require("react");var $t=t=>{let{isActive:e}=W();(0,Rt.useEffect)(()=>{if(e)return t()},[e])}; | ||
"use strict";var wt=Object.create;var R=Object.defineProperty,Et=Object.defineProperties,It=Object.getOwnPropertyDescriptor,bt=Object.getOwnPropertyDescriptors,Ut=Object.getOwnPropertyNames,_=Object.getOwnPropertySymbols,Ot=Object.getPrototypeOf,et=Object.prototype.hasOwnProperty,Dt=Object.prototype.propertyIsEnumerable;var tt=(t,e,i)=>e in t?R(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,u=(t,e)=>{for(var i in e||(e={}))et.call(e,i)&&tt(t,i,e[i]);if(_)for(var i of _(e))Dt.call(e,i)&&tt(t,i,e[i]);return t},y=(t,e)=>Et(t,bt(e));var Mt=(t,e)=>{for(var i in e)R(t,i,{get:e[i],enumerable:!0})},it=(t,e,i,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Ut(e))!et.call(t,s)&&s!==i&&R(t,s,{get:()=>e[s],enumerable:!(r=It(e,s))||r.enumerable});return t};var m=(t,e,i)=>(i=t!=null?wt(Ot(t)):{},it(e||!t||!t.__esModule?R(i,"default",{value:t,enumerable:!0}):i,t)),Nt=t=>it(R({},"__esModule",{value:!0}),t);var zt={};Mt(zt,{stackflow:()=>jt,useActions:()=>J,useActiveEffect:()=>$t,useActivity:()=>W,useActivityParams:()=>Bt,useStack:()=>Ft,useStepActions:()=>L});module.exports=Nt(zt);var at=require("react");var b=m(require("react"));function ot(){let t={value:null};function e(){return t.value}function i(r){t.value=r}return[e,i]}var E=require("react"),rt=m(require("react-fast-compare"));function I(t){let e=(0,E.useRef)(t),i=e.current,r=(0,rt.default)(i,t);return(0,E.useEffect)(()=>{r||(e.current=t)}),r?i:t}var w=(0,b.createContext)(null),nt=({children:t,value:e})=>b.default.createElement(w.Provider,{value:I(e)},t);var W=()=>(0,at.useContext)(w);var st=require("react");function Bt(){return(0,st.useContext)(w).params}var pt=require("react");var U=m(require("react"));var j=(0,U.createContext)(null),ct=({children:t,value:e})=>U.default.createElement(j.Provider,{value:I(e)},t);var Ft=()=>(0,pt.useContext)(j);var A=require("@stackflow/core"),d=m(require("react"));var mt=require("@stackflow/core");function v(){return(0,mt.id)()}var ut=require("@stackflow/core");function x(){return(0,ut.id)()}var g=m(require("react"));var lt=m(require("react")),ft,vt=(ft=lt.default.useDeferredValue)!=null?ft:t=>t;var C=m(require("react")),dt,yt=(dt=C.default.useSyncExternalStore)!=null?dt:(t,e)=>{let[i,r]=(0,C.useState)(()=>e());return(0,C.useEffect)(()=>t(()=>{r(()=>e())})),i};var $=(0,g.createContext)(null),z=(0,g.createContext)(null),St=({coreStore:t,children:e})=>{let i=yt(t.subscribe,t.actions.getStack,t.actions.getStack),r=vt(i);return g.default.createElement(z.Provider,{value:r},g.default.createElement($.Provider,{value:t.actions},e))};var At=m(require("react"));var O=()=>At.default.useContext($);var Pt=m(require("react"));var D=()=>Pt.default.useContext(z);var T=m(require("react"));var B=m(require("react"));var M=m(require("react")),G=(0,M.createContext)(null),kt=({children:t,value:e})=>M.default.createElement(G.Provider,{value:e},t);var xt=require("react");function N(){return(0,xt.useContext)(G)}var Kt=({activityComponentMap:t,plugin:e})=>{let i=D(),r=N();return e.render({stack:y(u({},i),{render(s){let p=u(u({},i),s);return{activities:p.activities.map(c=>y(u({},c),{key:c.id,render(f){let V=t[c.name],S=B.default.createElement(V,{params:c.params});return r.forEach(o=>{var n,a;S=(a=(n=o.wrapActivity)==null?void 0:n.call(o,{activity:y(u({},c),{render:()=>S})}))!=null?a:S}),B.default.createElement(ct,{value:p},B.default.createElement(nt,{key:c.id,value:u(u({},c),f)},S))}}))}}})})},Ct=Kt;var Vt=({activityComponentMap:t})=>{let e=D(),i=N(),r=i.filter(p=>!!p.render);(0,T.useEffect)(()=>{r.length===0&&console.warn(`Stackflow - There is no rendering plugin, so "<Stack />" doesn't render anything. If you want to render some UI, use "@stackflow/plugin-renderer-basic" or add another rendering plugin.`)},[r]);let s=T.default.createElement(T.default.Fragment,null,r.map(p=>T.default.createElement(Ct,{key:p.key,activityComponentMap:t,plugin:p})));return i.forEach(p=>{var c,f;s=(f=(c=p.wrapStack)==null?void 0:c.call(p,{stack:y(u({},e),{render(){return s}})}))!=null?f:s}),s},gt=Vt;var F=m(require("react"));function H(t){return t?t.animate===void 0||t.animate==null?{skipActiveState:!1}:{skipActiveState:!t.animate}:{skipActiveState:!1}}var Tt,qt=(Tt=F.default.useTransition)!=null?Tt:()=>[!1,t=>t()];function J(){let t=O(),[e,i]=qt();return(0,F.useMemo)(()=>({pending:e,push(r,s,p){let c=v();return t.push({activityId:c,activityName:r,activityParams:s,skipEnterActiveState:H(p).skipActiveState}),{activityId:c}},replace(r,s,p){var f;let c=v();return t.replace({activityId:(f=p==null?void 0:p.activityId)!=null?f:v(),activityName:r,activityParams:s,skipEnterActiveState:H(p).skipActiveState}),{activityId:c}},pop(r){t.pop({skipExitActiveState:H(r).skipActiveState})}}),[t.push,t.replace,t.pop,e,i])}var K=m(require("react"));var ht,Wt=(ht=K.default.useTransition)!=null?ht:()=>[!1,t=>t()],L=()=>{let t=O(),[e,i]=Wt();return(0,K.useMemo)(()=>({pending:e,stepPush(r){let s=x();t.stepPush({stepId:s,stepParams:r})},stepReplace(r){let s=x();t.stepReplace({stepId:s,stepParams:r})},stepPop(){t.stepPop({})}}),[t.stepPush,t.stepReplace,t.stepPop,e,i])};function Q(t){return t?t.animate===void 0||t.animate==null?{skipActiveState:!1}:{skipActiveState:!t.animate}:{skipActiveState:!1}}function jt(t){var S;typeof window!="undefined"&&window.document.documentElement.style.setProperty("--stackflow-transition-duration",`${t.transitionDuration}ms`);let e=((S=t.plugins)!=null?S:[]).flat(1/0).map(o=>o),i=e.map(o=>o()),r=Object.entries(t.activities).reduce((o,[n,a])=>y(u({},o),{[n]:"component"in a?d.default.memo(a.component):d.default.memo(a)}),{}),s=()=>new Date().getTime()-t.transitionDuration*2,p=(0,A.makeCoreStore)({initialEvents:[(0,A.makeEvent)("Initialized",{transitionDuration:t.transitionDuration,eventDate:s()}),...Object.entries(t.activities).map(([o,n])=>(0,A.makeEvent)("ActivityRegistered",u({activityName:o,eventDate:s()},"component"in n?{activityParamsSchema:n.paramsSchema}:null)))],plugins:[]}),[c,f]=ot(),V=o=>{let n=(0,d.useMemo)(()=>{let a=t.initialActivity?[(0,A.makeEvent)("Pushed",{activityId:v(),activityName:t.initialActivity(),activityParams:{},eventDate:s(),skipEnterActiveState:!1})]:[],l=i.reduce((h,q)=>{var X,Y,Z;return(Z=(Y=q.overrideInitialEvents)==null?void 0:Y.call(q,{initialEvents:h,initialContext:(X=o.initialContext)!=null?X:{}}))!=null?Z:h},a);l.length>0&&a.length>0&&l!==a&&console.warn(`Stackflow - Some plugin overrides an "initialActivity" option. The "initialActivity" option you set to "${a[0].activityName}" in the "stackflow" is ignored.`),l.length===0&&console.warn("Stackflow - There is no initial activity. If you want to set the initial activity, add the `initialActivity` option of the `stackflow()` function or add a plugin that sets the initial activity. (e.g. `@stackflow/plugin-history-sync`)");let k=(0,A.makeCoreStore)({initialEvents:[...p.pullEvents(),...l],plugins:e});return typeof window!="undefined"&&k.init(),f(k),k},[]);return d.default.createElement(kt,{value:i},d.default.createElement(St,{coreStore:n},d.default.createElement(gt,{activityComponentMap:r})))};return{activities:t.activities,Stack:V,useFlow:J,useStepFlow:L,addActivity(o){if(c()){console.warn("Stackflow - `addActivity()` API cannot be called after a `<Stack />` component has been rendered");return}r[o.name]=d.default.memo(o.component),p.actions.dispatchEvent("ActivityRegistered",{activityName:o.name,activityParamsSchema:o.paramsSchema,eventDate:s()})},addPlugin(o){if(c()){console.warn("Stackflow - `addPlugin()` API cannot be called after a `<Stack />` component has been rendered");return}[o].flat(1/0).map(n=>n).forEach(n=>{e.push(n),i.push(n())})},actions:{getStack(){var o,n;return(n=(o=c())==null?void 0:o.actions.getStack())!=null?n:p.actions.getStack()},dispatchEvent(o,n){var a;return(a=c())==null?void 0:a.actions.dispatchEvent(o,n)},push(o,n,a){var P;let l=v();return(P=c())==null||P.actions.push({activityId:l,activityName:o,activityParams:n,skipEnterActiveState:Q(a).skipActiveState}),{activityId:l}},replace(o,n,a){var P,k,h;let l=(P=a==null?void 0:a.activityId)!=null?P:v();return(h=c())==null||h.actions.replace({activityId:(k=a==null?void 0:a.activityId)!=null?k:v(),activityName:o,activityParams:n,skipEnterActiveState:Q(a).skipActiveState}),{activityId:l}},pop(o){var n;return(n=c())==null?void 0:n.actions.pop({skipExitActiveState:Q(o).skipActiveState})},stepPush(o){var a;let n=x();return(a=c())==null?void 0:a.actions.stepPush({stepId:n,stepParams:o})},stepReplace(o){var a;let n=x();return(a=c())==null?void 0:a.actions.stepReplace({stepId:n,stepParams:o})},stepPop(){var o;return(o=c())==null?void 0:o.actions.stepPop({})}}}}var Rt=require("react");var $t=t=>{let{isActive:e}=W();(0,Rt.useEffect)(()=>{if(e)return t()},[e])}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@stackflow/react", | ||
"version": "0.19.2-alpha.1", | ||
"version": "0.19.2-alpha.2", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "exports": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
0
131257