@epilot/spark-ui 0.15.0 → 0.15.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/components/bubble.d.cts +1 -1
- package/dist/components/bubble.d.ts +1 -1
- package/dist/components/button.d.cts +1 -1
- package/dist/components/button.d.ts +1 -1
- package/dist/components/callout.d.cts +1 -1
- package/dist/components/callout.d.ts +1 -1
- package/dist/components/info-block.d.cts +1 -1
- package/dist/components/info-block.d.ts +1 -1
- package/dist/components/marker.d.cts +1 -1
- package/dist/components/marker.d.ts +1 -1
- package/dist/components/page-header.d.cts +1 -1
- package/dist/components/page-header.d.ts +1 -1
- package/dist/components/reparent.cjs +23 -9
- package/dist/components/reparent.cjs.map +1 -1
- package/dist/components/reparent.d.cts +1 -0
- package/dist/components/reparent.d.ts +1 -0
- package/dist/components/reparent.js +23 -9
- package/dist/components/reparent.js.map +1 -1
- package/package.json +1 -1
|
@@ -10,7 +10,7 @@ declare function BubbleGroup({
|
|
|
10
10
|
...props
|
|
11
11
|
}: React$1.ComponentProps<'div'>): import("react/jsx-runtime").JSX.Element;
|
|
12
12
|
declare const bubbleVariants: (props?: ({
|
|
13
|
-
variant?: "
|
|
13
|
+
variant?: "secondary" | "destructive" | "default" | "ghost" | "outline" | "muted" | "tinted" | null | undefined;
|
|
14
14
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
15
15
|
declare function Bubble({
|
|
16
16
|
variant,
|
|
@@ -10,7 +10,7 @@ declare function BubbleGroup({
|
|
|
10
10
|
...props
|
|
11
11
|
}: React$1.ComponentProps<'div'>): import("react/jsx-runtime").JSX.Element;
|
|
12
12
|
declare const bubbleVariants: (props?: ({
|
|
13
|
-
variant?: "
|
|
13
|
+
variant?: "secondary" | "destructive" | "default" | "ghost" | "outline" | "muted" | "tinted" | null | undefined;
|
|
14
14
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
15
15
|
declare function Bubble({
|
|
16
16
|
variant,
|
|
@@ -9,7 +9,7 @@ import { VariantProps } from "class-variance-authority";
|
|
|
9
9
|
declare const buttonVariants: (props?: ({
|
|
10
10
|
variant?: "primary" | "secondary" | "tertiary" | "bare" | "destructive" | null | undefined;
|
|
11
11
|
color?: "accent" | "neutral" | "danger" | null | undefined;
|
|
12
|
-
size?: "small" | "default" | "
|
|
12
|
+
size?: "small" | "default" | "medium" | "icon-small" | "icon" | "icon-medium" | null | undefined;
|
|
13
13
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
14
14
|
type SparkButtonColor = 'accent' | 'neutral' | 'danger';
|
|
15
15
|
interface ButtonProps extends Omit<React$1.ComponentProps<typeof Button$1>, 'ref'>, Omit<VariantProps<typeof buttonVariants>, 'variant' | 'color'> {
|
|
@@ -9,7 +9,7 @@ import { VariantProps } from "class-variance-authority";
|
|
|
9
9
|
declare const buttonVariants: (props?: ({
|
|
10
10
|
variant?: "primary" | "secondary" | "tertiary" | "bare" | "destructive" | null | undefined;
|
|
11
11
|
color?: "accent" | "neutral" | "danger" | null | undefined;
|
|
12
|
-
size?: "small" | "default" | "
|
|
12
|
+
size?: "small" | "default" | "medium" | "icon-small" | "icon" | "icon-medium" | null | undefined;
|
|
13
13
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
14
14
|
type SparkButtonColor = 'accent' | 'neutral' | 'danger';
|
|
15
15
|
interface ButtonProps extends Omit<React$1.ComponentProps<typeof Button$1>, 'ref'>, Omit<VariantProps<typeof buttonVariants>, 'variant' | 'color'> {
|
|
@@ -8,7 +8,7 @@ import { VariantProps } from "class-variance-authority";
|
|
|
8
8
|
//#region src/components/callout.d.ts
|
|
9
9
|
type CalloutVariant = 'error' | 'info' | 'neutral' | 'success' | 'warning';
|
|
10
10
|
declare const calloutVariants: (props?: ({
|
|
11
|
-
variant?: "neutral" | "success" | "warning" | "
|
|
11
|
+
variant?: "neutral" | "success" | "warning" | "info" | "error" | null | undefined;
|
|
12
12
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
13
13
|
interface CalloutProps extends React$1.HTMLAttributes<HTMLDivElement>, VariantProps<typeof calloutVariants> {
|
|
14
14
|
/** Overrides the variant's default icon; the variant's color is kept. `false` renders no icon. */
|
|
@@ -8,7 +8,7 @@ import { VariantProps } from "class-variance-authority";
|
|
|
8
8
|
//#region src/components/callout.d.ts
|
|
9
9
|
type CalloutVariant = 'error' | 'info' | 'neutral' | 'success' | 'warning';
|
|
10
10
|
declare const calloutVariants: (props?: ({
|
|
11
|
-
variant?: "neutral" | "success" | "warning" | "
|
|
11
|
+
variant?: "neutral" | "success" | "warning" | "info" | "error" | null | undefined;
|
|
12
12
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
13
13
|
interface CalloutProps extends React$1.HTMLAttributes<HTMLDivElement>, VariantProps<typeof calloutVariants> {
|
|
14
14
|
/** Overrides the variant's default icon; the variant's color is kept. `false` renders no icon. */
|
|
@@ -5,7 +5,7 @@ import { VariantProps } from "class-variance-authority";
|
|
|
5
5
|
|
|
6
6
|
//#region src/components/info-block.d.ts
|
|
7
7
|
declare const InfoBlock: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLDivElement> & VariantProps<(props?: ({
|
|
8
|
-
variant?: "
|
|
8
|
+
variant?: "bare" | "default" | null | undefined;
|
|
9
9
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string> & React$1.RefAttributes<HTMLDivElement>>;
|
|
10
10
|
declare const InfoBlockIcon: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLDivElement> & React$1.RefAttributes<HTMLDivElement>>;
|
|
11
11
|
declare const InfoBlockContent: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLDivElement> & React$1.RefAttributes<HTMLDivElement>>;
|
|
@@ -5,7 +5,7 @@ import { VariantProps } from "class-variance-authority";
|
|
|
5
5
|
|
|
6
6
|
//#region src/components/info-block.d.ts
|
|
7
7
|
declare const InfoBlock: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLDivElement> & VariantProps<(props?: ({
|
|
8
|
-
variant?: "
|
|
8
|
+
variant?: "bare" | "default" | null | undefined;
|
|
9
9
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string> & React$1.RefAttributes<HTMLDivElement>>;
|
|
10
10
|
declare const InfoBlockIcon: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLDivElement> & React$1.RefAttributes<HTMLDivElement>>;
|
|
11
11
|
declare const InfoBlockContent: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLDivElement> & React$1.RefAttributes<HTMLDivElement>>;
|
|
@@ -6,7 +6,7 @@ import { useRender } from "@base-ui/react/use-render";
|
|
|
6
6
|
|
|
7
7
|
//#region src/components/marker.d.ts
|
|
8
8
|
declare const markerVariants: (props?: ({
|
|
9
|
-
variant?: "
|
|
9
|
+
variant?: "default" | "separator" | "border" | null | undefined;
|
|
10
10
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
11
11
|
declare function Marker({
|
|
12
12
|
className,
|
|
@@ -6,7 +6,7 @@ import { useRender } from "@base-ui/react/use-render";
|
|
|
6
6
|
|
|
7
7
|
//#region src/components/marker.d.ts
|
|
8
8
|
declare const markerVariants: (props?: ({
|
|
9
|
-
variant?: "
|
|
9
|
+
variant?: "default" | "separator" | "border" | null | undefined;
|
|
10
10
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
11
11
|
declare function Marker({
|
|
12
12
|
className,
|
|
@@ -6,7 +6,7 @@ import { useRender } from "@base-ui/react/use-render";
|
|
|
6
6
|
|
|
7
7
|
//#region src/components/page-header.d.ts
|
|
8
8
|
declare const PageHeader: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLElement> & React$1.RefAttributes<HTMLElement>>;
|
|
9
|
-
declare const PageHeaderBackButton: React$1.ForwardRefExoticComponent<Omit<ButtonProps, "color" | "
|
|
9
|
+
declare const PageHeaderBackButton: React$1.ForwardRefExoticComponent<Omit<ButtonProps, "color" | "styleVariant" | "size"> & React$1.RefAttributes<HTMLButtonElement>>;
|
|
10
10
|
declare const PageHeaderTitle: ({
|
|
11
11
|
className,
|
|
12
12
|
...props
|
|
@@ -6,7 +6,7 @@ import { useRender } from "@base-ui/react/use-render";
|
|
|
6
6
|
|
|
7
7
|
//#region src/components/page-header.d.ts
|
|
8
8
|
declare const PageHeader: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLElement> & React$1.RefAttributes<HTMLElement>>;
|
|
9
|
-
declare const PageHeaderBackButton: React$1.ForwardRefExoticComponent<Omit<ButtonProps, "color" | "
|
|
9
|
+
declare const PageHeaderBackButton: React$1.ForwardRefExoticComponent<Omit<ButtonProps, "color" | "styleVariant" | "size"> & React$1.RefAttributes<HTMLButtonElement>>;
|
|
10
10
|
declare const PageHeaderTitle: ({
|
|
11
11
|
className,
|
|
12
12
|
...props
|
|
@@ -9,6 +9,7 @@ let react_dom = require("react-dom");
|
|
|
9
9
|
const supportsMoveBefore = typeof Element !== "undefined" && "moveBefore" in Element.prototype;
|
|
10
10
|
function useReparent() {
|
|
11
11
|
const [host, setHost] = react.useState(null);
|
|
12
|
+
const [parkCount, setParkCount] = react.useState(0);
|
|
12
13
|
react.useEffect(() => {
|
|
13
14
|
const el = document.createElement("div");
|
|
14
15
|
el.style.display = "contents";
|
|
@@ -16,15 +17,25 @@ function useReparent() {
|
|
|
16
17
|
return () => el.remove();
|
|
17
18
|
}, []);
|
|
18
19
|
const park = react.useCallback(() => {
|
|
19
|
-
if (supportsMoveBefore
|
|
20
|
-
|
|
20
|
+
if (!supportsMoveBefore || !host?.isConnected) return;
|
|
21
|
+
if (host.parentElement === document.body) return;
|
|
22
|
+
try {
|
|
21
23
|
document.body.moveBefore(host, null);
|
|
24
|
+
} catch {
|
|
25
|
+
return;
|
|
22
26
|
}
|
|
27
|
+
host.style.display = "none";
|
|
28
|
+
setParkCount((count) => count + 1);
|
|
23
29
|
}, [host]);
|
|
24
30
|
return react.useMemo(() => ({
|
|
25
31
|
host,
|
|
26
|
-
park
|
|
27
|
-
|
|
32
|
+
park,
|
|
33
|
+
parkCount
|
|
34
|
+
}), [
|
|
35
|
+
host,
|
|
36
|
+
park,
|
|
37
|
+
parkCount
|
|
38
|
+
]);
|
|
28
39
|
}
|
|
29
40
|
function ReparentContent({ handle, children }) {
|
|
30
41
|
if (!handle.host) return null;
|
|
@@ -32,14 +43,17 @@ function ReparentContent({ handle, children }) {
|
|
|
32
43
|
}
|
|
33
44
|
function ReparentSlot({ handle, ...props }) {
|
|
34
45
|
const ref = react.useRef(null);
|
|
35
|
-
const host = handle
|
|
46
|
+
const { host, parkCount } = handle;
|
|
36
47
|
react.useLayoutEffect(() => {
|
|
37
48
|
const slot = ref.current;
|
|
38
|
-
if (!slot || !host) return;
|
|
49
|
+
if (!slot || !host || host.parentElement === slot) return;
|
|
39
50
|
host.style.display = "contents";
|
|
40
|
-
if (supportsMoveBefore && host.isConnected
|
|
41
|
-
|
|
42
|
-
|
|
51
|
+
if (supportsMoveBefore && host.isConnected === slot.isConnected) try {
|
|
52
|
+
slot.moveBefore(host, null);
|
|
53
|
+
return;
|
|
54
|
+
} catch {}
|
|
55
|
+
slot.appendChild(host);
|
|
56
|
+
}, [host, parkCount]);
|
|
43
57
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
44
58
|
"data-slot": "reparent-slot",
|
|
45
59
|
ref,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reparent.cjs","names":["React"],"sources":["../../src/components/reparent.tsx"],"sourcesContent":["import * as React from 'react'\nimport { createPortal } from 'react-dom'\n\n// moveBefore ships in Chrome/Edge 133+, Firefox 144+; Safari has no state-preserving move\nconst supportsMoveBefore =\n typeof Element !== 'undefined' && 'moveBefore' in Element.prototype\n\ntype MovableElement = Element & {\n moveBefore: (node: Node, child: Node | null) => void\n}\n\ninterface ReparentHandle {\n host: HTMLElement | null\n park: () => void\n}\n\n// host created after mount so server and client hydrate the same (empty) markup\nfunction useReparent(): ReparentHandle {\n const [host, setHost] = React.useState<HTMLElement | null>(null)\n React.useEffect(() => {\n const el = document.createElement('div')\n el.style.display = 'contents'\n setHost(el)\n return () => el.remove()\n }, [])\n const park = React.useCallback(() => {\n if (supportsMoveBefore
|
|
1
|
+
{"version":3,"file":"reparent.cjs","names":["React"],"sources":["../../src/components/reparent.tsx"],"sourcesContent":["import * as React from 'react'\nimport { createPortal } from 'react-dom'\n\n// moveBefore ships in Chrome/Edge 133+, Firefox 144+; Safari has no state-preserving move\nconst supportsMoveBefore =\n typeof Element !== 'undefined' && 'moveBefore' in Element.prototype\n\ntype MovableElement = Element & {\n moveBefore: (node: Node, child: Node | null) => void\n}\n\ninterface ReparentHandle {\n host: HTMLElement | null\n park: () => void\n parkCount?: number\n}\n\n// host created after mount so server and client hydrate the same (empty) markup\nfunction useReparent(): ReparentHandle {\n const [host, setHost] = React.useState<HTMLElement | null>(null)\n const [parkCount, setParkCount] = React.useState(0)\n React.useEffect(() => {\n const el = document.createElement('div')\n el.style.display = 'contents'\n setHost(el)\n return () => el.remove()\n }, [])\n const park = React.useCallback(() => {\n if (!supportsMoveBefore || !host?.isConnected) return\n if (host.parentElement === document.body) return\n try {\n ;(document.body as unknown as MovableElement).moveBefore(host, null)\n } catch {\n return\n }\n host.style.display = 'none'\n // re-runs every slot's adopt effect, so a park with no layout swap still recovers\n setParkCount((count) => count + 1)\n }, [host])\n return React.useMemo(\n () => ({ host, park, parkCount }),\n [host, park, parkCount],\n )\n}\n\nfunction ReparentContent({\n handle,\n children,\n}: {\n handle: ReparentHandle\n children: React.ReactNode\n}) {\n if (!handle.host) return null\n return createPortal(children, handle.host)\n}\n\ninterface ReparentSlotProps extends React.ComponentProps<'div'> {\n handle: ReparentHandle\n}\n\nfunction ReparentSlot({ handle, ...props }: ReparentSlotProps) {\n const ref = React.useRef<HTMLDivElement>(null)\n const { host, parkCount } = handle\n React.useLayoutEffect(() => {\n const slot = ref.current\n if (!slot || !host || host.parentElement === slot) return\n host.style.display = 'contents'\n // moveBefore throws unless node and new parent are both connected or both detached\n if (supportsMoveBefore && host.isConnected === slot.isConnected) {\n try {\n ;(slot as unknown as MovableElement).moveBefore(host, null)\n return\n } catch {}\n }\n slot.appendChild(host)\n }, [host, parkCount])\n return <div data-slot=\"reparent-slot\" ref={ref} {...props} />\n}\n\nexport { ReparentContent, ReparentSlot, supportsMoveBefore, useReparent }\nexport type { ReparentHandle, ReparentSlotProps }\n"],"mappings":";;;;;;;;AAIA,MAAM,qBACJ,OAAO,YAAY,eAAe,gBAAgB,QAAQ;AAa5D,SAAS,cAA8B;CACrC,MAAM,CAAC,MAAM,WAAWA,MAAM,SAA6B,IAAI;CAC/D,MAAM,CAAC,WAAW,gBAAgBA,MAAM,SAAS,CAAC;CAClD,MAAM,gBAAgB;EACpB,MAAM,KAAK,SAAS,cAAc,KAAK;EACvC,GAAG,MAAM,UAAU;EACnB,QAAQ,EAAE;EACV,aAAa,GAAG,OAAO;CACzB,GAAG,CAAC,CAAC;CACL,MAAM,OAAOA,MAAM,kBAAkB;EACnC,IAAI,CAAC,sBAAsB,CAAC,MAAM,aAAa;EAC/C,IAAI,KAAK,kBAAkB,SAAS,MAAM;EAC1C,IAAI;GACD,SAAU,KAAmC,WAAW,MAAM,IAAI;EACrE,QAAQ;GACN;EACF;EACA,KAAK,MAAM,UAAU;EAErB,cAAc,UAAU,QAAQ,CAAC;CACnC,GAAG,CAAC,IAAI,CAAC;CACT,OAAOA,MAAM,eACJ;EAAE;EAAM;EAAM;CAAU,IAC/B;EAAC;EAAM;EAAM;CAAS,CACxB;AACF;AAEA,SAAS,gBAAgB,EACvB,QACA,YAIC;CACD,IAAI,CAAC,OAAO,MAAM,OAAO;CACzB,QAAA,GAAA,UAAA,cAAoB,UAAU,OAAO,IAAI;AAC3C;AAMA,SAAS,aAAa,EAAE,QAAQ,GAAG,SAA4B;CAC7D,MAAM,MAAMA,MAAM,OAAuB,IAAI;CAC7C,MAAM,EAAE,MAAM,cAAc;CAC5B,MAAM,sBAAsB;EAC1B,MAAM,OAAO,IAAI;EACjB,IAAI,CAAC,QAAQ,CAAC,QAAQ,KAAK,kBAAkB,MAAM;EACnD,KAAK,MAAM,UAAU;EAErB,IAAI,sBAAsB,KAAK,gBAAgB,KAAK,aAClD,IAAI;GACD,KAAoC,WAAW,MAAM,IAAI;GAC1D;EACF,QAAQ,CAAC;EAEX,KAAK,YAAY,IAAI;CACvB,GAAG,CAAC,MAAM,SAAS,CAAC;CACpB,OAAO,iBAAA,GAAA,kBAAA,KAAC,OAAD;EAAK,aAAU;EAAqB;EAAK,GAAI;CAAQ,CAAA;AAC9D"}
|
|
@@ -6,6 +6,7 @@ import { createPortal } from "react-dom";
|
|
|
6
6
|
const supportsMoveBefore = typeof Element !== "undefined" && "moveBefore" in Element.prototype;
|
|
7
7
|
function useReparent() {
|
|
8
8
|
const [host, setHost] = React$1.useState(null);
|
|
9
|
+
const [parkCount, setParkCount] = React$1.useState(0);
|
|
9
10
|
React$1.useEffect(() => {
|
|
10
11
|
const el = document.createElement("div");
|
|
11
12
|
el.style.display = "contents";
|
|
@@ -13,15 +14,25 @@ function useReparent() {
|
|
|
13
14
|
return () => el.remove();
|
|
14
15
|
}, []);
|
|
15
16
|
const park = React$1.useCallback(() => {
|
|
16
|
-
if (supportsMoveBefore
|
|
17
|
-
|
|
17
|
+
if (!supportsMoveBefore || !host?.isConnected) return;
|
|
18
|
+
if (host.parentElement === document.body) return;
|
|
19
|
+
try {
|
|
18
20
|
document.body.moveBefore(host, null);
|
|
21
|
+
} catch {
|
|
22
|
+
return;
|
|
19
23
|
}
|
|
24
|
+
host.style.display = "none";
|
|
25
|
+
setParkCount((count) => count + 1);
|
|
20
26
|
}, [host]);
|
|
21
27
|
return React$1.useMemo(() => ({
|
|
22
28
|
host,
|
|
23
|
-
park
|
|
24
|
-
|
|
29
|
+
park,
|
|
30
|
+
parkCount
|
|
31
|
+
}), [
|
|
32
|
+
host,
|
|
33
|
+
park,
|
|
34
|
+
parkCount
|
|
35
|
+
]);
|
|
25
36
|
}
|
|
26
37
|
function ReparentContent({ handle, children }) {
|
|
27
38
|
if (!handle.host) return null;
|
|
@@ -29,14 +40,17 @@ function ReparentContent({ handle, children }) {
|
|
|
29
40
|
}
|
|
30
41
|
function ReparentSlot({ handle, ...props }) {
|
|
31
42
|
const ref = React$1.useRef(null);
|
|
32
|
-
const host = handle
|
|
43
|
+
const { host, parkCount } = handle;
|
|
33
44
|
React$1.useLayoutEffect(() => {
|
|
34
45
|
const slot = ref.current;
|
|
35
|
-
if (!slot || !host) return;
|
|
46
|
+
if (!slot || !host || host.parentElement === slot) return;
|
|
36
47
|
host.style.display = "contents";
|
|
37
|
-
if (supportsMoveBefore && host.isConnected
|
|
38
|
-
|
|
39
|
-
|
|
48
|
+
if (supportsMoveBefore && host.isConnected === slot.isConnected) try {
|
|
49
|
+
slot.moveBefore(host, null);
|
|
50
|
+
return;
|
|
51
|
+
} catch {}
|
|
52
|
+
slot.appendChild(host);
|
|
53
|
+
}, [host, parkCount]);
|
|
40
54
|
return /* @__PURE__ */ jsx("div", {
|
|
41
55
|
"data-slot": "reparent-slot",
|
|
42
56
|
ref,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reparent.js","names":["React"],"sources":["../../src/components/reparent.tsx"],"sourcesContent":["import * as React from 'react'\nimport { createPortal } from 'react-dom'\n\n// moveBefore ships in Chrome/Edge 133+, Firefox 144+; Safari has no state-preserving move\nconst supportsMoveBefore =\n typeof Element !== 'undefined' && 'moveBefore' in Element.prototype\n\ntype MovableElement = Element & {\n moveBefore: (node: Node, child: Node | null) => void\n}\n\ninterface ReparentHandle {\n host: HTMLElement | null\n park: () => void\n}\n\n// host created after mount so server and client hydrate the same (empty) markup\nfunction useReparent(): ReparentHandle {\n const [host, setHost] = React.useState<HTMLElement | null>(null)\n React.useEffect(() => {\n const el = document.createElement('div')\n el.style.display = 'contents'\n setHost(el)\n return () => el.remove()\n }, [])\n const park = React.useCallback(() => {\n if (supportsMoveBefore
|
|
1
|
+
{"version":3,"file":"reparent.js","names":["React"],"sources":["../../src/components/reparent.tsx"],"sourcesContent":["import * as React from 'react'\nimport { createPortal } from 'react-dom'\n\n// moveBefore ships in Chrome/Edge 133+, Firefox 144+; Safari has no state-preserving move\nconst supportsMoveBefore =\n typeof Element !== 'undefined' && 'moveBefore' in Element.prototype\n\ntype MovableElement = Element & {\n moveBefore: (node: Node, child: Node | null) => void\n}\n\ninterface ReparentHandle {\n host: HTMLElement | null\n park: () => void\n parkCount?: number\n}\n\n// host created after mount so server and client hydrate the same (empty) markup\nfunction useReparent(): ReparentHandle {\n const [host, setHost] = React.useState<HTMLElement | null>(null)\n const [parkCount, setParkCount] = React.useState(0)\n React.useEffect(() => {\n const el = document.createElement('div')\n el.style.display = 'contents'\n setHost(el)\n return () => el.remove()\n }, [])\n const park = React.useCallback(() => {\n if (!supportsMoveBefore || !host?.isConnected) return\n if (host.parentElement === document.body) return\n try {\n ;(document.body as unknown as MovableElement).moveBefore(host, null)\n } catch {\n return\n }\n host.style.display = 'none'\n // re-runs every slot's adopt effect, so a park with no layout swap still recovers\n setParkCount((count) => count + 1)\n }, [host])\n return React.useMemo(\n () => ({ host, park, parkCount }),\n [host, park, parkCount],\n )\n}\n\nfunction ReparentContent({\n handle,\n children,\n}: {\n handle: ReparentHandle\n children: React.ReactNode\n}) {\n if (!handle.host) return null\n return createPortal(children, handle.host)\n}\n\ninterface ReparentSlotProps extends React.ComponentProps<'div'> {\n handle: ReparentHandle\n}\n\nfunction ReparentSlot({ handle, ...props }: ReparentSlotProps) {\n const ref = React.useRef<HTMLDivElement>(null)\n const { host, parkCount } = handle\n React.useLayoutEffect(() => {\n const slot = ref.current\n if (!slot || !host || host.parentElement === slot) return\n host.style.display = 'contents'\n // moveBefore throws unless node and new parent are both connected or both detached\n if (supportsMoveBefore && host.isConnected === slot.isConnected) {\n try {\n ;(slot as unknown as MovableElement).moveBefore(host, null)\n return\n } catch {}\n }\n slot.appendChild(host)\n }, [host, parkCount])\n return <div data-slot=\"reparent-slot\" ref={ref} {...props} />\n}\n\nexport { ReparentContent, ReparentSlot, supportsMoveBefore, useReparent }\nexport type { ReparentHandle, ReparentSlotProps }\n"],"mappings":";;;;;AAIA,MAAM,qBACJ,OAAO,YAAY,eAAe,gBAAgB,QAAQ;AAa5D,SAAS,cAA8B;CACrC,MAAM,CAAC,MAAM,WAAWA,QAAM,SAA6B,IAAI;CAC/D,MAAM,CAAC,WAAW,gBAAgBA,QAAM,SAAS,CAAC;CAClD,QAAM,gBAAgB;EACpB,MAAM,KAAK,SAAS,cAAc,KAAK;EACvC,GAAG,MAAM,UAAU;EACnB,QAAQ,EAAE;EACV,aAAa,GAAG,OAAO;CACzB,GAAG,CAAC,CAAC;CACL,MAAM,OAAOA,QAAM,kBAAkB;EACnC,IAAI,CAAC,sBAAsB,CAAC,MAAM,aAAa;EAC/C,IAAI,KAAK,kBAAkB,SAAS,MAAM;EAC1C,IAAI;GACD,SAAU,KAAmC,WAAW,MAAM,IAAI;EACrE,QAAQ;GACN;EACF;EACA,KAAK,MAAM,UAAU;EAErB,cAAc,UAAU,QAAQ,CAAC;CACnC,GAAG,CAAC,IAAI,CAAC;CACT,OAAOA,QAAM,eACJ;EAAE;EAAM;EAAM;CAAU,IAC/B;EAAC;EAAM;EAAM;CAAS,CACxB;AACF;AAEA,SAAS,gBAAgB,EACvB,QACA,YAIC;CACD,IAAI,CAAC,OAAO,MAAM,OAAO;CACzB,OAAO,aAAa,UAAU,OAAO,IAAI;AAC3C;AAMA,SAAS,aAAa,EAAE,QAAQ,GAAG,SAA4B;CAC7D,MAAM,MAAMA,QAAM,OAAuB,IAAI;CAC7C,MAAM,EAAE,MAAM,cAAc;CAC5B,QAAM,sBAAsB;EAC1B,MAAM,OAAO,IAAI;EACjB,IAAI,CAAC,QAAQ,CAAC,QAAQ,KAAK,kBAAkB,MAAM;EACnD,KAAK,MAAM,UAAU;EAErB,IAAI,sBAAsB,KAAK,gBAAgB,KAAK,aAClD,IAAI;GACD,KAAoC,WAAW,MAAM,IAAI;GAC1D;EACF,QAAQ,CAAC;EAEX,KAAK,YAAY,IAAI;CACvB,GAAG,CAAC,MAAM,SAAS,CAAC;CACpB,OAAO,oBAAC,OAAD;EAAK,aAAU;EAAqB;EAAK,GAAI;CAAQ,CAAA;AAC9D"}
|