@stackflow/react
Advanced tools
Comparing version 0.21.2 to 0.21.3
@@ -10,2 +10,3 @@ export * from "./activity/ActivityComponentType"; | ||
export * from "./useEnterDoneEffect"; | ||
export * from "./useStep"; | ||
export * from "./useStepActions"; |
@@ -51,3 +51,5 @@ "use strict"; | ||
useActivityParams: () => useActivityParams, | ||
useEnterDoneEffect: () => useEnterDoneEffect, | ||
useStack: () => useStack, | ||
useStep: () => useStep, | ||
useStepActions: () => useStepActions | ||
@@ -130,3 +132,3 @@ }); | ||
var import_core7 = require("@stackflow/core"); | ||
var import_react18 = __toESM(require("react")); | ||
var import_react19 = __toESM(require("react")); | ||
@@ -146,3 +148,3 @@ // src/activity/makeActivityId.ts | ||
// src/core/CoreProvider.tsx | ||
var import_react9 = __toESM(require("react")); | ||
var import_react10 = __toESM(require("react")); | ||
@@ -168,7 +170,12 @@ // src/shims/useDeferredValue.ts | ||
// src/shims/useTransition.ts | ||
var import_react9 = __toESM(require("react")); | ||
var _a3; | ||
var useTransition = (_a3 = import_react9.default.useTransition) != null ? _a3 : () => [false, (cb) => cb()]; | ||
// src/core/CoreProvider.tsx | ||
var CoreActionsContext = (0, import_react9.createContext)( | ||
var CoreActionsContext = (0, import_react10.createContext)( | ||
null | ||
); | ||
var CoreStateContext = (0, import_react9.createContext)(null); | ||
var CoreStateContext = (0, import_react10.createContext)(null); | ||
var CoreProvider = ({ | ||
@@ -184,5 +191,5 @@ coreStore, | ||
const deferredStack = useDeferredValue(stack); | ||
return /* @__PURE__ */ import_react9.default.createElement(CoreStateContext.Provider, { | ||
return /* @__PURE__ */ import_react10.default.createElement(CoreStateContext.Provider, { | ||
value: deferredStack | ||
}, /* @__PURE__ */ import_react9.default.createElement(CoreActionsContext.Provider, { | ||
}, /* @__PURE__ */ import_react10.default.createElement(CoreActionsContext.Provider, { | ||
value: coreStore.actions | ||
@@ -194,22 +201,22 @@ }, children)); | ||
// src/core/useCoreActions.ts | ||
var import_react10 = __toESM(require("react")); | ||
var useCoreActions = () => import_react10.default.useContext(CoreActionsContext); | ||
var import_react11 = __toESM(require("react")); | ||
var useCoreActions = () => import_react11.default.useContext(CoreActionsContext); | ||
// src/core/useCoreState.ts | ||
var import_react11 = __toESM(require("react")); | ||
var useCoreState = () => import_react11.default.useContext(CoreStateContext); | ||
var import_react12 = __toESM(require("react")); | ||
var useCoreState = () => import_react12.default.useContext(CoreStateContext); | ||
// src/MainRenderer.tsx | ||
var import_react15 = __toESM(require("react")); | ||
var import_react16 = __toESM(require("react")); | ||
// src/PluginRenderer.tsx | ||
var import_react14 = __toESM(require("react")); | ||
var import_react15 = __toESM(require("react")); | ||
// src/plugins/PluginsProvider.tsx | ||
var import_react12 = __toESM(require("react")); | ||
var PluginsContext = (0, import_react12.createContext)(null); | ||
var import_react13 = __toESM(require("react")); | ||
var PluginsContext = (0, import_react13.createContext)(null); | ||
var PluginsProvider = ({ | ||
children, | ||
value | ||
}) => /* @__PURE__ */ import_react12.default.createElement(PluginsContext.Provider, { | ||
}) => /* @__PURE__ */ import_react13.default.createElement(PluginsContext.Provider, { | ||
value | ||
@@ -220,5 +227,5 @@ }, children); | ||
// src/plugins/usePlugins.ts | ||
var import_react13 = require("react"); | ||
var import_react14 = require("react"); | ||
function usePlugins() { | ||
return (0, import_react13.useContext)(PluginsContext); | ||
return (0, import_react14.useContext)(PluginsContext); | ||
} | ||
@@ -242,8 +249,8 @@ | ||
const Activity = activityComponentMap[activity.name]; | ||
let output = /* @__PURE__ */ import_react14.default.createElement(Activity, { | ||
let output = /* @__PURE__ */ import_react15.default.createElement(Activity, { | ||
params: activity.params | ||
}); | ||
plugins.forEach((p) => { | ||
var _a5, _b; | ||
output = (_b = (_a5 = p.wrapActivity) == null ? void 0 : _a5.call(p, { | ||
var _a4, _b; | ||
output = (_b = (_a4 = p.wrapActivity) == null ? void 0 : _a4.call(p, { | ||
activity: __spreadProps(__spreadValues({}, activity), { | ||
@@ -254,5 +261,5 @@ render: () => output | ||
}); | ||
return /* @__PURE__ */ import_react14.default.createElement(StackProvider, { | ||
return /* @__PURE__ */ import_react15.default.createElement(StackProvider, { | ||
value: stack | ||
}, /* @__PURE__ */ import_react14.default.createElement(ActivityProvider, { | ||
}, /* @__PURE__ */ import_react15.default.createElement(ActivityProvider, { | ||
key: activity.id, | ||
@@ -280,3 +287,3 @@ value: __spreadValues(__spreadValues({}, activity), overrideActivity) | ||
); | ||
(0, import_react15.useEffect)(() => { | ||
(0, import_react16.useEffect)(() => { | ||
if (renderingPlugins.length === 0) { | ||
@@ -288,3 +295,3 @@ console.warn( | ||
}, [renderingPlugins]); | ||
let output = /* @__PURE__ */ import_react15.default.createElement(import_react15.default.Fragment, null, renderingPlugins.map((plugin) => /* @__PURE__ */ import_react15.default.createElement(PluginRenderer_default, { | ||
let output = /* @__PURE__ */ import_react16.default.createElement(import_react16.default.Fragment, null, renderingPlugins.map((plugin) => /* @__PURE__ */ import_react16.default.createElement(PluginRenderer_default, { | ||
key: plugin.key, | ||
@@ -295,4 +302,4 @@ activityComponentMap, | ||
plugins.forEach((plugin) => { | ||
var _a5, _b; | ||
output = (_b = (_a5 = plugin.wrapStack) == null ? void 0 : _a5.call(plugin, { | ||
var _a4, _b; | ||
output = (_b = (_a4 = plugin.wrapStack) == null ? void 0 : _a4.call(plugin, { | ||
stack: __spreadProps(__spreadValues({}, coreState), { | ||
@@ -311,3 +318,3 @@ render() { | ||
// src/useActions.ts | ||
var import_react16 = __toESM(require("react")); | ||
var import_react17 = require("react"); | ||
function parseActionOptions(options) { | ||
@@ -323,8 +330,6 @@ if (!options) { | ||
} | ||
var _a3; | ||
var useTransition = (_a3 = import_react16.default.useTransition) != null ? _a3 : () => [false, (cb) => cb()]; | ||
function useActions() { | ||
const coreActions = useCoreActions(); | ||
const [pending] = useTransition(); | ||
return (0, import_react16.useMemo)( | ||
return (0, import_react17.useMemo)( | ||
() => ({ | ||
@@ -345,6 +350,6 @@ pending, | ||
replace(activityName, activityParams, options) { | ||
var _a5; | ||
var _a4; | ||
const activityId = makeActivityId(); | ||
coreActions == null ? void 0 : coreActions.replace({ | ||
activityId: (_a5 = options == null ? void 0 : options.activityId) != null ? _a5 : makeActivityId(), | ||
activityId: (_a4 = options == null ? void 0 : options.activityId) != null ? _a4 : makeActivityId(), | ||
activityName, | ||
@@ -369,9 +374,7 @@ activityParams, | ||
// src/useStepActions.ts | ||
var import_react17 = __toESM(require("react")); | ||
var _a4; | ||
var useTransition2 = (_a4 = import_react17.default.useTransition) != null ? _a4 : () => [false, (cb) => cb()]; | ||
var import_react18 = require("react"); | ||
var useStepActions = () => { | ||
const coreActions = useCoreActions(); | ||
const [pending] = useTransition2(); | ||
return (0, import_react17.useMemo)( | ||
const [pending] = useTransition(); | ||
return (0, import_react18.useMemo)( | ||
() => ({ | ||
@@ -419,3 +422,3 @@ pending, | ||
function stackflow(options) { | ||
var _a5; | ||
var _a4; | ||
if (typeof window !== "undefined") { | ||
@@ -428,7 +431,7 @@ const html = window.document.documentElement; | ||
} | ||
const plugins = ((_a5 = options.plugins) != null ? _a5 : []).flat(Infinity).map((p) => p); | ||
const plugins = ((_a4 = options.plugins) != null ? _a4 : []).flat(Infinity).map((p) => p); | ||
const pluginInstances = plugins.map((plugin) => plugin()); | ||
const activityComponentMap = Object.entries(options.activities).reduce( | ||
(acc, [key, Activity]) => __spreadProps(__spreadValues({}, acc), { | ||
[key]: "component" in Activity ? import_react18.default.memo(Activity.component) : import_react18.default.memo(Activity) | ||
[key]: "component" in Activity ? import_react19.default.memo(Activity.component) : import_react19.default.memo(Activity) | ||
}), | ||
@@ -456,4 +459,4 @@ {} | ||
const [getCoreStore, setCoreStore] = makeRef(); | ||
const Stack = import_react18.default.memo((props) => { | ||
const coreStore = (0, import_react18.useMemo)(() => { | ||
const Stack = import_react19.default.memo((props) => { | ||
const coreStore = (0, import_react19.useMemo)(() => { | ||
const prevCoreStore = getCoreStore(); | ||
@@ -474,6 +477,6 @@ if (isBrowser && prevCoreStore) { | ||
(initialEvents, pluginInstance) => { | ||
var _a6, _b, _c; | ||
var _a5, _b, _c; | ||
return (_c = (_b = pluginInstance.overrideInitialEvents) == null ? void 0 : _b.call(pluginInstance, { | ||
initialEvents, | ||
initialContext: (_a6 = props.initialContext) != null ? _a6 : {} | ||
initialContext: (_a5 = props.initialContext) != null ? _a5 : {} | ||
})) != null ? _c : initialEvents; | ||
@@ -507,7 +510,7 @@ }, | ||
}, []); | ||
return /* @__PURE__ */ import_react18.default.createElement(PluginsProvider, { | ||
return /* @__PURE__ */ import_react19.default.createElement(PluginsProvider, { | ||
value: pluginInstances | ||
}, /* @__PURE__ */ import_react18.default.createElement(CoreProvider, { | ||
}, /* @__PURE__ */ import_react19.default.createElement(CoreProvider, { | ||
coreStore | ||
}, /* @__PURE__ */ import_react18.default.createElement(MainRenderer_default, { | ||
}, /* @__PURE__ */ import_react19.default.createElement(MainRenderer_default, { | ||
activityComponentMap | ||
@@ -529,3 +532,3 @@ }))); | ||
} | ||
activityComponentMap[activity.name] = import_react18.default.memo(activity.component); | ||
activityComponentMap[activity.name] = import_react19.default.memo(activity.component); | ||
staticCoreStore.actions.dispatchEvent("ActivityRegistered", { | ||
@@ -551,13 +554,13 @@ activityName: activity.name, | ||
getStack() { | ||
var _a6, _b; | ||
return (_b = (_a6 = getCoreStore()) == null ? void 0 : _a6.actions.getStack()) != null ? _b : staticCoreStore.actions.getStack(); | ||
var _a5, _b; | ||
return (_b = (_a5 = getCoreStore()) == null ? void 0 : _a5.actions.getStack()) != null ? _b : staticCoreStore.actions.getStack(); | ||
}, | ||
dispatchEvent(name, parameters) { | ||
var _a6; | ||
return (_a6 = getCoreStore()) == null ? void 0 : _a6.actions.dispatchEvent(name, parameters); | ||
var _a5; | ||
return (_a5 = getCoreStore()) == null ? void 0 : _a5.actions.dispatchEvent(name, parameters); | ||
}, | ||
push(activityName, activityParams, options2) { | ||
var _a6; | ||
var _a5; | ||
const activityId = makeActivityId(); | ||
(_a6 = getCoreStore()) == null ? void 0 : _a6.actions.push({ | ||
(_a5 = getCoreStore()) == null ? void 0 : _a5.actions.push({ | ||
activityId, | ||
@@ -573,4 +576,4 @@ activityName, | ||
replace(activityName, activityParams, options2) { | ||
var _a6, _b, _c; | ||
const activityId = (_a6 = options2 == null ? void 0 : options2.activityId) != null ? _a6 : makeActivityId(); | ||
var _a5, _b, _c; | ||
const activityId = (_a5 = options2 == null ? void 0 : options2.activityId) != null ? _a5 : makeActivityId(); | ||
(_c = getCoreStore()) == null ? void 0 : _c.actions.replace({ | ||
@@ -587,4 +590,4 @@ activityId: (_b = options2 == null ? void 0 : options2.activityId) != null ? _b : makeActivityId(), | ||
pop(options2) { | ||
var _a6; | ||
return (_a6 = getCoreStore()) == null ? void 0 : _a6.actions.pop({ | ||
var _a5; | ||
return (_a5 = getCoreStore()) == null ? void 0 : _a5.actions.pop({ | ||
skipExitActiveState: parseActionOptions2(options2).skipActiveState | ||
@@ -594,5 +597,5 @@ }); | ||
stepPush(params) { | ||
var _a6; | ||
var _a5; | ||
const stepId = makeStepId(); | ||
return (_a6 = getCoreStore()) == null ? void 0 : _a6.actions.stepPush({ | ||
return (_a5 = getCoreStore()) == null ? void 0 : _a5.actions.stepPush({ | ||
stepId, | ||
@@ -603,5 +606,5 @@ stepParams: params | ||
stepReplace(params) { | ||
var _a6; | ||
var _a5; | ||
const stepId = makeStepId(); | ||
return (_a6 = getCoreStore()) == null ? void 0 : _a6.actions.stepReplace({ | ||
return (_a5 = getCoreStore()) == null ? void 0 : _a5.actions.stepReplace({ | ||
stepId, | ||
@@ -612,4 +615,4 @@ stepParams: params | ||
stepPop() { | ||
var _a6; | ||
return (_a6 = getCoreStore()) == null ? void 0 : _a6.actions.stepPop({}); | ||
var _a5; | ||
return (_a5 = getCoreStore()) == null ? void 0 : _a5.actions.stepPop({}); | ||
} | ||
@@ -621,3 +624,3 @@ } | ||
// src/useActiveEffect.ts | ||
var import_react19 = require("react"); | ||
var import_react20 = require("react"); | ||
var noop = () => { | ||
@@ -627,3 +630,3 @@ }; | ||
const { isActive } = useActivity(); | ||
(0, import_react19.useEffect)(() => { | ||
(0, import_react20.useEffect)(() => { | ||
if (isActive) { | ||
@@ -637,3 +640,22 @@ return effect(); | ||
// src/useEnterDoneEffect.ts | ||
var import_react20 = require("react"); | ||
var import_react21 = require("react"); | ||
var noop2 = () => { | ||
}; | ||
var useEnterDoneEffect = (effect, deps = []) => { | ||
const { isTop, transitionState } = useActivity(); | ||
(0, import_react21.useEffect)(() => { | ||
if (isTop && transitionState === "enter-done") { | ||
return effect(); | ||
} | ||
return noop2; | ||
}, [isTop, transitionState, ...deps]); | ||
}; | ||
// src/useStep.ts | ||
var import_react22 = require("react"); | ||
function useStep() { | ||
var _a4; | ||
const { steps, id: id3 } = (0, import_react22.useContext)(ActivityContext); | ||
return (_a4 = steps.filter((step) => step.id !== id3).at(-1)) != null ? _a4 : null; | ||
} | ||
//# sourceMappingURL=index.js.map |
export * from "./useDeferredValue"; | ||
export * from "./useSyncExternalStore"; | ||
export * from "./useTransition"; |
/// <reference types="react" /> | ||
declare const useEnterDoneEffect: (effect: React.EffectCallback, deps?: import("react").DependencyList) => void; | ||
export default useEnterDoneEffect; | ||
export declare const useEnterDoneEffect: (effect: React.EffectCallback, deps?: import("react").DependencyList) => void; |
{ | ||
"name": "@stackflow/react", | ||
"version": "0.21.2", | ||
"version": "0.21.3", | ||
"license": "MIT", | ||
@@ -64,3 +64,3 @@ "exports": { | ||
}, | ||
"gitHead": "be4a7845c2d5a7999cd172733a5690b1d2657b47" | ||
"gitHead": "49e9bc061fc8f716489a3acad6d922d0476ee94e" | ||
} |
@@ -10,2 +10,3 @@ export * from "./activity/ActivityComponentType"; | ||
export * from "./useEnterDoneEffect"; | ||
export * from "./useStep"; | ||
export * from "./useStepActions"; |
export * from "./useDeferredValue"; | ||
export * from "./useSyncExternalStore"; | ||
export * from "./useTransition"; |
@@ -7,2 +7,3 @@ import React, { useMemo } from "react"; | ||
import { useCoreActions } from "./core"; | ||
import { useTransition } from "./shims"; | ||
@@ -70,5 +71,2 @@ function parseActionOptions(options?: { animate?: boolean }) { | ||
const useTransition: () => [boolean, React.TransitionStartFunction] = | ||
React.useTransition ?? (() => [false, (cb: () => void) => cb()]); | ||
export function useActions< | ||
@@ -75,0 +73,0 @@ T extends BaseActivities, |
@@ -5,3 +5,5 @@ import { useEffect } from "react"; | ||
const useEnterDoneEffect = ( | ||
const noop = () => {}; | ||
export const useEnterDoneEffect = ( | ||
effect: React.EffectCallback, | ||
@@ -16,5 +18,5 @@ deps: React.DependencyList = [], | ||
} | ||
return noop; | ||
}, [isTop, transitionState, ...deps]); | ||
}; | ||
export default useEnterDoneEffect; |
@@ -7,2 +7,3 @@ import React, { useMemo } from "react"; | ||
import { useCoreActions } from "./core"; | ||
import { useTransition } from "./shims"; | ||
@@ -28,5 +29,2 @@ export type UseStepActionsOutputType<P> = { | ||
const useTransition: () => [boolean, React.TransitionStartFunction] = | ||
React.useTransition ?? (() => [false, (cb: () => void) => cb()]); | ||
export const useStepActions: UseStepActions = () => { | ||
@@ -33,0 +31,0 @@ const coreActions = useCoreActions(); |
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
156787
79
2345