Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@stackflow/react

Package Overview
Dependencies
Maintainers
1
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stackflow/react - npm Package Compare versions

Comparing version 0.16.0 to 0.16.1-alpha.20

1

dist/activity/ActivityProvider.d.ts
import type { Activity } from "@stackflow/core";
import React from "react";
export declare const ActivityContext: React.Context<Activity>;
interface ActivityProviderProps {

@@ -4,0 +5,0 @@ children: React.ReactNode;

1

dist/activity/index.d.ts
export * from "./ActivityComponentType";
export * from "./ActivityContext";
export * from "./ActivityProvider";

@@ -4,0 +3,0 @@ export * from "./makeActivityId";

@@ -0,4 +1,8 @@

import type { ActivityRegisteredEvent } from "@stackflow/core/dist/event-types";
import type { ActivityComponentType } from "./activity";
export declare type BaseActivities = {
[activityName: string]: ActivityComponentType<any>;
[activityName: string]: ActivityComponentType<any> | {
component: ActivityComponentType<any>;
paramsSchema: NonNullable<ActivityRegisteredEvent["activityParamsSchema"]>;
};
};

@@ -0,11 +1,9 @@

import type { AggregateOutput, CreateCoreStoreOutput } from "@stackflow/core";
import React from "react";
import type { BaseActivities } from "../BaseActivities";
export declare const CoreActionsContext: React.Context<import("@stackflow/core").StackflowActions>;
export declare const CoreStateContext: React.Context<AggregateOutput>;
export interface CoreProviderProps {
activities: BaseActivities;
transitionDuration: number;
initialActivity?: (args: {
initContext: any;
}) => string;
coreStore: CreateCoreStoreOutput;
children: React.ReactNode;
}
export declare const CoreProvider: React.FC<CoreProviderProps>;

@@ -1,5 +0,3 @@

export * from "./CoreActionsContext";
export * from "./CoreProvider";
export * from "./CoreStateContext";
export * from "./useCoreActions";
export * from "./useCoreState";

@@ -1,12 +0,1 @@

import type { PoppedEvent, PushedEvent, ReplacedEvent, StepPoppedEvent, StepPushedEvent, StepReplacedEvent } from "@stackflow/core/dist/event-types";
import type { BaseDomainEvent } from "@stackflow/core/dist/event-types/_base";
export declare const useCoreActions: () => {
dispatchEvent: import("@stackflow/core").DispatchEvent;
getStack: () => import("@stackflow/core").AggregateOutput;
push: (params: Omit<PushedEvent, keyof BaseDomainEvent>) => void;
replace: (params: Omit<ReplacedEvent, keyof BaseDomainEvent>) => void;
pop: (params?: Omit<PoppedEvent, keyof BaseDomainEvent>) => void;
stepPush: (params: Omit<StepPushedEvent, keyof BaseDomainEvent>) => void;
stepReplace: (params: Omit<StepReplacedEvent, keyof BaseDomainEvent>) => void;
stepPop: (params?: Omit<StepPoppedEvent, keyof BaseDomainEvent>) => void;
};
export declare const useCoreActions: () => import("@stackflow/core").StackflowActions;
export * from "./activity/ActivityComponentType";
export * from "./activity/useActivity";
export * from "./activity/useActivityParams";
export * from "./init-context/useInitContext";
export * from "./stack/useStack";

@@ -6,0 +5,0 @@ export * from "./stackflow";

@@ -1,2 +0,2 @@

"use strict";var _t=Object.create;var _=Object.defineProperty,Ht=Object.defineProperties,Kt=Object.getOwnPropertyDescriptor,Lt=Object.getOwnPropertyDescriptors,Vt=Object.getOwnPropertyNames,ot=Object.getOwnPropertySymbols,qt=Object.getPrototypeOf,it=Object.prototype.hasOwnProperty,Gt=Object.prototype.propertyIsEnumerable;var rt=(t,o,e)=>o in t?_(t,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[o]=e,p=(t,o)=>{for(var e in o||(o={}))it.call(o,e)&&rt(t,e,o[e]);if(ot)for(var e of ot(o))Gt.call(o,e)&&rt(t,e,o[e]);return t},S=(t,o)=>Ht(t,Lt(o));var Wt=(t,o)=>{for(var e in o)_(t,e,{get:o[e],enumerable:!0})},nt=(t,o,e,n)=>{if(o&&typeof o=="object"||typeof o=="function")for(let c of Vt(o))!it.call(t,c)&&c!==e&&_(t,c,{get:()=>o[c],enumerable:!(n=Kt(o,c))||n.enumerable});return t};var x=(t,o,e)=>(e=t!=null?_t(qt(t)):{},nt(o||!t||!t.__esModule?_(e,"default",{value:t,enumerable:!0}):e,t)),jt=t=>nt(_({},"__esModule",{value:!0}),t);var ne={};Wt(ne,{stackflow:()=>ie,useActions:()=>K,useActivity:()=>$t,useActivityParams:()=>zt,useInitContext:()=>H,useStack:()=>Jt,useStepActions:()=>L});module.exports=jt(ne);var at=require("react");var st=require("react"),I=(0,st.createContext)(null);var $t=()=>(0,at.useContext)(I);var ct=require("react");function zt(){return(0,ct.useContext)(I).params}var mt=x(require("react"));var pt=require("react"),q=(0,pt.createContext)({});function H(){return mt.default.useContext(q)}var ut=require("react");var ft=require("react"),G=(0,ft.createContext)(null);var Jt=()=>(0,ut.useContext)(G);var h=x(require("react"));var vt=require("react"),W=(0,vt.createContext)(null);var w=require("@stackflow/core"),y=x(require("react")),Rt=x(require("react-fast-compare"));var dt=x(require("react"));var j=require("react"),Pt=x(require("react-fast-compare"));function $(t){let o=(0,j.useRef)(t),e=o.current,n=(0,Pt.default)(e,t);return(0,j.useEffect)(()=>{n||(o.current=t)}),n?e:t}var lt=({children:t,value:o})=>dt.default.createElement(I.Provider,{value:$(o)},t);var yt=require("@stackflow/core");function B(){return(0,yt.id)()}var kt=require("@stackflow/core");function Z(){return(0,kt.id)()}var xt=x(require("react"));var St=({children:t,value:o})=>xt.default.createElement(q.Provider,{value:o},t);var At=require("react"),z=(0,At.createContext)(null);var Et=x(require("react"));var Ct=({children:t,value:o})=>Et.default.createElement(z.Provider,{value:o},t);var ht=require("react");function C(){return(0,ht.useContext)(z)}var Tt=require("react"),J=(0,Tt.createContext)(null);var Qt=1e3,Xt=Qt/60,wt=({transitionDuration:t,initialActivity:o,activities:e,children:n})=>{let c=C(),m=H(),r=(0,y.useMemo)(()=>{let v=new Date().getTime()-t,P=o?[(0,w.makeEvent)("Pushed",{activityId:B(),activityName:o({initContext:m}),activityParams:{},eventDate:v,skipEnterActiveState:!1})]:[],l=c.reduce((R,O)=>{var N,F;return(F=(N=O.overrideInitialEvents)==null?void 0:N.call(O,{initialEvents:R}))!=null?F:R},P);!!l&&!!P&&l!==P&&console.warn(`Stackflow - Some plugin overrides an "initialActivity" option. The "initialActivity" option you set to "${P[0].activityName}" in the "stackflow" is ignored.`);let f=l;f.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 V=Object.keys(e).map(R=>(0,w.makeEvent)("ActivityRegistered",{activityName:R,eventDate:v})),M=[(0,w.makeEvent)("Initialized",{transitionDuration:t,eventDate:v}),...V];return f.forEach(R=>{M.push(R)}),M},[]),s=(0,y.useMemo)(()=>(0,w.aggregate)(r,new Date().getTime()),[]),[i,a]=(0,y.useState)(()=>s),d=(0,y.useRef)(r),A=(0,y.useRef)(s),u=(0,y.useCallback)(()=>A.current,[A]),k=(0,y.useCallback)((v,P)=>{let l=[...d.current,(0,w.makeEvent)(v,P)],T=new Date().getTime(),f=(0,w.aggregate)(l,T);a(f),d.current=l,A.current=f},[d,a]);return(0,y.useEffect)(()=>{let v=setInterval(()=>{let P=d.current,l=(0,w.aggregate)(P,new Date().getTime());(0,Rt.default)(i,l)||(a(l),A.current=l),l.globalTransitionState==="idle"&&clearInterval(v)},Xt);return()=>{clearInterval(v)}},[d,i,a]),y.default.createElement(J.Provider,{value:i},y.default.createElement(W.Provider,{value:(0,y.useMemo)(()=>({getStack:u,dispatchEvent:k}),[u,k])},n))};var E=x(require("react"));var g=()=>{let t=C(),o=H(),{dispatchEvent:e,getStack:n}=E.default.useContext(W),c=(0,E.useCallback)(u=>{let{isPrevented:k,params:v}=A("PUSHED",u);k||e("Pushed",p({},v))},[e]),m=(0,E.useCallback)(u=>{let{isPrevented:k,params:v}=A("REPLACED",u);k||e("Replaced",p({},v))},[e]),r=(0,E.useCallback)(u=>{let k=u!=null?u:{},{isPrevented:v,params:P}=A("POPPED",k);v||e("Popped",p({},P))},[e]),s=(0,E.useCallback)(u=>{let{isPrevented:k,params:v}=A("STEP_PUSHED",u);k||e("StepPushed",p({},v))},[e]),i=(0,E.useCallback)(u=>{let{isPrevented:k,params:v}=A("STEP_REPLACED",u);k||e("StepReplaced",p({},v))},[e]),a=(0,E.useCallback)(u=>{let k=u!=null?u:{},{isPrevented:v,params:P}=A("STEP_POPPED",k);v||e("StepPopped",p({},P))},[e]),d=(0,E.useMemo)(()=>({dispatchEvent:e,getStack:n,push:c,replace:m,pop:r,stepPush:s,stepReplace:i,stepPop:a}),[e,n,c,m,r,s,i,a]),A=(0,E.useCallback)((u,k)=>{let v=!1,P=p({},k),l=()=>{v=!0},T=f=>{P=p(p({},P),f)};return t.forEach(f=>{var V,M,R,O,N,F;switch(u){case"PUSHED":(V=f.onBeforePush)==null||V.call(f,{actionParams:P,actions:S(p({},d),{preventDefault:l,overrideActionParams:T})});break;case"REPLACED":(M=f.onBeforeReplace)==null||M.call(f,{actionParams:P,actions:S(p({},d),{preventDefault:l,overrideActionParams:T})});break;case"POPPED":(R=f.onBeforePop)==null||R.call(f,{actionParams:P,actions:S(p({},d),{preventDefault:l,overrideActionParams:T})});break;case"STEP_PUSHED":(O=f.onBeforeStepPush)==null||O.call(f,{actionParams:P,actions:S(p({},d),{preventDefault:l,overrideActionParams:T})});break;case"STEP_REPLACED":(N=f.onBeforeStepReplace)==null||N.call(f,{actionParams:P,actions:S(p({},d),{preventDefault:l,overrideActionParams:T})});break;case"STEP_POPPED":(F=f.onBeforeStepPop)==null||F.call(f,{actionParams:P,actions:S(p({},d),{preventDefault:l,overrideActionParams:T})});break;default:break}}),{isPrevented:v,params:P}},[t,o]);return d};var gt=x(require("react"));var b=()=>gt.default.useContext(J);var Dt=require("@stackflow/core"),D=require("react");var Yt=()=>{let t=C(),o=b(),e=g(),n=(0,D.useCallback)(r=>{t.forEach(s=>{var i;(i=s.onInit)==null||i.call(s,r)})},[]),c=(0,D.useCallback)(({actions:r,effect:s})=>{switch(s._TAG){case"PUSHED":{t.forEach(i=>{var a;return(a=i.onPushed)==null?void 0:a.call(i,{actions:r,effect:s})});break}case"REPLACED":{t.forEach(i=>{var a;return(a=i.onReplaced)==null?void 0:a.call(i,{actions:r,effect:s})});break}case"POPPED":{t.forEach(i=>{var a;return(a=i.onPopped)==null?void 0:a.call(i,{actions:r,effect:s})});break}case"STEP_PUSHED":{t.forEach(i=>{var a;return(a=i.onStepPushed)==null?void 0:a.call(i,{actions:r,effect:s})});break}case"STEP_REPLACED":{t.forEach(i=>{var a;return(a=i.onStepReplaced)==null?void 0:a.call(i,{actions:r,effect:s})});break}case"STEP_POPPED":{t.forEach(i=>{var a;return(a=i.onStepPopped)==null?void 0:a.call(i,{actions:r,effect:s})});break}case"%SOMETHING_CHANGED%":{t.forEach(i=>{var a;return(a=i.onChanged)==null?void 0:a.call(i,{actions:r,effect:s})});break}default:break}},[]);(0,D.useEffect)(()=>{n==null||n({actions:e})},[]);let m=(0,D.useRef)(o);return(0,D.useEffect)(()=>{let r=m.current;(r?(0,Dt.produceEffects)(r,o):[]).forEach(i=>{c({actions:e,effect:i})}),m.current=p({},o)},[o]),null},Ot=Yt;var U=x(require("react"));var Q=x(require("react"));var It=x(require("react"));var Bt=({children:t,value:o})=>It.default.createElement(G.Provider,{value:$(o)},t);var Zt=({activities:t,plugin:o})=>{let e=b(),n=C();return o.render({stack:S(p({},e),{render(c){let m=p(p({},e),c);return{activities:m.activities.map(r=>S(p({},r),{key:r.id,render(s){let i=t[r.name],a=Q.default.createElement(i,{params:r.params});return n.forEach(d=>{var A,u;a=(u=(A=d.wrapActivity)==null?void 0:A.call(d,{activity:S(p({},r),{render:()=>a})}))!=null?u:a}),Q.default.createElement(Bt,{value:m},Q.default.createElement(lt,{key:r.id,value:p(p({},r),s)},a))}}))}}})})},bt=Zt;var te=({activities:t})=>{let o=b(),e=C(),n=e.filter(m=>!!m.render);(0,U.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 c=U.default.createElement(U.default.Fragment,null,n.map(m=>U.default.createElement(bt,{activities:t,key:m.key,plugin:m})));return e.forEach(m=>{var r,s;c=(s=(r=m.wrapStack)==null?void 0:r.call(m,{stack:S(p({},o),{render(){return c}})}))!=null?s:c}),c},Ut=te;var et=x(require("react"));var X=x(require("react"));function tt(t){return t?t.animate===void 0||t.animate==null?{skipActiveState:!1}:{skipActiveState:!t.animate}:{skipActiveState:!1}}var Mt,ee=(Mt=X.default.useTransition)!=null?Mt:()=>[!1,t=>t()];function K(){let t=g(),[o,e]=ee();return(0,X.useMemo)(()=>({pending:o,push(n,c,m){let r=B();return e(()=>{t.push({activityId:r,activityName:n,activityParams:c,skipEnterActiveState:tt(m).skipActiveState})}),{activityId:r}},replace(n,c,m){let r=B();return e(()=>{var s;t.replace({activityId:(s=m==null?void 0:m.activityId)!=null?s:B(),activityName:n,activityParams:c,skipEnterActiveState:tt(m).skipActiveState})}),{activityId:r}},pop(n){e(()=>{t.pop({skipExitActiveState:tt(n).skipActiveState})})}}),[t.push,t.replace,t.pop,o,e])}var Y=x(require("react"));var Nt,oe=(Nt=Y.default.useTransition)!=null?Nt:()=>[!1,t=>t()],L=()=>{let t=g(),[o,e]=oe();return(0,Y.useMemo)(()=>({pending:o,stepPush(n){let c=Z();e(()=>{t.stepPush({stepId:c,stepParams:n})})},stepReplace(n){let c=Z();e(()=>{t.stepReplace({stepId:c,stepParams:n})})},stepPop(){e(()=>{t.stepPop({})})}}),[t.stepPush,t.stepReplace,t.stepPop,o,e])};var re=et.default.forwardRef((t,o)=>{let{dispatchEvent:e,getStack:n}=g(),{push:c,pop:m,replace:r}=K(),{stepPush:s,stepPop:i,stepReplace:a}=L("");return et.default.useImperativeHandle(o,()=>({actions:{dispatchEvent:e,getStack:n,push:c,pop:m,replace:r,stepPush:s,stepPop:i,stepReplace:a}})),null}),Ft=re;function ie(t){let o=Object.entries(t.activities).reduce((r,[s,i])=>S(p({},r),{[s]:h.default.memo(i)}),{});typeof window!="undefined"&&window.document.documentElement.style.setProperty("--stackflow-transition-duration",`${t.transitionDuration}ms`);let e={current:null},n=r=>`\`<Stack />\` component has not been mounted. Make sure you include \`<Stack />\` within your React tree. Or, make sure you call \`${r}()\` after it is rendered.`;return{Stack:r=>{var i;let s=(0,h.useMemo)(()=>{var a;return((a=t.plugins)!=null?a:[]).flat(1/0).map(d=>d).map(d=>d({initContext:r.initContext}))},[]);return h.default.createElement(St,{value:(i=r.initContext)!=null?i:{}},h.default.createElement(Ct,{value:s},h.default.createElement(wt,{activities:o,initialActivity:t.initialActivity,transitionDuration:t.transitionDuration},h.default.createElement(Ut,{activities:o}),h.default.createElement(Ot,null),h.default.createElement(Ft,{ref:e}))))},useFlow:K,useStepFlow:L,actions:{dispatchEvent(r,s){if(!e.current)throw new Error(n("dispatchEvent"));return e.current.actions.dispatchEvent(r,s)},getStack(){if(!e.current)throw new Error(n("getStack"));return e.current.actions.getStack()},push(r,s,i){if(!e.current)throw new Error(n("push"));return e.current.actions.push(r,s,i)},pop(r){if(!e.current)throw new Error(n("pop"));return e.current.actions.pop(r)},replace(r,s,i){if(!e.current)throw new Error(n("replace"));return e.current.actions.replace(r,s,i)},stepPush(r){if(!e.current)throw new Error(n("stepPush"));return e.current.actions.stepPush(r)},stepReplace(r){if(!e.current)throw new Error(n("stepReplace"));return e.current.actions.stepReplace(r)},stepPop(){if(!e.current)throw new Error(n("stepPop"));return e.current.actions.stepPop()}}}}
"use strict";var At=Object.create;var h=Object.defineProperty,Pt=Object.defineProperties,xt=Object.getOwnPropertyDescriptor,St=Object.getOwnPropertyDescriptors,kt=Object.getOwnPropertyNames,X=Object.getOwnPropertySymbols,gt=Object.getPrototypeOf,Z=Object.prototype.hasOwnProperty,Ct=Object.prototype.propertyIsEnumerable;var Y=(t,e,i)=>e in t?h(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,u=(t,e)=>{for(var i in e||(e={}))Z.call(e,i)&&Y(t,i,e[i]);if(X)for(var i of X(e))Ct.call(e,i)&&Y(t,i,e[i]);return t},v=(t,e)=>Pt(t,St(e));var Tt=(t,e)=>{for(var i in e)h(t,i,{get:e[i],enumerable:!0})},_=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of kt(e))!Z.call(t,s)&&s!==i&&h(t,s,{get:()=>e[s],enumerable:!(n=xt(e,s))||n.enumerable});return t};var m=(t,e,i)=>(i=t!=null?At(gt(t)):{},_(e||!t||!t.__esModule?h(i,"default",{value:t,enumerable:!0}):i,t)),ht=t=>_(h({},"__esModule",{value:!0}),t);var Nt={};Tt(Nt,{stackflow:()=>bt,useActions:()=>$,useActivity:()=>wt,useActivityParams:()=>Rt,useStack:()=>Et,useStepActions:()=>G});module.exports=ht(Nt);var it=require("react");var U=m(require("react"));var O=require("react"),tt=m(require("react-fast-compare"));function I(t){let e=(0,O.useRef)(t),i=e.current,n=(0,tt.default)(i,t);return(0,O.useEffect)(()=>{n||(e.current=t)}),n?i:t}var w=(0,U.createContext)(null),et=({children:t,value:e})=>U.default.createElement(w.Provider,{value:I(e)},t);var wt=()=>(0,it.useContext)(w);var ot=require("react");function Rt(){return(0,ot.useContext)(w).params}var nt=require("react");var B=m(require("react"));var q=(0,B.createContext)(null),rt=({children:t,value:e})=>B.default.createElement(q.Provider,{value:I(e)},t);var Et=()=>(0,nt.useContext)(q);var T=require("@stackflow/core"),l=m(require("react"));var at=require("@stackflow/core");function d(){return(0,at.id)()}var st=require("@stackflow/core");function g(){return(0,st.id)()}var P=m(require("react")),W=(0,P.createContext)(null),z=(0,P.createContext)(null),ct=({coreStore:t,children:e})=>{let i=(0,P.useSyncExternalStore)(t.subscribe,t.actions.getStack,t.actions.getStack);return P.default.createElement(z.Provider,{value:i},P.default.createElement(W.Provider,{value:t.actions},e))};var pt=m(require("react"));var b=()=>pt.default.useContext(W);var ut=m(require("react"));var N=()=>ut.default.useContext(z);var C=m(require("react"));var R=m(require("react"));var D=m(require("react")),V=(0,D.createContext)(null),mt=({children:t,value:e})=>D.default.createElement(V.Provider,{value:e},t);var lt=require("react");function F(){return(0,lt.useContext)(V)}var Ot=({activities:t,plugin:e})=>{let i=N(),n=F();return e.render({stack:v(u({},i),{render(s){let c=u(u({},i),s);return{activities:c.activities.map(o=>v(u({},o),{key:o.id,render(f){let E=t[o.name],x;if("component"in E){let{component:y}=E;x=R.default.createElement(y,{params:o.params})}else x=R.default.createElement(E,{params:o.params});return n.forEach(y=>{var r,a;x=(a=(r=y.wrapActivity)==null?void 0:r.call(y,{activity:v(u({},o),{render:()=>x})}))!=null?a:x}),R.default.createElement(rt,{value:c},R.default.createElement(et,{key:o.id,value:u(u({},o),f)},x))}}))}}})})},ft=Ot;var It=({activities:t})=>{let e=N(),i=F(),n=i.filter(c=>!!c.render);(0,C.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=C.default.createElement(C.default.Fragment,null,n.map(c=>C.default.createElement(ft,{key:c.key,activities:t,plugin:c})));return i.forEach(c=>{var o,f;s=(f=(o=c.wrapStack)==null?void 0:o.call(c,{stack:v(u({},e),{render(){return s}})}))!=null?f:s}),s},vt=It;var M=m(require("react"));function j(t){return t?t.animate===void 0||t.animate==null?{skipActiveState:!1}:{skipActiveState:!t.animate}:{skipActiveState:!1}}var dt,Ut=(dt=M.default.useTransition)!=null?dt:()=>[!1,t=>t()];function $(){let t=b(),[e,i]=Ut();return(0,M.useMemo)(()=>({pending:e,push(n,s,c){let o=d();return i(()=>{t.push({activityId:o,activityName:n,activityParams:s,skipEnterActiveState:j(c).skipActiveState})}),{activityId:o}},replace(n,s,c){let o=d();return i(()=>{var f;t.replace({activityId:(f=c==null?void 0:c.activityId)!=null?f:d(),activityName:n,activityParams:s,skipEnterActiveState:j(c).skipActiveState})}),{activityId:o}},pop(n){i(()=>{t.pop({skipExitActiveState:j(n).skipActiveState})})}}),[t.push,t.replace,t.pop,e,i])}var K=m(require("react"));var yt,Bt=(yt=K.default.useTransition)!=null?yt:()=>[!1,t=>t()],G=()=>{let t=b(),[e,i]=Bt();return(0,K.useMemo)(()=>({pending:e,stepPush(n){let s=g();i(()=>{t.stepPush({stepId:s,stepParams:n})})},stepReplace(n){let s=g();i(()=>{t.stepReplace({stepId:s,stepParams:n})})},stepPop(){i(()=>{t.stepPop({})})}}),[t.stepPush,t.stepReplace,t.stepPop,e,i])};function H(t){return t?t.animate===void 0||t.animate==null?{skipActiveState:!1}:{skipActiveState:!t.animate}:{skipActiveState:!1}}function bt(t){var y;let e=((y=t.plugins)!=null?y:[]).flat(1/0).map(r=>r),i=e.map(r=>r()),n=new Date().getTime()-t.transitionDuration,s=(0,T.makeEvent)("Initialized",{transitionDuration:t.transitionDuration,eventDate:n}),c=Object.entries(t.activities).map(([r,a])=>(0,T.makeEvent)("ActivityRegistered",u({activityName:r,eventDate:n},"component"in a?{activityParamsSchema:a.paramsSchema}:null))),o=(0,T.createCoreStore)({initialEvents:[s,...c],plugins:e}),f=Object.entries(t.activities).reduce((r,[a,p])=>"component"in p?v(u({},r),{[a]:{paramsSchema:p.paramsSchema,component:p.component}}):v(u({},r),{[a]:l.default.memo(p)}),{});return typeof window!="undefined"&&window.document.documentElement.style.setProperty("--stackflow-transition-duration",`${t.transitionDuration}ms`),{Stack:r=>{let a=(0,l.useMemo)(()=>t.initialActivity?[(0,T.makeEvent)("Pushed",{activityId:d(),activityName:t.initialActivity(),activityParams:{},eventDate:n,skipEnterActiveState:!1})]:[],[]),p=(0,l.useMemo)(()=>i.reduce((A,k)=>{var J,L,Q;return(Q=(L=k.overrideInitialEvents)==null?void 0:L.call(k,{initialEvents:A,initialContext:(J=r.initialContext)!=null?J:{}}))!=null?Q:A},a),[]);(0,l.useMemo)(()=>{p.forEach(A=>{o.actions.dispatchEvent(A.name,A)})},[]);let S=!!p&&!!a&&p!==a;return(0,l.useEffect)(()=>{S&&console.warn(`Stackflow - Some plugin overrides an "initialActivity" option. The "initialActivity" option you set to "${a[0].activityName}" in the "stackflow" is ignored.`),p.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`)")},[]),(0,l.useEffect)(()=>{o.initialize()},[]),l.default.createElement(mt,{value:i},l.default.createElement(ct,{coreStore:o},l.default.createElement(vt,{activities:f})))},useFlow:$,useStepFlow:G,actions:{dispatchEvent(r,a){return o.actions.dispatchEvent(r,a)},getStack(){return o.actions.getStack()},push(r,a,p){let S=d();return o.actions.push({activityId:S,activityName:r,activityParams:a,skipEnterActiveState:H(p).skipActiveState}),{activityId:S}},replace(r,a,p){var A,k;let S=(A=p==null?void 0:p.activityId)!=null?A:d();return o.actions.replace({activityId:(k=p==null?void 0:p.activityId)!=null?k:d(),activityName:r,activityParams:a,skipEnterActiveState:H(p).skipActiveState}),{activityId:S}},pop(r){return o.actions.pop({skipExitActiveState:H(r).skipActiveState})},stepPush(r){let a=g();return o.actions.stepPush({stepId:a,stepParams:r})},stepReplace(r){let a=g();return o.actions.stepReplace({stepId:a,stepParams:r})},stepPop(){return o.actions.stepPop({})}}}}
//# sourceMappingURL=index.js.map

@@ -1,3 +0,2 @@

export * from "./PluginsContext";
export * from "./PluginsProvider";
export * from "./usePlugins";
import React from "react";
import type { PluginsContextValue } from "./PluginsContext";
import type { StackflowReactPlugin } from "../StackflowReactPlugin";
export declare type PluginsContextValue = Array<ReturnType<StackflowReactPlugin>>;
export declare const PluginsContext: React.Context<PluginsContextValue>;
interface PluginsProviderProps {

@@ -4,0 +6,0 @@ children: React.ReactNode;

@@ -1,1 +0,1 @@

export declare function usePlugins(): import("./PluginsContext").PluginsContextValue;
export declare function usePlugins(): import("./PluginsProvider").PluginsContextValue;

@@ -1,3 +0,2 @@

export * from "./StackContext";
export * from "./StackProvider";
export * from "./useStack";
import type { AggregateOutput } from "@stackflow/core";
import React from "react";
export declare const StackContext: React.Context<AggregateOutput>;
interface StackProviderProps {

@@ -4,0 +5,0 @@ children: React.ReactNode;

@@ -1,17 +0,11 @@

import type { StackflowPluginActions } from "@stackflow/core";
import type { StackflowActions } from "@stackflow/core";
import React from "react";
import type { BaseActivities } from "./BaseActivities";
import type { StackflowReactPlugin } from "./StackflowReactPlugin";
import type { StackRefCurrentType } from "./StackRefManager";
import type { UseActionsOutputType } from "./useActions";
import type { UseStepActions, UseStepActionsOutputType } from "./useStepActions";
export interface StackProps {
/**
* Context data to pass to plugins in render time
*/
initContext?: {};
}
export declare type StackComponentType = React.FC<StackProps>;
export declare type StackComponentType = React.FC<{
initialContext?: any;
}>;
declare type StackflowPluginsEntry<T extends BaseActivities> = StackflowReactPlugin<T> | StackflowPluginsEntry<T>[];
export declare type StackRefType<T extends BaseActivities> = React.MutableRefObject<StackRefCurrentType<T> | null>;
export declare type StackflowOptions<T extends BaseActivities> = {

@@ -30,5 +24,3 @@ /**

*/
initialActivity?: (args: {
initContext: any;
}) => Extract<keyof T, string>;
initialActivity?: () => Extract<keyof T, string>;
/**

@@ -55,3 +47,3 @@ * Inject stackflow plugins

*/
actions: Pick<StackflowPluginActions, "dispatchEvent" | "getStack"> & Pick<UseActionsOutputType<T>, "push" | "pop" | "replace"> & Pick<UseStepActionsOutputType<{}>, "stepPush" | "stepReplace" | "stepPop">;
actions: Pick<StackflowActions, "dispatchEvent" | "getStack"> & Pick<UseActionsOutputType<T>, "push" | "pop" | "replace"> & Pick<UseStepActionsOutputType<{}>, "stepPush" | "stepReplace" | "stepPop">;
};

@@ -58,0 +50,0 @@ /**

import type { Activity, AggregateOutput, StackflowPlugin } from "@stackflow/core";
import type React from "react";
export declare type StackflowReactPlugin<T = never> = (args: {
initContext: any;
}) => {
export declare type StackflowReactPlugin<T = never> = () => {
/**

@@ -7,0 +5,0 @@ * Determine how to render by using the stack state

@@ -11,3 +11,5 @@ import type { ActivityComponentType } from "./activity";

*/
push: <K extends Extract<keyof T, string>>(activityName: K, params: T[K] extends ActivityComponentType<infer U> ? U : {}, options?: {
push: <K extends Extract<keyof T, string>>(activityName: K, params: T[K] extends ActivityComponentType<infer U> | {
component: ActivityComponentType<infer U>;
} ? U : {}, options?: {
animate?: boolean;

@@ -20,3 +22,5 @@ }) => {

*/
replace: <K extends Extract<keyof T, string>>(activityName: K, params: T[K] extends ActivityComponentType<infer U> ? U : {}, options?: {
replace: <K extends Extract<keyof T, string>>(activityName: K, params: T[K] extends ActivityComponentType<infer U> | {
component: ActivityComponentType<infer U>;
} ? U : {}, options?: {
animate?: boolean;

@@ -23,0 +27,0 @@ activityId?: string;

@@ -9,3 +9,5 @@ import type { ActivityComponentType } from "./activity";

};
export declare type UseStepActions<T extends BaseActivities = {}> = <K extends Extract<keyof T, string>>(activityName: K) => UseStepActionsOutputType<T[K] extends ActivityComponentType<infer U> ? U : {}>;
export declare type UseStepActions<T extends BaseActivities = {}> = <K extends Extract<keyof T, string>>(activityName: K) => UseStepActionsOutputType<T[K] extends ActivityComponentType<infer U> | {
component: ActivityComponentType<infer U>;
} ? U : {}>;
export declare const useStepActions: UseStepActions;
{
"name": "@stackflow/react",
"version": "0.16.0",
"version": "0.16.1-alpha.20+dfd24a7f",
"license": "MIT",

@@ -30,6 +30,18 @@ "exports": {

"devDependencies": {
"@stackflow/core": "^0.16.0",
"@stackflow/core": "^0.16.1-alpha.20+dfd24a7f",
"@stackflow/esbuild-config": "^0.16.0",
"@stackflow/eslint-config": "^0.16.0",
"@types/react": "^18.0.9",
"@typescript-eslint/eslint-plugin": "^5.32.0",
"@typescript-eslint/parser": "^5.20.0",
"esbuild": "^0.14.51",
"eslint": "^8.13.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-json-format": "^2.0.1",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-react": "^7.29.4",
"eslint-plugin-react-hooks": "^4.4.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"react": "^18.1.0",

@@ -53,3 +65,3 @@ "rimraf": "^3.0.2",

},
"gitHead": "f7be64a38d76837c1595488f018dbf50714e293d"
"gitHead": "dfd24a7f8282311bddd58887aa4c888658474fec"
}
export * from "./ActivityComponentType";
export * from "./ActivityContext";
export * from "./ActivityProvider";

@@ -4,0 +3,0 @@ export * from "./makeActivityId";

import { useContext } from "react";
import { ActivityContext } from "./ActivityContext";
import { ActivityContext } from "./ActivityProvider";

@@ -5,0 +5,0 @@ /**

import { useContext } from "react";
import { ActivityContext } from "./ActivityContext";
import { ActivityContext } from "./ActivityProvider";

@@ -5,0 +5,0 @@ /**

@@ -0,5 +1,14 @@

import type { ActivityRegisteredEvent } from "@stackflow/core/dist/event-types";
import type { ActivityComponentType } from "./activity";
export type BaseActivities = {
[activityName: string]: ActivityComponentType<any>;
[activityName: string]:
| ActivityComponentType<any>
| {
component: ActivityComponentType<any>;
paramsSchema: NonNullable<
ActivityRegisteredEvent["activityParamsSchema"]
>;
};
};

@@ -1,5 +0,3 @@

export * from "./CoreActionsContext";
export * from "./CoreProvider";
export * from "./CoreStateContext";
export * from "./useCoreActions";
export * from "./useCoreState";

@@ -1,241 +0,5 @@

import type { Effect } from "@stackflow/core";
import type {
PoppedEvent,
PushedEvent,
ReplacedEvent,
StepPoppedEvent,
StepPushedEvent,
StepReplacedEvent,
} from "@stackflow/core/dist/event-types";
import type { BaseDomainEvent } from "@stackflow/core/dist/event-types/_base";
import React, { useCallback, useMemo } from "react";
import React from "react";
import { useInitContext } from "../init-context";
import { usePlugins } from "../plugins";
import { CoreActionsContext } from "./CoreActionsContext";
import { CoreActionsContext } from "./CoreProvider";
export const useCoreActions = () => {
const plugins = usePlugins();
const initContext = useInitContext();
const { dispatchEvent, getStack } = React.useContext(CoreActionsContext);
const push = useCallback(
(params: Omit<PushedEvent, keyof BaseDomainEvent>) => {
// eslint-disable-next-line no-use-before-define
const { isPrevented, params: eventParams } = triggerPreEffectHook(
"PUSHED",
params,
);
if (!isPrevented) {
dispatchEvent("Pushed", {
...eventParams,
});
}
},
[dispatchEvent],
);
const replace = useCallback(
(params: Omit<ReplacedEvent, keyof BaseDomainEvent>) => {
// eslint-disable-next-line no-use-before-define
const { isPrevented, params: eventParams } = triggerPreEffectHook(
"REPLACED",
params,
);
if (!isPrevented) {
dispatchEvent("Replaced", {
...eventParams,
});
}
},
[dispatchEvent],
);
const pop = useCallback(
(params?: Omit<PoppedEvent, keyof BaseDomainEvent>) => {
const initialParams = params ?? {};
// eslint-disable-next-line no-use-before-define
const { isPrevented, params: eventParams } = triggerPreEffectHook(
"POPPED",
initialParams,
);
if (!isPrevented) {
dispatchEvent("Popped", { ...eventParams });
}
},
[dispatchEvent],
);
const stepPush = useCallback(
(params: Omit<StepPushedEvent, keyof BaseDomainEvent>) => {
// eslint-disable-next-line no-use-before-define
const { isPrevented, params: eventParams } = triggerPreEffectHook(
"STEP_PUSHED",
params,
);
if (!isPrevented) {
dispatchEvent("StepPushed", {
...eventParams,
});
}
},
[dispatchEvent],
);
const stepReplace = useCallback(
(params: Omit<StepReplacedEvent, keyof BaseDomainEvent>) => {
// eslint-disable-next-line no-use-before-define
const { isPrevented, params: eventParams } = triggerPreEffectHook(
"STEP_REPLACED",
params,
);
if (!isPrevented) {
dispatchEvent("StepReplaced", {
...eventParams,
});
}
},
[dispatchEvent],
);
const stepPop = useCallback(
(params?: Omit<StepPoppedEvent, keyof BaseDomainEvent>) => {
const initialParams = params ?? {};
// eslint-disable-next-line no-use-before-define
const { isPrevented, params: eventParams } = triggerPreEffectHook(
"STEP_POPPED",
initialParams,
);
if (!isPrevented) {
dispatchEvent("StepPopped", { ...eventParams });
}
},
[dispatchEvent],
);
const coreActions = useMemo(
() => ({
dispatchEvent,
getStack,
push,
replace,
pop,
stepPush,
stepReplace,
stepPop,
}),
[
dispatchEvent,
getStack,
push,
replace,
pop,
stepPush,
stepReplace,
stepPop,
],
);
const triggerPreEffectHook = useCallback(
(preEffect: Effect["_TAG"], initialActionParams: any) => {
let isPrevented = false;
let actionParams = {
...initialActionParams,
};
const preventDefault = () => {
isPrevented = true;
};
const overrideActionParams = (newActionParams: any) => {
actionParams = {
...actionParams,
...newActionParams,
};
};
plugins.forEach((plugin) => {
switch (preEffect) {
case "PUSHED":
plugin.onBeforePush?.({
actionParams,
actions: {
...coreActions,
preventDefault,
overrideActionParams,
},
});
break;
case "REPLACED":
plugin.onBeforeReplace?.({
actionParams,
actions: {
...coreActions,
preventDefault,
overrideActionParams,
},
});
break;
case "POPPED":
plugin.onBeforePop?.({
actionParams,
actions: {
...coreActions,
preventDefault,
overrideActionParams,
},
});
break;
case "STEP_PUSHED":
plugin.onBeforeStepPush?.({
actionParams,
actions: {
...coreActions,
preventDefault,
overrideActionParams,
},
});
break;
case "STEP_REPLACED":
plugin.onBeforeStepReplace?.({
actionParams,
actions: {
...coreActions,
preventDefault,
overrideActionParams,
},
});
break;
case "STEP_POPPED":
plugin.onBeforeStepPop?.({
actionParams,
actions: {
...coreActions,
preventDefault,
overrideActionParams,
},
});
break;
default:
break;
}
});
return {
isPrevented,
params: actionParams,
};
},
[plugins, initContext],
);
return coreActions;
};
export const useCoreActions = () => React.useContext(CoreActionsContext);
import React from "react";
import { CoreStateContext } from "./CoreStateContext";
import { CoreStateContext } from "./CoreProvider";
export const useCoreState = () => React.useContext(CoreStateContext);
export * from "./activity/ActivityComponentType";
export * from "./activity/useActivity";
export * from "./activity/useActivityParams";
export * from "./init-context/useInitContext";
export * from "./stack/useStack";

@@ -6,0 +5,0 @@ export * from "./stackflow";

@@ -1,3 +0,2 @@

export * from "./PluginsContext";
export * from "./PluginsProvider";
export * from "./usePlugins";
import { useContext } from "react";
import { PluginsContext } from "./PluginsContext";
import { PluginsContext } from "./PluginsProvider";

@@ -5,0 +5,0 @@ export function usePlugins() {

@@ -1,3 +0,2 @@

export * from "./StackContext";
export * from "./StackProvider";
export * from "./useStack";
import { useContext } from "react";
import { StackContext } from "./StackContext";
import { StackContext } from "./StackProvider";

@@ -5,0 +5,0 @@ /**

@@ -8,3 +8,3 @@ import type {

export type StackflowReactPlugin<T = never> = (args: { initContext: any }) => {
export type StackflowReactPlugin<T = never> = () => {
/**

@@ -11,0 +11,0 @@ * Determine how to render by using the stack state

@@ -33,3 +33,7 @@ import React, { useMemo } from "react";

activityName: K,
params: T[K] extends ActivityComponentType<infer U> ? U : {},
params: T[K] extends
| ActivityComponentType<infer U>
| { component: ActivityComponentType<infer U> }
? U
: {},
options?: {

@@ -47,3 +51,7 @@ animate?: boolean;

activityName: K,
params: T[K] extends ActivityComponentType<infer U> ? U : {},
params: T[K] extends
| ActivityComponentType<infer U>
| { component: ActivityComponentType<infer U> }
? U
: {},
options?: {

@@ -50,0 +58,0 @@ animate?: boolean;

@@ -20,3 +20,7 @@ import React, { useMemo } from "react";

) => UseStepActionsOutputType<
T[K] extends ActivityComponentType<infer U> ? U : {}
T[K] extends
| ActivityComponentType<infer U>
| { component: ActivityComponentType<infer U> }
? U
: {}
>;

@@ -23,0 +27,0 @@

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

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc