@stackflow/plugin-history-sync
Advanced tools
Comparing version 0.21.3 to 1.0.0
@@ -38,2 +38,6 @@ "use strict"; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
@@ -56,9 +60,12 @@ mod | ||
var import_core = require("@stackflow/core"); | ||
var import_react2 = __toESM(require("react")); | ||
// src/utils/isServer.ts | ||
function isServer() { | ||
return typeof window === "undefined"; | ||
} | ||
// src/historyState.ts | ||
var STATE_TAG = `${"@stackflow/plugin-history-sync"}@${"0.21.2"}`; | ||
var isServer = typeof window === "undefined"; | ||
var STATE_TAG = `${"@stackflow/plugin-history-sync"}@${"0.21.3"}`; | ||
function getCurrentState() { | ||
if (isServer) { | ||
if (isServer()) { | ||
return null; | ||
@@ -77,5 +84,5 @@ } | ||
return __spreadProps(__spreadValues({}, step), { | ||
pushedBy: "activityContext" in step.pushedBy ? __spreadProps(__spreadValues({}, step.pushedBy), { | ||
enteredBy: "activityContext" in step.enteredBy ? __spreadProps(__spreadValues({}, step.enteredBy), { | ||
activityContext: void 0 | ||
}) : __spreadValues({}, step.pushedBy) | ||
}) : __spreadValues({}, step.enteredBy) | ||
}); | ||
@@ -86,3 +93,3 @@ } | ||
context: void 0, | ||
pushedBy: __spreadProps(__spreadValues({}, activity.pushedBy), { | ||
enteredBy: __spreadProps(__spreadValues({}, activity.enteredBy), { | ||
activityContext: void 0 | ||
@@ -105,3 +112,3 @@ }), | ||
}) { | ||
if (isServer) { | ||
if (isServer()) { | ||
return; | ||
@@ -117,3 +124,3 @@ } | ||
}) { | ||
if (isServer) { | ||
if (isServer()) { | ||
return; | ||
@@ -187,7 +194,6 @@ } | ||
// src/RoutesContext.tsx | ||
var import_react = __toESM(require("react")); | ||
var import_react = require("react"); | ||
var import_jsx_runtime = require("react/jsx-runtime"); | ||
var RoutesContext = (0, import_react.createContext)({}); | ||
var RoutesProvider = (props) => /* @__PURE__ */ import_react.default.createElement(RoutesContext.Provider, { | ||
value: props.routes | ||
}, props.children); | ||
var RoutesProvider = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RoutesContext.Provider, { value: props.routes, children: props.children }); | ||
RoutesProvider.displayName = "RoutesProvider"; | ||
@@ -199,5 +205,5 @@ function useRoutes() { | ||
// src/historySyncPlugin.tsx | ||
var import_jsx_runtime2 = require("react/jsx-runtime"); | ||
var SECOND = 1e3; | ||
var MINUTE = 60 * SECOND; | ||
var isServer2 = typeof window === "undefined"; | ||
function historySyncPlugin(options) { | ||
@@ -210,5 +216,3 @@ return () => { | ||
wrapStack({ stack }) { | ||
return /* @__PURE__ */ import_react2.default.createElement(RoutesProvider, { | ||
routes: options.routes | ||
}, stack.render()); | ||
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RoutesProvider, { routes: options.routes, children: stack.render() }); | ||
}, | ||
@@ -220,7 +224,7 @@ overrideInitialEvents({ initialContext }) { | ||
return [ | ||
__spreadProps(__spreadValues({}, initialHistoryState.activity.pushedBy), { | ||
__spreadProps(__spreadValues({}, initialHistoryState.activity.enteredBy), { | ||
name: "Pushed" | ||
}), | ||
...((_a = initialHistoryState.step) == null ? void 0 : _a.pushedBy.name) === "StepPushed" || ((_b = initialHistoryState.step) == null ? void 0 : _b.pushedBy.name) === "StepReplaced" ? [ | ||
__spreadProps(__spreadValues({}, initialHistoryState.step.pushedBy), { | ||
...((_a = initialHistoryState.step) == null ? void 0 : _a.enteredBy.name) === "StepPushed" || ((_b = initialHistoryState.step) == null ? void 0 : _b.enteredBy.name) === "StepReplaced" ? [ | ||
__spreadProps(__spreadValues({}, initialHistoryState.step.enteredBy), { | ||
name: "StepPushed" | ||
@@ -236,3 +240,3 @@ }) | ||
} | ||
if (isServer2) { | ||
if (isServer()) { | ||
return null; | ||
@@ -365,6 +369,6 @@ } | ||
pushFlag += 1; | ||
push(__spreadValues({}, targetActivity.pushedBy)); | ||
if ((targetStep == null ? void 0 : targetStep.pushedBy.name) === "StepPushed" || (targetStep == null ? void 0 : targetStep.pushedBy.name) === "StepReplaced") { | ||
push(__spreadValues({}, targetActivity.enteredBy)); | ||
if ((targetStep == null ? void 0 : targetStep.enteredBy.name) === "StepPushed" || (targetStep == null ? void 0 : targetStep.enteredBy.name) === "StepReplaced") { | ||
pushFlag += 1; | ||
stepPush(__spreadValues({}, targetStep.pushedBy)); | ||
stepPush(__spreadValues({}, targetStep.enteredBy)); | ||
} | ||
@@ -374,5 +378,5 @@ } | ||
if (isStepBackward()) { | ||
if (!nextStep && targetStep && ((targetStep == null ? void 0 : targetStep.pushedBy.name) === "StepPushed" || (targetStep == null ? void 0 : targetStep.pushedBy.name) === "StepReplaced")) { | ||
if (!nextStep && targetStep && ((targetStep == null ? void 0 : targetStep.enteredBy.name) === "StepPushed" || (targetStep == null ? void 0 : targetStep.enteredBy.name) === "StepReplaced")) { | ||
pushFlag += 1; | ||
stepPush(__spreadValues({}, targetStep.pushedBy)); | ||
stepPush(__spreadValues({}, targetStep.enteredBy)); | ||
} | ||
@@ -400,3 +404,3 @@ dispatchEvent("StepPopped", {}); | ||
}; | ||
if (!isServer2) { | ||
if (!isServer()) { | ||
window.addEventListener("popstate", onPopState); | ||
@@ -493,3 +497,3 @@ } | ||
var _a; | ||
if (typeof window === "undefined") { | ||
if (isServer()) { | ||
return; | ||
@@ -508,3 +512,3 @@ } | ||
var _a; | ||
if (typeof window === "undefined") { | ||
if (isServer()) { | ||
return; | ||
@@ -511,0 +515,0 @@ } |
@@ -1,6 +0,6 @@ | ||
import React from "react"; | ||
/// <reference types="react" /> | ||
export declare type RoutesMap = { | ||
[activityName in string]?: string | string[]; | ||
}; | ||
export declare const RoutesContext: React.Context<RoutesMap>; | ||
export declare const RoutesContext: import("react").Context<RoutesMap>; | ||
interface RoutesProviderProps { | ||
@@ -7,0 +7,0 @@ routes: RoutesMap; |
{ | ||
"name": "@stackflow/plugin-history-sync", | ||
"version": "0.21.3", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
@@ -30,6 +30,6 @@ "exports": { | ||
"devDependencies": { | ||
"@stackflow/core": "^0.21.1", | ||
"@stackflow/core": "^1.0.0", | ||
"@stackflow/esbuild-config": "^0.20.0", | ||
"@stackflow/eslint-config": "^0.20.0", | ||
"@stackflow/react": "^0.21.3", | ||
"@stackflow/eslint-config": "^1.0.0", | ||
"@stackflow/react": "^1.0.0", | ||
"@types/node": "^18.6.3", | ||
@@ -68,3 +68,3 @@ "@types/react": "^18.0.10", | ||
}, | ||
"gitHead": "49e9bc061fc8f716489a3acad6d922d0476ee94e" | ||
"gitHead": "d96a0b26503473cb0f246e8cf137a231d1f1eda3" | ||
} |
import type { Activity, ActivityStep } from "@stackflow/core"; | ||
import { isServer } from "./utils"; | ||
const STATE_TAG = `${process.env.PACKAGE_NAME}@${process.env.PACKAGE_VERSION}`; | ||
const isServer = typeof window === "undefined"; | ||
interface State { | ||
@@ -16,3 +16,3 @@ activity: Activity; | ||
export function getCurrentState(): unknown { | ||
if (isServer) { | ||
if (isServer()) { | ||
return null; | ||
@@ -43,10 +43,10 @@ } | ||
...step, | ||
pushedBy: | ||
"activityContext" in step.pushedBy | ||
enteredBy: | ||
"activityContext" in step.enteredBy | ||
? { | ||
...step.pushedBy, | ||
...step.enteredBy, | ||
activityContext: undefined, | ||
} | ||
: { | ||
...step.pushedBy, | ||
...step.enteredBy, | ||
}, | ||
@@ -60,4 +60,4 @@ }; | ||
context: undefined, | ||
pushedBy: { | ||
...activity.pushedBy, | ||
enteredBy: { | ||
...activity.enteredBy, | ||
activityContext: undefined, | ||
@@ -86,3 +86,3 @@ }, | ||
}) { | ||
if (isServer) { | ||
if (isServer()) { | ||
return; | ||
@@ -103,3 +103,3 @@ } | ||
}) { | ||
if (isServer) { | ||
if (isServer()) { | ||
return; | ||
@@ -106,0 +106,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
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
109326
27
1614
1