@ssgoi/react 4.1.0 → 4.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/dist/lib/ssgoi-transition.d.ts +2 -3
- package/dist/lib/ssgoi.d.ts +5 -4
- package/dist/lib/types.d.ts +10 -2
- package/dist/lib/utils.d.ts +10 -0
- package/dist/react/src/lib/ssgoi-transition.cjs +1 -1
- package/dist/react/src/lib/ssgoi-transition.js +36 -20
- package/dist/react/src/lib/ssgoi.cjs +1 -1
- package/dist/react/src/lib/ssgoi.js +32 -25
- package/dist/react/src/lib/utils.cjs +1 -0
- package/dist/react/src/lib/utils.js +17 -0
- package/package.json +1 -1
- package/dist/lib/create-pathname-detector.d.ts +0 -6
- package/dist/react/src/lib/create-pathname-detector.cjs +0 -1
- package/dist/react/src/lib/create-pathname-detector.js +0 -24
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { ReactNode, ElementType
|
|
1
|
+
import { ReactNode, ElementType } from 'react';
|
|
2
2
|
type SsgoiTransitionProps<T extends ElementType = "div"> = {
|
|
3
3
|
children: ReactNode;
|
|
4
4
|
id: string;
|
|
5
5
|
as?: T;
|
|
6
6
|
className?: string;
|
|
7
|
-
style?: CSSProperties;
|
|
8
7
|
};
|
|
9
|
-
export declare const SsgoiTransition: <T extends ElementType = "div">({ children, id, as, className,
|
|
8
|
+
export declare const SsgoiTransition: <T extends ElementType = "div">({ children, id, as, className, ...rest }: SsgoiTransitionProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
10
9
|
export {};
|
package/dist/lib/ssgoi.d.ts
CHANGED
|
@@ -4,11 +4,12 @@ interface SsgoiProps {
|
|
|
4
4
|
config: SsgoiConfig;
|
|
5
5
|
children: ReactNode;
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* Hook to get current pathname (e.g., Next.js usePathname)
|
|
8
|
+
* @example
|
|
9
|
+
* import { usePathname } from 'next/navigation';
|
|
10
|
+
* <Ssgoi config={config} usePathname={usePathname}>
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
|
+
usePathname?: () => string;
|
|
12
13
|
}
|
|
13
14
|
export declare const Ssgoi: React.FC<SsgoiProps>;
|
|
14
15
|
export {};
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { CSSProperties } from 'react';
|
|
2
2
|
import { SsgoiContext } from '@ssgoi/core/types';
|
|
3
3
|
export * from '@ssgoi/core/types';
|
|
4
|
+
/**
|
|
5
|
+
* Navigation info containing from/to paths
|
|
6
|
+
*/
|
|
7
|
+
export type NavigationInfo = {
|
|
8
|
+
from: string | null;
|
|
9
|
+
to: string;
|
|
10
|
+
};
|
|
4
11
|
/**
|
|
5
12
|
* React-specific context type with style control
|
|
6
13
|
*/
|
|
@@ -9,7 +16,8 @@ export type ReactSsgoiContext = {
|
|
|
9
16
|
getTransition: SsgoiContext;
|
|
10
17
|
/**
|
|
11
18
|
* Get initial style for an element
|
|
12
|
-
* Returns { visibility: "hidden" } if transition is configured, {} otherwise
|
|
19
|
+
* Returns { visibility: "hidden" } on first call if transition is configured, {} otherwise
|
|
20
|
+
* Subsequent calls always return {} to prevent re-hiding on rerender
|
|
13
21
|
*/
|
|
14
|
-
getInitialStyle: (
|
|
22
|
+
getInitialStyle: () => CSSProperties;
|
|
15
23
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Combines multiple ref callbacks into one
|
|
4
|
+
*/
|
|
5
|
+
export declare function combineRefs<T>(...refs: Array<((el: T | null) => void) | null | undefined>): (el: T | null) => void;
|
|
6
|
+
/**
|
|
7
|
+
* Forks style from element.style based on initialStyle keys
|
|
8
|
+
* Returns the current DOM style values for keys that were in initialStyle
|
|
9
|
+
*/
|
|
10
|
+
export declare function forkStyleFromElement(element: HTMLElement, initialStyle: CSSProperties): CSSProperties;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("react/jsx-runtime"),e=require("react"),T=require("./transition.cjs"),j=require("./context.cjs"),f=require("./utils.cjs"),x=({children:a,id:s,as:R,className:m,...g})=>{const{getTransition:S,getInitialStyle:y}=j.useSsgoi(),b=R||"div",n=e.useRef(null),i=e.useRef(!0),t=e.useRef(null);t.current===null&&(t.current=y());let r;i.current?r=t.current:n.current&&t.current&&(r=f.forkStyleFromElement(n.current,t.current));const o=e.useCallback(l=>{n.current=l,l&&(i.current=!1)},[]),c=S(s),u=e.useMemo(()=>T.transition(c),[c]),d=e.useMemo(()=>f.combineRefs(o,u),[o,u]);return q.jsx(b,{ref:d,"data-ssgoi-transition":s,className:m,style:r,...g,children:a})};exports.SsgoiTransition=x;
|
|
@@ -1,28 +1,44 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
import { jsx as d } from "react/jsx-runtime";
|
|
3
|
+
import { useRef as r, useCallback as C, useMemo as u } from "react";
|
|
4
|
+
import { transition as k } from "./transition.js";
|
|
5
|
+
import { useSsgoi as x } from "./context.js";
|
|
6
|
+
import { forkStyleFromElement as E, combineRefs as F } from "./utils.js";
|
|
7
|
+
const h = ({
|
|
8
|
+
children: m,
|
|
9
|
+
id: o,
|
|
10
|
+
as: a,
|
|
11
|
+
className: R,
|
|
12
|
+
...p
|
|
12
13
|
}) => {
|
|
13
|
-
const { getTransition:
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const { getTransition: g, getInitialStyle: S } = x(), y = a || "div", e = r(null), i = r(!0), t = r(null);
|
|
15
|
+
t.current === null && (t.current = S());
|
|
16
|
+
let n;
|
|
17
|
+
i.current ? n = t.current : e.current && t.current && (n = E(
|
|
18
|
+
e.current,
|
|
19
|
+
t.current
|
|
20
|
+
));
|
|
21
|
+
const s = C((l) => {
|
|
22
|
+
e.current = l, l && (i.current = !1);
|
|
23
|
+
}, []), c = g(o), f = u(
|
|
24
|
+
() => k(c),
|
|
25
|
+
[c]
|
|
26
|
+
), b = u(
|
|
27
|
+
() => F(s, f),
|
|
28
|
+
[s, f]
|
|
29
|
+
);
|
|
30
|
+
return /* @__PURE__ */ d(
|
|
31
|
+
y,
|
|
16
32
|
{
|
|
17
|
-
ref:
|
|
18
|
-
"data-ssgoi-transition":
|
|
19
|
-
className:
|
|
20
|
-
style:
|
|
21
|
-
...
|
|
22
|
-
children:
|
|
33
|
+
ref: b,
|
|
34
|
+
"data-ssgoi-transition": o,
|
|
35
|
+
className: R,
|
|
36
|
+
style: n,
|
|
37
|
+
...p,
|
|
38
|
+
children: m
|
|
23
39
|
}
|
|
24
40
|
);
|
|
25
41
|
};
|
|
26
42
|
export {
|
|
27
|
-
|
|
43
|
+
h as SsgoiTransition
|
|
28
44
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),o=require("react"),v=require("./context.cjs"),s=require("@ssgoi/core");function R(t){const n=o.useRef(null),e=o.useRef(null);t!==null&&n.current!==t&&(e.current=n.current,n.current=t);const r=o.useRef({from:null,to:""});return t!==null&&(r.current={from:e.current,to:t}),o.useCallback(()=>r.current,[])}function S(t){return{trigger(){},get(n){const{from:e,to:r}=t();return!e||!r||e===r?Promise.resolve(null):Promise.resolve({from:e,to:r})}}}const y=o.memo(({config:t,children:n,usePathname:e})=>{const r=e?.()??null,i=R(r),l=o.useMemo(()=>{const{getTransition:g,hasMatchingTransition:f}=s.createSggoiTransitionContext(t,{createNavigationDetector:e?()=>S(i):s.createAnyOrderDetector});return{getTransition:g,getInitialStyle:()=>{if(!e)return{};const{from:u,to:c}=i();return!u||u===c?{}:f(u,c)?{visibility:"hidden"}:{}}}},[t,e,i]);return a.jsx(v.SsgoiProvider,{value:l,children:n})});exports.Ssgoi=y;
|
|
@@ -1,36 +1,43 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import
|
|
4
|
-
import { SsgoiProvider as
|
|
5
|
-
import { createSggoiTransitionContext as
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
2
|
+
import { jsx as g } from "react/jsx-runtime";
|
|
3
|
+
import a, { useMemo as m, useRef as c, useCallback as v } from "react";
|
|
4
|
+
import { SsgoiProvider as y } from "./context.js";
|
|
5
|
+
import { createSggoiTransitionContext as R, createAnyOrderDetector as S } from "@ssgoi/core";
|
|
6
|
+
function d(t) {
|
|
7
|
+
const n = c(null), r = c(null);
|
|
8
|
+
t !== null && n.current !== t && (r.current = n.current, n.current = t);
|
|
9
|
+
const e = c({ from: null, to: "" });
|
|
10
|
+
return t !== null && (e.current = { from: r.current, to: t }), v(() => e.current, []);
|
|
11
|
+
}
|
|
12
|
+
function p(t) {
|
|
13
|
+
return {
|
|
14
|
+
trigger() {
|
|
15
|
+
},
|
|
16
|
+
get(n) {
|
|
17
|
+
const { from: r, to: e } = t();
|
|
18
|
+
return !r || !e || r === e ? Promise.resolve(null) : Promise.resolve({ from: r, to: e });
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const C = a.memo(
|
|
23
|
+
({ config: t, children: n, usePathname: r }) => {
|
|
24
|
+
const e = r?.() ?? null, o = d(e), l = m(() => {
|
|
25
|
+
const { getTransition: s, hasMatchingTransition: f } = R(t, {
|
|
26
|
+
createNavigationDetector: r ? () => p(o) : S
|
|
17
27
|
});
|
|
18
28
|
return {
|
|
19
|
-
getTransition:
|
|
20
|
-
getInitialStyle: (
|
|
29
|
+
getTransition: s,
|
|
30
|
+
getInitialStyle: () => {
|
|
21
31
|
if (!r)
|
|
22
32
|
return {};
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
return t.current = e, {};
|
|
26
|
-
const a = t.current;
|
|
27
|
-
return t.current = e, s(a, u) ? { visibility: "hidden" } : {};
|
|
33
|
+
const { from: i, to: u } = o();
|
|
34
|
+
return !i || i === u ? {} : f(i, u) ? { visibility: "hidden" } : {};
|
|
28
35
|
}
|
|
29
36
|
};
|
|
30
|
-
}, [
|
|
31
|
-
return /* @__PURE__ */
|
|
37
|
+
}, [t, r, o]);
|
|
38
|
+
return /* @__PURE__ */ g(y, { value: l, children: n });
|
|
32
39
|
}
|
|
33
40
|
);
|
|
34
41
|
export {
|
|
35
|
-
|
|
42
|
+
C as Ssgoi
|
|
36
43
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function f(...t){return o=>{t.forEach(e=>e?.(o))}}function c(t,o){const e={};for(const n of Object.keys(o)){const r=t.style[n];r&&(e[n]=r)}return e}exports.combineRefs=f;exports.forkStyleFromElement=c;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function f(...o) {
|
|
2
|
+
return (t) => {
|
|
3
|
+
o.forEach((e) => e?.(t));
|
|
4
|
+
};
|
|
5
|
+
}
|
|
6
|
+
function c(o, t) {
|
|
7
|
+
const e = {};
|
|
8
|
+
for (const n of Object.keys(t)) {
|
|
9
|
+
const r = o.style[n];
|
|
10
|
+
r && (e[n] = r);
|
|
11
|
+
}
|
|
12
|
+
return e;
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
f as combineRefs,
|
|
16
|
+
c as forkStyleFromElement
|
|
17
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { NavigationDetector } from '@ssgoi/core';
|
|
2
|
-
/**
|
|
3
|
-
* Creates a NavigationDetector based on pathname changes
|
|
4
|
-
* Uses getPathname() to detect navigation without relying on IN/OUT callbacks
|
|
5
|
-
*/
|
|
6
|
-
export declare function createPathnameDetector(getPathname: () => string): NavigationDetector;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function s(o){let e=null,t=null,r=!1,l=!1;return{trigger(){},get(u){const n=o();if(!t||r&&l){if(!e||e===n)return e=n,Promise.resolve(null);t={from:e,to:n},r=!1,l=!1}u==="out"?r=!0:l=!0;const a=t;return r&&l&&(e=n,t=null),Promise.resolve(a)}}}exports.createPathnameDetector=s;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
function s(u) {
|
|
2
|
-
let e = null, t = null, r = !1, l = !1;
|
|
3
|
-
return {
|
|
4
|
-
trigger() {
|
|
5
|
-
},
|
|
6
|
-
get(o) {
|
|
7
|
-
const n = u();
|
|
8
|
-
if (!t || r && l) {
|
|
9
|
-
if (!e || e === n)
|
|
10
|
-
return e = n, Promise.resolve(null);
|
|
11
|
-
t = {
|
|
12
|
-
from: e,
|
|
13
|
-
to: n
|
|
14
|
-
}, r = !1, l = !1;
|
|
15
|
-
}
|
|
16
|
-
o === "out" ? r = !0 : l = !0;
|
|
17
|
-
const a = t;
|
|
18
|
-
return r && l && (e = n, t = null), Promise.resolve(a);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
export {
|
|
23
|
-
s as createPathnameDetector
|
|
24
|
-
};
|