@zayne-labs/ui-react 0.6.2 → 0.7.0

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.
Files changed (61) hide show
  1. package/dist/esm/{chunk-ENDWJXPF.js → chunk-L2SROZYQ.js} +2 -2
  2. package/dist/esm/{chunk-ENDWJXPF.js.map → chunk-L2SROZYQ.js.map} +1 -1
  3. package/dist/esm/common/await/index.d.ts +7 -5
  4. package/dist/esm/common/await/index.js +37 -2
  5. package/dist/esm/common/await/index.js.map +1 -1
  6. package/dist/esm/common/focus-scope/index.d.ts +32 -0
  7. package/dist/esm/common/focus-scope/index.js +232 -0
  8. package/dist/esm/common/focus-scope/index.js.map +1 -0
  9. package/dist/esm/common/show/index.js +48 -2
  10. package/dist/esm/common/show/index.js.map +1 -1
  11. package/dist/esm/common/slot/index.js +1 -1
  12. package/dist/esm/common/suspense-with-boundary/index.js +11 -2
  13. package/dist/esm/common/suspense-with-boundary/index.js.map +1 -1
  14. package/dist/esm/common/switch/index.js +38 -2
  15. package/dist/esm/common/switch/index.js.map +1 -1
  16. package/dist/esm/common/teleport/index.js +28 -1
  17. package/dist/esm/common/teleport/index.js.map +1 -1
  18. package/dist/esm/ui/card/index.js +43 -4
  19. package/dist/esm/ui/card/index.js.map +1 -1
  20. package/dist/esm/ui/carousel/index.js +272 -4
  21. package/dist/esm/ui/carousel/index.js.map +1 -1
  22. package/dist/esm/ui/drag-scroll/index.js +117 -2
  23. package/dist/esm/ui/drag-scroll/index.js.map +1 -1
  24. package/dist/esm/ui/drop-zone/index.js +137 -2
  25. package/dist/esm/ui/drop-zone/index.js.map +1 -1
  26. package/dist/esm/ui/form/index.js +508 -12
  27. package/dist/esm/ui/form/index.js.map +1 -1
  28. package/package.json +8 -11
  29. package/dist/esm/chunk-CB2EZJYW.js +0 -31
  30. package/dist/esm/chunk-CB2EZJYW.js.map +0 -1
  31. package/dist/esm/chunk-CWUEUCR5.js +0 -3
  32. package/dist/esm/chunk-CWUEUCR5.js.map +0 -1
  33. package/dist/esm/chunk-DJIVSXN7.js +0 -24
  34. package/dist/esm/chunk-DJIVSXN7.js.map +0 -1
  35. package/dist/esm/chunk-E42DOTGX.js +0 -119
  36. package/dist/esm/chunk-E42DOTGX.js.map +0 -1
  37. package/dist/esm/chunk-FPCKBOJN.js +0 -50
  38. package/dist/esm/chunk-FPCKBOJN.js.map +0 -1
  39. package/dist/esm/chunk-GVL6BLX5.js +0 -274
  40. package/dist/esm/chunk-GVL6BLX5.js.map +0 -1
  41. package/dist/esm/chunk-LIUXM66P.js +0 -509
  42. package/dist/esm/chunk-LIUXM66P.js.map +0 -1
  43. package/dist/esm/chunk-NPIJ4XZP.js +0 -13
  44. package/dist/esm/chunk-NPIJ4XZP.js.map +0 -1
  45. package/dist/esm/chunk-PNYEIX7F.js +0 -3
  46. package/dist/esm/chunk-PNYEIX7F.js.map +0 -1
  47. package/dist/esm/chunk-PXYYL2LL.js +0 -45
  48. package/dist/esm/chunk-PXYYL2LL.js.map +0 -1
  49. package/dist/esm/chunk-RQZL6ZG6.js +0 -139
  50. package/dist/esm/chunk-RQZL6ZG6.js.map +0 -1
  51. package/dist/esm/chunk-SVQ4WBSO.js +0 -40
  52. package/dist/esm/chunk-SVQ4WBSO.js.map +0 -1
  53. package/dist/esm/common/index.d.ts +0 -12
  54. package/dist/esm/common/index.js +0 -12
  55. package/dist/esm/common/index.js.map +0 -1
  56. package/dist/esm/index.d.ts +0 -20
  57. package/dist/esm/index.js +0 -19
  58. package/dist/esm/index.js.map +0 -1
  59. package/dist/esm/ui/index.d.ts +0 -11
  60. package/dist/esm/ui/index.js +0 -19
  61. package/dist/esm/ui/index.js.map +0 -1
@@ -43,5 +43,5 @@ function SlotClone(props) {
43
43
  }
44
44
 
45
45
  export { Slot, Slottable };
46
- //# sourceMappingURL=chunk-ENDWJXPF.js.map
47
- //# sourceMappingURL=chunk-ENDWJXPF.js.map
46
+ //# sourceMappingURL=chunk-L2SROZYQ.js.map
47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AAAA;AAIF,EAAA,uBAAQ,KAAA,CAAA,aAAA,CAAA,SAAA,EAAA,EAAW,GAAG,eAAA,EAAA,EAAkB,QAAS,CAAA;AAClD;AASA,SAAS,UAAU,KAAuB,EAAA;AACzC,EAAA,MAAM,EAAE,QAAU,EAAA,GAAA,EAAK,YAAc,EAAA,GAAG,iBAAoB,GAAA,KAAA;AAE5D,EAAI,IAAA,CAAC,cAA6B,CAAA,QAAQ,CAAG,EAAA;AAC5C,IAAO,OAAA,QAAA,CAAS,MAAM,QAAQ,CAAA,GAAI,IAAI,QAAS,CAAA,IAAA,CAAK,IAAI,CAAI,GAAA,IAAA;AAAA;AAG7D,EAAA,MAAM,QAAW,GAAA,QAAA,CAAS,KAAM,CAAA,GAAA,IAAQ,QAAqC,CAAA,GAAA;AAE7E,EAAA,MAAM,WAAc,GAAA;AAAA,IACnB,GAAG,UAAA,CAAW,eAAiB,EAAA,QAAA,CAAS,KAAK,CAAA;AAAA,IAC7C,KAAK,YAAe,GAAA,WAAA,CAAY,CAAC,YAAc,EAAA,QAA8B,CAAC,CAAI,GAAA;AAAA,GACnF;AAEA,EAAO,OAAA,YAAA,CAAa,UAAU,WAAW,CAAA;AAC1C","file":"chunk-ENDWJXPF.js","sourcesContent":["import * as React from \"react\";\n\nimport { type InferProps, composeRefs, mergeProps } from \"@zayne-labs/toolkit-react/utils\";\nimport { isArray } from \"@zayne-labs/toolkit-type-helpers\";\nimport { Children, cloneElement, isValidElement } from \"react\";\n\ntype SlotProps = InferProps<HTMLElement>;\n\n/* -------------------------------------------------------------------------------------------------\n * Slottable\n * ----------------------------------------------------------------------------------------------- */\n\nexport function Slottable({ children }: Pick<SlotProps, \"children\">) {\n\treturn children;\n}\n\nconst isSlottable = (child: React.ReactNode): child is React.ReactElement => {\n\treturn isValidElement(child) && child.type === Slottable;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * Slot\n * ----------------------------------------------------------------------------------------------- */\n\nexport function Slot(props: SlotProps) {\n\tconst { children, ...restOfSlotProps } = props;\n\n\tconst childrenArray = isArray<React.ReactNode>(children) ? children : [children];\n\tconst slottable = childrenArray.find((element) => isSlottable(element));\n\n\tif (slottable) {\n\t\t// == The new element to render is the one passed as a child of `Slottable`\n\t\tconst newElement = (slottable.props as SlotProps).children;\n\n\t\tif (Children.count(newElement) > 1) {\n\t\t\treturn Children.only(null);\n\t\t}\n\n\t\tconst newElementChildren = childrenArray.map((child) => {\n\t\t\tif (child === slottable) {\n\t\t\t\t// == Because the new element will be the one rendered, we are only interested in grabbing its children (`newElement.props.children`)\n\t\t\t\treturn isValidElement<SlotProps>(newElement) && newElement.props.children;\n\t\t\t}\n\n\t\t\treturn child;\n\t\t});\n\n\t\treturn (\n\t\t\t<SlotClone {...restOfSlotProps}>\n\t\t\t\t{isValidElement(newElement) && cloneElement(newElement, undefined, newElementChildren)}\n\t\t\t</SlotClone>\n\t\t);\n\t}\n\n\treturn <SlotClone {...restOfSlotProps}>{children}</SlotClone>;\n}\n\ntype SlotCloneProps = {\n\tchildren: React.ReactNode;\n\tref?: React.RefObject<HTMLElement>;\n};\n\ntype UnknownProps = Record<string, unknown>;\n\nfunction SlotClone(props: SlotCloneProps) {\n\tconst { children, ref: forwardedRef, ...restOfSlotProps } = props;\n\n\tif (!isValidElement<UnknownProps>(children)) {\n\t\treturn Children.count(children) > 1 ? Children.only(null) : null;\n\t}\n\n\tconst childRef = children.props.ref ?? (children as unknown as UnknownProps).ref;\n\n\tconst clonedProps = {\n\t\t...mergeProps(restOfSlotProps, children.props),\n\t\tref: forwardedRef ? composeRefs([forwardedRef, childRef as React.Ref<unknown>]) : childRef,\n\t};\n\n\treturn cloneElement(children, clonedProps);\n}\n"]}
1
+ {"version":3,"sources":["../../src/components/common/slot/slot.tsx"],"names":[],"mappings":";;;;;;AAYO,SAAS,SAAA,CAAU,EAAE,QAAA,EAAyC,EAAA;AACpE,EAAO,OAAA,QAAA;AACR;AAEA,IAAM,WAAA,GAAc,CAAC,KAAwD,KAAA;AAC5E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AI,IAAA,CAAC,cAA6B,CAAA,QAAQ,CAAG,EAAA;AAC5C,IAAO,OAAA,QAAA,CAAS,MAAM,QAAQ,CAAA,GAAI,IAAI,QAAS,CAAA,IAAA,CAAK,IAAI,CAAI,GAAA,IAAA;AAAA;AAG7D,EAAA,MAAM,QAAY,GAAA,QAAA,CAAS,KAAM,CAAA,GAAA,IAC5B,QAAqC,CAAA,GAAA;AAE1C,EAAA,MAAM,WAAc,GAAA;AAAA,IACnB,GAAG,UAAA,CAAW,eAAiB,EAAA,QAAA,CAAS,KAAK,CAAA;AAAA,IAC7C,KAAK,YAAe,GAAA,WAAA,CAAY,CAAC,YAAc,EAAA,QAAQ,CAAC,CAAI,GAAA;AAAA,GAC7D;AAEA,EAAO,OAAA,YAAA,CAAa,UAAU,WAAW,CAAA;AAC1C","file":"chunk-L2SROZYQ.js","sourcesContent":["import * as React from \"react\";\n\nimport { type InferProps, composeRefs, mergeProps } from \"@zayne-labs/toolkit-react/utils\";\nimport { isArray } from \"@zayne-labs/toolkit-type-helpers\";\nimport { Children, cloneElement, isValidElement } from \"react\";\n\ntype SlotProps = InferProps<HTMLElement>;\n\n/* -------------------------------------------------------------------------------------------------\n * Slottable\n * ----------------------------------------------------------------------------------------------- */\n\nexport function Slottable({ children }: Pick<SlotProps, \"children\">) {\n\treturn children;\n}\n\nconst isSlottable = (child: React.ReactNode): child is React.ReactElement => {\n\treturn isValidElement(child) && child.type === Slottable;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * Slot\n * ----------------------------------------------------------------------------------------------- */\n\nexport function Slot(props: SlotProps) {\n\tconst { children, ...restOfSlotProps } = props;\n\n\tconst childrenArray = isArray<React.ReactNode>(children) ? children : [children];\n\tconst slottable = childrenArray.find((element) => isSlottable(element));\n\n\tif (slottable) {\n\t\t// == The new element to render is the one passed as a child of `Slottable`\n\t\tconst newElement = (slottable.props as SlotProps).children;\n\n\t\tif (Children.count(newElement) > 1) {\n\t\t\treturn Children.only(null);\n\t\t}\n\n\t\tconst newElementChildren = childrenArray.map((child) => {\n\t\t\tif (child === slottable) {\n\t\t\t\t// == Because the new element will be the one rendered, we are only interested in grabbing its children (`newElement.props.children`)\n\t\t\t\treturn isValidElement<SlotProps>(newElement) && newElement.props.children;\n\t\t\t}\n\n\t\t\treturn child;\n\t\t});\n\n\t\treturn (\n\t\t\t<SlotClone {...restOfSlotProps}>\n\t\t\t\t{isValidElement(newElement) && cloneElement(newElement, undefined, newElementChildren)}\n\t\t\t</SlotClone>\n\t\t);\n\t}\n\n\treturn <SlotClone {...restOfSlotProps}>{children}</SlotClone>;\n}\n\ntype SlotCloneProps = {\n\tchildren: React.ReactNode;\n\tref?: React.RefObject<HTMLElement>;\n};\n\ntype UnknownProps = Record<string, unknown>;\n\nfunction SlotClone(props: SlotCloneProps) {\n\tconst { children, ref: forwardedRef, ...restOfSlotProps } = props;\n\n\tif (!isValidElement<UnknownProps>(children)) {\n\t\treturn Children.count(children) > 1 ? Children.only(null) : null;\n\t}\n\n\tconst childRef = (children.props.ref\n\t\t?? (children as unknown as UnknownProps).ref) as React.Ref<HTMLElement>;\n\n\tconst clonedProps = {\n\t\t...mergeProps(restOfSlotProps, children.props),\n\t\tref: forwardedRef ? composeRefs([forwardedRef, childRef]) : childRef,\n\t};\n\n\treturn cloneElement(children, clonedProps);\n}\n"]}
@@ -3,13 +3,15 @@ import { DiscriminatedRenderProps } from '@zayne-labs/toolkit-react/utils';
3
3
  import { SuspenseWithBoundaryProps } from '../suspense-with-boundary/index.js';
4
4
  import '../../types-CeWumkhm.js';
5
5
 
6
- type RenderPropFn<Tvalue> = (result: Tvalue) => react.ReactNode;
7
- type AwaitProps<Tvalue> = AwaitInnerProps<Tvalue> & Pick<SuspenseWithBoundaryProps, "errorFallback" | "fallback"> & {
6
+ type RenderPropFn<TValue> = (result: TValue) => react.ReactNode;
7
+ type AwaitProps<TValue> = AwaitInnerProps<TValue> & Pick<SuspenseWithBoundaryProps, "errorFallback" | "fallback"> & {
8
+ asChild?: boolean;
8
9
  wrapperVariant?: "none" | "only-boundary" | "only-suspense" | "suspense-and-boundary";
9
10
  };
10
- declare function Await<Tvalue>(props: AwaitProps<Tvalue>): react.JSX.Element;
11
- type AwaitInnerProps<Tvalue> = DiscriminatedRenderProps<RenderPropFn<Tvalue>> & {
12
- promise: Promise<Tvalue>;
11
+ declare function Await<TValue>(props: AwaitProps<TValue>): react.JSX.Element;
12
+ type AwaitInnerProps<TValue> = DiscriminatedRenderProps<react.ReactNode | RenderPropFn<TValue>> & {
13
+ asChild?: boolean;
14
+ promise: Promise<TValue>;
13
15
  };
14
16
 
15
17
  export { Await, type AwaitInnerProps };
@@ -1,5 +1,40 @@
1
- export { Await } from '../../chunk-DJIVSXN7.js';
2
- import '../../chunk-OM4ZFFQS.js';
1
+ import { Slot } from '../../chunk-L2SROZYQ.js';
2
+ import { ErrorBoundary } from '../../chunk-OM4ZFFQS.js';
3
3
  import '../../chunk-PZ5AY32C.js';
4
+ import * as React from 'react';
5
+ import { Fragment, Suspense, use } from 'react';
6
+
7
+ function Await(props) {
8
+ const { errorFallback, fallback, wrapperVariant = "suspense-and-boundary", ...restOfProps } = props;
9
+ const WithErrorBoundary = wrapperVariant === "only-boundary" || wrapperVariant === "suspense-and-boundary" ? ErrorBoundary : Fragment;
10
+ const WithSuspense = wrapperVariant === "only-suspense" || wrapperVariant === "suspense-and-boundary" ? Suspense : Fragment;
11
+ const errorBoundaryProps = Boolean(errorFallback) && { fallback: errorFallback };
12
+ const suspenseProps = Boolean(fallback) && { fallback };
13
+ return /* @__PURE__ */ React.createElement(WithErrorBoundary, { ...errorBoundaryProps }, /* @__PURE__ */ React.createElement(WithSuspense, { ...suspenseProps }, /* @__PURE__ */ React.createElement(AwaitInner, { ...restOfProps })));
14
+ }
15
+ function AwaitInner(props) {
16
+ const { asChild, children, promise, render } = props;
17
+ const result = use(promise);
18
+ const Component = asChild ? Slot : Fragment;
19
+ const componentProps = asChild && { promise };
20
+ let resolvedChildren;
21
+ switch (true) {
22
+ case typeof children === "function": {
23
+ resolvedChildren = children(result);
24
+ break;
25
+ }
26
+ case typeof render === "function": {
27
+ resolvedChildren = render(result);
28
+ break;
29
+ }
30
+ default: {
31
+ resolvedChildren = children ?? render;
32
+ break;
33
+ }
34
+ }
35
+ return /* @__PURE__ */ React.createElement(Component, { ...componentProps }, resolvedChildren);
36
+ }
37
+
38
+ export { Await };
4
39
  //# sourceMappingURL=index.js.map
5
40
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
1
+ {"version":3,"sources":["../../../../src/components/common/await/await.tsx"],"names":["ReactFragment"],"mappings":";;;;;;AAkBO,SAAS,MAAc,KAA2B,EAAA;AACxD,EAAA,MAAM,EAAE,aAAe,EAAA,QAAA,EAAU,iBAAiB,uBAAyB,EAAA,GAAG,aAAgB,GAAA,KAAA;AAE9F,EAAA,MAAM,iBACL,GAAA,cAAA,KAAmB,eAAmB,IAAA,cAAA,KAAmB,0BACtD,aACA,GAAAA,QAAA;AAEJ,EAAA,MAAM,YACL,GAAA,cAAA,KAAmB,eAAmB,IAAA,cAAA,KAAmB,0BACtD,QACA,GAAAA,QAAA;AAEJ,EAAA,MAAM,qBAAqB,OAAQ,CAAA,aAAa,CAAK,IAAA,EAAE,UAAU,aAAc,EAAA;AAE/E,EAAA,MAAM,aAAgB,GAAA,OAAA,CAAQ,QAAQ,CAAA,IAAK,EAAE,QAAS,EAAA;AAEtD,EAAA,uBACE,KAAA,CAAA,aAAA,CAAA,iBAAA,EAAA,EAAmB,GAAG,kBAAA,EAAA,kBACrB,KAAA,CAAA,aAAA,CAAA,YAAA,EAAA,EAAc,GAAG,aAAA,EAAA,kBAChB,KAAA,CAAA,aAAA,CAAA,UAAA,EAAA,EAAY,GAAG,WAAA,EAAa,CAC9B,CACD,CAAA;AAEF;AAOA,SAAS,WAAmB,KAAgC,EAAA;AAC3D,EAAA,MAAM,EAAE,OAAA,EAAS,QAAU,EAAA,OAAA,EAAS,QAAW,GAAA,KAAA;AAE/C,EAAM,MAAA,MAAA,GAAS,IAAI,OAAO,CAAA;AAE1B,EAAM,MAAA,SAAA,GAAY,UAAU,IAAO,GAAAA,QAAA;AAEnC,EAAM,MAAA,cAAA,GAAiB,OAAW,IAAA,EAAE,OAAQ,EAAA;AAE5C,EAAI,IAAA,gBAAA;AAEJ,EAAA,QAAQ,IAAM;AAAA,IACb,KAAK,OAAO,QAAA,KAAa,UAAY,EAAA;AACpC,MAAA,gBAAA,GAAmB,SAAS,MAAM,CAAA;AAClC,MAAA;AAAA;AACD,IACA,KAAK,OAAO,MAAA,KAAW,UAAY,EAAA;AAClC,MAAA,gBAAA,GAAmB,OAAO,MAAM,CAAA;AAChC,MAAA;AAAA;AACD,IACA,SAAS;AACR,MAAA,gBAAA,GAAmB,QAAY,IAAA,MAAA;AAC/B,MAAA;AAAA;AACD;AAGD,EAAA,uBAAQ,KAAA,CAAA,aAAA,CAAA,SAAA,EAAA,EAAW,GAAG,cAAA,EAAA,EAAiB,gBAAiB,CAAA;AACzD","file":"index.js","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\nimport type { DiscriminatedRenderProps } from \"@zayne-labs/toolkit-react/utils\";\nimport { Fragment as ReactFragment, Suspense, use } from \"react\";\nimport { ErrorBoundary } from \"../error-boundary\";\nimport { Slot } from \"../slot\";\nimport type { SuspenseWithBoundaryProps } from \"../suspense-with-boundary\";\n\ntype RenderPropFn<TValue> = (result: TValue) => React.ReactNode;\n\ntype AwaitProps<TValue> = AwaitInnerProps<TValue>\n\t& Pick<SuspenseWithBoundaryProps, \"errorFallback\" | \"fallback\"> & {\n\t\tasChild?: boolean;\n\t\twrapperVariant?: \"none\" | \"only-boundary\" | \"only-suspense\" | \"suspense-and-boundary\";\n\t};\n\nexport function Await<TValue>(props: AwaitProps<TValue>) {\n\tconst { errorFallback, fallback, wrapperVariant = \"suspense-and-boundary\", ...restOfProps } = props;\n\n\tconst WithErrorBoundary =\n\t\twrapperVariant === \"only-boundary\" || wrapperVariant === \"suspense-and-boundary\"\n\t\t\t? ErrorBoundary\n\t\t\t: ReactFragment;\n\n\tconst WithSuspense =\n\t\twrapperVariant === \"only-suspense\" || wrapperVariant === \"suspense-and-boundary\"\n\t\t\t? Suspense\n\t\t\t: ReactFragment;\n\n\tconst errorBoundaryProps = Boolean(errorFallback) && { fallback: errorFallback };\n\n\tconst suspenseProps = Boolean(fallback) && { fallback };\n\n\treturn (\n\t\t<WithErrorBoundary {...errorBoundaryProps}>\n\t\t\t<WithSuspense {...suspenseProps}>\n\t\t\t\t<AwaitInner {...restOfProps} />\n\t\t\t</WithSuspense>\n\t\t</WithErrorBoundary>\n\t);\n}\n\nexport type AwaitInnerProps<TValue> = DiscriminatedRenderProps<React.ReactNode | RenderPropFn<TValue>> & {\n\tasChild?: boolean;\n\tpromise: Promise<TValue>;\n};\n\nfunction AwaitInner<TValue>(props: AwaitInnerProps<TValue>) {\n\tconst { asChild, children, promise, render } = props;\n\n\tconst result = use(promise);\n\n\tconst Component = asChild ? Slot : ReactFragment;\n\n\tconst componentProps = asChild && { promise };\n\n\tlet resolvedChildren: React.ReactNode;\n\n\tswitch (true) {\n\t\tcase typeof children === \"function\": {\n\t\t\tresolvedChildren = children(result);\n\t\t\tbreak;\n\t\t}\n\t\tcase typeof render === \"function\": {\n\t\t\tresolvedChildren = render(result);\n\t\t\tbreak;\n\t\t}\n\t\tdefault: {\n\t\t\tresolvedChildren = children ?? render;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn <Component {...componentProps}>{resolvedChildren}</Component>;\n}\n"]}
@@ -0,0 +1,32 @@
1
+ import * as react from 'react';
2
+ import { InferProps } from '@zayne-labs/toolkit-react/utils';
3
+
4
+ type FocusScopeElement = react.ComponentRef<"div">;
5
+ type FocusScopeProps = Omit<InferProps<"div">, "ref"> & {
6
+ /**
7
+ * When `true`, tabbing from last item will focus first tabbable
8
+ * and shift+tab from first item will focus last tababble.
9
+ * @defaultValue false
10
+ */
11
+ loop?: boolean;
12
+ /**
13
+ * Event handler called when auto-focusing on mount.
14
+ * Can be prevented.
15
+ */
16
+ onMountAutoFocus?: (event: Event) => void;
17
+ /**
18
+ * Event handler called when auto-focusing on unmount.
19
+ * Can be prevented.
20
+ */
21
+ onUnmountAutoFocus?: (event: Event) => void;
22
+ ref?: react.Ref<FocusScopeElement>;
23
+ /**
24
+ * When `true`, focus cannot escape the focus scope via keyboard,
25
+ * pointer, or a programmatic focus.
26
+ * @defaultValue false
27
+ */
28
+ trapped?: boolean;
29
+ };
30
+ declare function FocusScope(props: FocusScopeProps): react.JSX.Element;
31
+
32
+ export { FocusScope };
@@ -0,0 +1,232 @@
1
+ import '../../chunk-PZ5AY32C.js';
2
+ import * as React from 'react';
3
+ import { useState, useRef, useEffect } from 'react';
4
+ import { useCallbackRef } from '@zayne-labs/toolkit-react';
5
+ import { composeRefs } from '@zayne-labs/toolkit-react/utils';
6
+
7
+ // src/components/common/focus-scope/utils.ts
8
+ var focusFirst = (candidates, options = {}) => {
9
+ const { select = false } = options;
10
+ const previouslyFocusedElement = document.activeElement;
11
+ for (const candidate of candidates) {
12
+ focusElement(candidate, { select });
13
+ if (document.activeElement !== previouslyFocusedElement) return;
14
+ }
15
+ };
16
+ var getTabbableEdges = (container) => {
17
+ const candidates = getTabbableCandidates(container);
18
+ const first = findVisible(candidates, container);
19
+ const last = findVisible(candidates.reverse(), container);
20
+ return [first, last];
21
+ };
22
+ var getTabbableCandidates = (container) => {
23
+ const nodes = [];
24
+ const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
25
+ acceptNode: (node) => {
26
+ const isHiddenInput = node.tagName === "INPUT" && node.type === "hidden";
27
+ if (node.disabled || node.hidden || isHiddenInput) return NodeFilter.FILTER_SKIP;
28
+ return node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
29
+ }
30
+ });
31
+ while (walker.nextNode()) {
32
+ nodes.push(walker.currentNode);
33
+ }
34
+ return nodes;
35
+ };
36
+ var findVisible = (elements, container) => {
37
+ if (elements.length === 0) return null;
38
+ let visibleElement = null;
39
+ for (const element of elements) {
40
+ if (!isHidden(element, { upTo: container })) {
41
+ visibleElement = element;
42
+ break;
43
+ }
44
+ }
45
+ return visibleElement;
46
+ };
47
+ var isHidden = (initialNode, options) => {
48
+ const { upTo } = options;
49
+ if (!initialNode || getComputedStyle(initialNode).visibility === "hidden") {
50
+ return true;
51
+ }
52
+ let currentNode = initialNode;
53
+ while (currentNode) {
54
+ if (upTo !== void 0 && currentNode === upTo) {
55
+ return false;
56
+ }
57
+ if (getComputedStyle(currentNode).display === "none") {
58
+ return true;
59
+ }
60
+ currentNode = currentNode.parentElement;
61
+ }
62
+ return false;
63
+ };
64
+ var isSelectableInput = (element) => {
65
+ return element instanceof HTMLInputElement && "select" in element;
66
+ };
67
+ var focusElement = (element, options = {}) => {
68
+ const { select = false } = options;
69
+ if (element && typeof element.focus === "function") {
70
+ const previouslyFocusedElement = document.activeElement;
71
+ element.focus({ preventScroll: true });
72
+ if (element !== previouslyFocusedElement && isSelectableInput(element) && select) {
73
+ element.select();
74
+ }
75
+ }
76
+ };
77
+ var createFocusScopesStack = () => {
78
+ let stack = [];
79
+ const api = {
80
+ add(focusScope) {
81
+ const activeFocusScope = stack[0];
82
+ if (focusScope !== activeFocusScope) {
83
+ activeFocusScope?.pause();
84
+ }
85
+ stack = arrayRemove(stack, focusScope);
86
+ stack.unshift(focusScope);
87
+ },
88
+ remove(focusScope) {
89
+ stack = arrayRemove(stack, focusScope);
90
+ stack[0]?.resume();
91
+ }
92
+ };
93
+ return api;
94
+ };
95
+ var focusScopesStack = createFocusScopesStack();
96
+ var arrayRemove = (array, item) => {
97
+ const updatedArray = [...array];
98
+ const index = updatedArray.indexOf(item);
99
+ if (index !== -1) {
100
+ updatedArray.splice(index, 1);
101
+ }
102
+ return updatedArray;
103
+ };
104
+ var removeLinks = (items) => {
105
+ return items.filter((item) => item.tagName !== "A");
106
+ };
107
+
108
+ // src/components/common/focus-scope/focus-scope.tsx
109
+ var AUTOFOCUS_ON_MOUNT = "focusScope.autoFocusOnMount";
110
+ var AUTOFOCUS_ON_UNMOUNT = "focusScope.autoFocusOnUnmount";
111
+ var EVENT_OPTIONS = { bubbles: false, cancelable: true };
112
+ function FocusScope(props) {
113
+ const {
114
+ loop = false,
115
+ onMountAutoFocus,
116
+ onUnmountAutoFocus,
117
+ ref: forwardedRef,
118
+ trapped = false,
119
+ ...scopeProps
120
+ } = props;
121
+ const [container, setContainer] = useState(null);
122
+ const savedOnMountAutoFocus = useCallbackRef(onMountAutoFocus);
123
+ const savedOnUnmountAutoFocus = useCallbackRef(onUnmountAutoFocus);
124
+ const lastFocusedElementRef = useRef(null);
125
+ const composedRefs = composeRefs([forwardedRef, (node) => setContainer(node)]);
126
+ const focusScope = useRef({
127
+ pause() {
128
+ this.paused = true;
129
+ },
130
+ paused: false,
131
+ resume() {
132
+ this.paused = false;
133
+ }
134
+ }).current;
135
+ useEffect(() => {
136
+ if (!trapped) return;
137
+ const handleFocusIn = function(event) {
138
+ if (focusScope.paused || !container) return;
139
+ const target = event.target;
140
+ if (container.contains(target)) {
141
+ lastFocusedElementRef.current = target;
142
+ } else {
143
+ focusElement(lastFocusedElementRef.current, { select: true });
144
+ }
145
+ };
146
+ const handleFocusOut = function(event) {
147
+ if (focusScope.paused || !container) return;
148
+ const relatedTarget = event.relatedTarget;
149
+ if (relatedTarget === null) return;
150
+ if (!container.contains(relatedTarget)) {
151
+ focusElement(lastFocusedElementRef.current, { select: true });
152
+ }
153
+ };
154
+ const handleMutations = function(mutations) {
155
+ const focusedElement = document.activeElement;
156
+ if (focusedElement !== document.body) return;
157
+ for (const mutation of mutations) {
158
+ if (mutation.removedNodes.length > 0) focusElement(container);
159
+ }
160
+ };
161
+ document.addEventListener("focusin", handleFocusIn);
162
+ document.addEventListener("focusout", handleFocusOut);
163
+ const mutationObserver = new MutationObserver(handleMutations);
164
+ if (container) {
165
+ mutationObserver.observe(container, { childList: true, subtree: true });
166
+ }
167
+ return () => {
168
+ document.removeEventListener("focusin", handleFocusIn);
169
+ document.removeEventListener("focusout", handleFocusOut);
170
+ mutationObserver.disconnect();
171
+ };
172
+ }, [trapped, container, focusScope.paused]);
173
+ useEffect(() => {
174
+ if (!container) return;
175
+ focusScopesStack.add(focusScope);
176
+ const previouslyFocusedElement = document.activeElement;
177
+ const hasFocusedCandidate = container.contains(previouslyFocusedElement);
178
+ if (!hasFocusedCandidate) {
179
+ const mountEvent = new CustomEvent(AUTOFOCUS_ON_MOUNT, EVENT_OPTIONS);
180
+ container.addEventListener(AUTOFOCUS_ON_MOUNT, savedOnMountAutoFocus);
181
+ container.dispatchEvent(mountEvent);
182
+ if (!mountEvent.defaultPrevented) {
183
+ focusFirst(removeLinks(getTabbableCandidates(container)), { select: true });
184
+ document.activeElement === previouslyFocusedElement && focusElement(container);
185
+ }
186
+ }
187
+ return () => {
188
+ container.removeEventListener(AUTOFOCUS_ON_MOUNT, savedOnMountAutoFocus);
189
+ setTimeout(() => {
190
+ const unmountEvent = new CustomEvent(AUTOFOCUS_ON_UNMOUNT, EVENT_OPTIONS);
191
+ container.addEventListener(AUTOFOCUS_ON_UNMOUNT, savedOnUnmountAutoFocus);
192
+ container.dispatchEvent(unmountEvent);
193
+ if (!unmountEvent.defaultPrevented) {
194
+ focusElement(document.body, { select: true });
195
+ }
196
+ container.removeEventListener(AUTOFOCUS_ON_UNMOUNT, savedOnUnmountAutoFocus);
197
+ focusScopesStack.remove(focusScope);
198
+ }, 0);
199
+ };
200
+ }, [container, savedOnMountAutoFocus, savedOnUnmountAutoFocus, focusScope]);
201
+ const handleKeyDown = (event) => {
202
+ if (!loop && !trapped) return;
203
+ if (focusScope.paused) return;
204
+ const isTabKey = event.key === "Tab" && !event.altKey && !event.ctrlKey && !event.metaKey;
205
+ const focusedElement = document.activeElement;
206
+ if (!(isTabKey && focusedElement)) return;
207
+ const container2 = event.currentTarget;
208
+ const [first, last] = getTabbableEdges(container2);
209
+ const hasTabbableElementsInside = first && last;
210
+ if (!hasTabbableElementsInside && focusedElement === container2) {
211
+ event.preventDefault();
212
+ return;
213
+ }
214
+ if (!event.shiftKey && focusedElement === last) {
215
+ event.preventDefault();
216
+ if (loop && first) {
217
+ focusElement(first, { select: true });
218
+ }
219
+ }
220
+ if (event.shiftKey && focusedElement === first) {
221
+ event.preventDefault();
222
+ if (loop && last) {
223
+ focusElement(last, { select: true });
224
+ }
225
+ }
226
+ };
227
+ return /* @__PURE__ */ React.createElement("div", { tabIndex: -1, ...scopeProps, onKeyDown: handleKeyDown, ref: composedRefs });
228
+ }
229
+
230
+ export { FocusScope };
231
+ //# sourceMappingURL=index.js.map
232
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/components/common/focus-scope/utils.ts","../../../../src/components/common/focus-scope/focus-scope.tsx"],"names":[],"mappings":";;;;;;;AAAO,IAAM,UAAa,GAAA,CAAC,UAA2B,EAAA,OAAA,GAAgC,EAAO,KAAA;AAC5F,EAAM,MAAA,EAAE,MAAS,GAAA,KAAA,EAAU,GAAA,OAAA;AAE3B,EAAA,MAAM,2BAA2B,QAAS,CAAA,aAAA;AAE1C,EAAA,KAAA,MAAW,aAAa,UAAY,EAAA;AACnC,IAAa,YAAA,CAAA,SAAA,EAAW,EAAE,MAAA,EAAQ,CAAA;AAClC,IAAI,IAAA,QAAA,CAAS,kBAAkB,wBAA0B,EAAA;AAAA;AAE3D,CAAA;AAEO,IAAM,gBAAA,GAAmB,CAAC,SAA2B,KAAA;AAC3D,EAAM,MAAA,UAAA,GAAa,sBAAsB,SAAS,CAAA;AAClD,EAAM,MAAA,KAAA,GAAQ,WAAY,CAAA,UAAA,EAAY,SAAS,CAAA;AAC/C,EAAA,MAAM,IAAO,GAAA,WAAA,CAAY,UAAW,CAAA,OAAA,IAAW,SAAS,CAAA;AACxD,EAAO,OAAA,CAAC,OAAO,IAAI,CAAA;AACpB,CAAA;AAEO,I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KAAA,CAAM,OAAW,IAAA,CAAC,KAAM,CAAA,OAAA;AAClF,IAAA,MAAM,iBAAiB,QAAS,CAAA,aAAA;AAEhC,IAAI,IAAA,EAAE,YAAY,cAAiB,CAAA,EAAA;AAEnC,IAAA,MAAM,aAAa,KAAM,CAAA,aAAA;AACzB,IAAA,MAAM,CAAC,KAAA,EAAO,IAAI,CAAA,GAAI,iBAAiB,UAAU,CAAA;AACjD,IAAA,MAAM,4BAA4B,KAAS,IAAA,IAAA;AAE3C,IAAI,IAAA,CAAC,yBAA6B,IAAA,cAAA,KAAmB,UAAY,EAAA;AAChE,MAAA,KAAA,CAAM,cAAe,EAAA;AACrB,MAAA;AAAA;AAGD,IAAA,IAAI,CAAC,KAAA,CAAM,QAAY,IAAA,cAAA,KAAmB,IAAM,EAAA;AAC/C,MAAA,KAAA,CAAM,cAAe,EAAA;AACrB,MAAA,IAAI,QAAQ,KAAO,EAAA;AAClB,QAAA,YAAA,CAAa,KAAO,EAAA,EAAE,MAAQ,EAAA,IAAA,EAAM,CAAA;AAAA;AACrC;AAGD,IAAI,IAAA,KAAA,CAAM,QAAY,IAAA,cAAA,KAAmB,KAAO,EAAA;AAC/C,MAAA,KAAA,CAAM,cAAe,EAAA;AACrB,MAAA,IAAI,QAAQ,IAAM,EAAA;AACjB,QAAA,YAAA,CAAa,IAAM,EAAA,EAAE,MAAQ,EAAA,IAAA,EAAM,CAAA;AAAA;AACpC;AACD,GACD;AAEA,EAAO,uBAAA,KAAA,CAAA,aAAA,CAAC,SAAI,QAAU,EAAA,EAAA,EAAK,GAAG,UAAY,EAAA,SAAA,EAAW,aAAe,EAAA,GAAA,EAAK,YAAc,EAAA,CAAA;AACxF","file":"index.js","sourcesContent":["export const focusFirst = (candidates: HTMLElement[], options: { select?: boolean } = {}) => {\n\tconst { select = false } = options;\n\n\tconst previouslyFocusedElement = document.activeElement;\n\n\tfor (const candidate of candidates) {\n\t\tfocusElement(candidate, { select });\n\t\tif (document.activeElement !== previouslyFocusedElement) return;\n\t}\n};\n\nexport const getTabbableEdges = (container: HTMLElement) => {\n\tconst candidates = getTabbableCandidates(container);\n\tconst first = findVisible(candidates, container);\n\tconst last = findVisible(candidates.reverse(), container);\n\treturn [first, last];\n};\n\nexport const getTabbableCandidates = (container: HTMLElement): HTMLElement[] => {\n\tconst nodes: HTMLElement[] = [];\n\n\tconst walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {\n\t\tacceptNode: (node: HTMLInputElement) => {\n\t\t\tconst isHiddenInput = node.tagName === \"INPUT\" && node.type === \"hidden\";\n\n\t\t\tif (node.disabled || node.hidden || isHiddenInput) return NodeFilter.FILTER_SKIP;\n\n\t\t\treturn node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;\n\t\t},\n\t});\n\n\twhile (walker.nextNode()) {\n\t\tnodes.push(walker.currentNode as HTMLElement);\n\t}\n\n\treturn nodes;\n};\n\nconst findVisible = (elements: HTMLElement[], container: HTMLElement): HTMLElement | null => {\n\tif (elements.length === 0) return null;\n\tlet visibleElement: HTMLElement | null = null;\n\n\tfor (const element of elements) {\n\t\tif (!isHidden(element, { upTo: container })) {\n\t\t\tvisibleElement = element;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn visibleElement;\n};\n\nconst isHidden = (\n\tinitialNode: HTMLElement | null,\n\toptions: { upTo: HTMLElement | undefined }\n): boolean => {\n\tconst { upTo } = options;\n\n\tif (!initialNode || getComputedStyle(initialNode).visibility === \"hidden\") {\n\t\treturn true;\n\t}\n\n\tlet currentNode: HTMLElement | null = initialNode;\n\n\twhile (currentNode) {\n\t\tif (upTo !== void 0 && currentNode === upTo) {\n\t\t\treturn false;\n\t\t}\n\t\tif (getComputedStyle(currentNode).display === \"none\") {\n\t\t\treturn true;\n\t\t}\n\t\tcurrentNode = currentNode.parentElement;\n\t}\n\n\treturn false;\n};\n\nconst isSelectableInput = (element: HTMLElement): element is HTMLInputElement => {\n\treturn element instanceof HTMLInputElement && \"select\" in element;\n};\n\nexport const focusElement = (element: HTMLElement | null, options: { select?: boolean } = {}) => {\n\tconst { select = false } = options;\n\n\tif (element && typeof element.focus === \"function\") {\n\t\tconst previouslyFocusedElement = document.activeElement;\n\t\telement.focus({ preventScroll: true });\n\n\t\tif (element !== previouslyFocusedElement && isSelectableInput(element) && select) {\n\t\t\telement.select();\n\t\t}\n\t}\n};\n\nconst createFocusScopesStack = () => {\n\tlet stack: Array<{ pause: () => void; paused: boolean; resume: () => void }> = [];\n\n\tconst api = {\n\t\tadd(focusScope: { pause: () => void; paused: boolean; resume: () => void }) {\n\t\t\tconst activeFocusScope = stack[0];\n\t\t\tif (focusScope !== activeFocusScope) {\n\t\t\t\tactiveFocusScope?.pause();\n\t\t\t}\n\t\t\tstack = arrayRemove(stack, focusScope);\n\t\t\tstack.unshift(focusScope);\n\t\t},\n\t\tremove(focusScope: { pause: () => void; paused: boolean; resume: () => void }) {\n\t\t\tstack = arrayRemove(stack, focusScope);\n\t\t\tstack[0]?.resume();\n\t\t},\n\t};\n\n\treturn api;\n};\n\nexport const focusScopesStack = createFocusScopesStack();\n\nconst arrayRemove = <T>(array: T[], item: T): T[] => {\n\tconst updatedArray = [...array];\n\tconst index = updatedArray.indexOf(item);\n\tif (index !== -1) {\n\t\tupdatedArray.splice(index, 1);\n\t}\n\treturn updatedArray;\n};\n\nexport const removeLinks = (items: HTMLElement[]): HTMLElement[] => {\n\treturn items.filter((item) => item.tagName !== \"A\");\n};\n","\"use client\";\n\nimport * as React from \"react\";\n\nimport { useCallbackRef } from \"@zayne-labs/toolkit-react\";\nimport { type InferProps, composeRefs } from \"@zayne-labs/toolkit-react/utils\";\nimport { useEffect, useRef, useState } from \"react\";\nimport {\n\tfocusElement,\n\tfocusFirst,\n\tfocusScopesStack,\n\tgetTabbableCandidates,\n\tgetTabbableEdges,\n\tremoveLinks,\n} from \"./utils\";\n\n/* -------------------------------------------------------------------------------------------------\n * FocusScope\n * Copied and modified from @radix-ui/react-focus-scope\n * @see https://github.com/radix-ui/primitives/tree/main/packages/react/focus-scope\n * ----------------------------------------------------------------------------------------------- */\n\ntype FocusScopeElement = React.ComponentRef<\"div\">;\n\ntype FocusScopeProps = Omit<InferProps<\"div\">, \"ref\"> & {\n\t/**\n\t * When `true`, tabbing from last item will focus first tabbable\n\t * and shift+tab from first item will focus last tababble.\n\t * @defaultValue false\n\t */\n\tloop?: boolean;\n\t/**\n\t * Event handler called when auto-focusing on mount.\n\t * Can be prevented.\n\t */\n\tonMountAutoFocus?: (event: Event) => void;\n\t/**\n\t * Event handler called when auto-focusing on unmount.\n\t * Can be prevented.\n\t */\n\tonUnmountAutoFocus?: (event: Event) => void;\n\n\tref?: React.Ref<FocusScopeElement>;\n\n\t/**\n\t * When `true`, focus cannot escape the focus scope via keyboard,\n\t * pointer, or a programmatic focus.\n\t * @defaultValue false\n\t */\n\ttrapped?: boolean;\n};\n\nconst AUTOFOCUS_ON_MOUNT = \"focusScope.autoFocusOnMount\";\nconst AUTOFOCUS_ON_UNMOUNT = \"focusScope.autoFocusOnUnmount\";\nconst EVENT_OPTIONS = { bubbles: false, cancelable: true };\n\nfunction FocusScope(props: FocusScopeProps) {\n\tconst {\n\t\tloop = false,\n\t\tonMountAutoFocus,\n\t\tonUnmountAutoFocus,\n\t\tref: forwardedRef,\n\t\ttrapped = false,\n\t\t...scopeProps\n\t} = props;\n\tconst [container, setContainer] = useState<HTMLElement | null>(null);\n\n\tconst savedOnMountAutoFocus = useCallbackRef(onMountAutoFocus);\n\n\tconst savedOnUnmountAutoFocus = useCallbackRef(onUnmountAutoFocus);\n\n\tconst lastFocusedElementRef = useRef<HTMLElement | null>(null);\n\tconst composedRefs = composeRefs([forwardedRef, (node) => setContainer(node)]);\n\n\tconst focusScope = useRef({\n\t\tpause() {\n\t\t\tthis.paused = true;\n\t\t},\n\t\tpaused: false,\n\t\tresume() {\n\t\t\tthis.paused = false;\n\t\t},\n\t}).current;\n\n\tuseEffect(() => {\n\t\tif (!trapped) return;\n\n\t\tconst handleFocusIn = function (event: FocusEvent) {\n\t\t\tif (focusScope.paused || !container) return;\n\t\t\tconst target = event.target as HTMLElement;\n\t\t\tif (container.contains(target)) {\n\t\t\t\tlastFocusedElementRef.current = target;\n\t\t\t} else {\n\t\t\t\tfocusElement(lastFocusedElementRef.current, { select: true });\n\t\t\t}\n\t\t};\n\n\t\tconst handleFocusOut = function (event: FocusEvent) {\n\t\t\tif (focusScope.paused || !container) return;\n\t\t\tconst relatedTarget = event.relatedTarget as HTMLElement | null;\n\t\t\tif (relatedTarget === null) return;\n\t\t\tif (!container.contains(relatedTarget)) {\n\t\t\t\tfocusElement(lastFocusedElementRef.current, { select: true });\n\t\t\t}\n\t\t};\n\n\t\tconst handleMutations = function (mutations: MutationRecord[]) {\n\t\t\tconst focusedElement = document.activeElement;\n\t\t\tif (focusedElement !== document.body) return;\n\t\t\tfor (const mutation of mutations) {\n\t\t\t\tif (mutation.removedNodes.length > 0) focusElement(container);\n\t\t\t}\n\t\t};\n\n\t\tdocument.addEventListener(\"focusin\", handleFocusIn);\n\t\tdocument.addEventListener(\"focusout\", handleFocusOut);\n\t\tconst mutationObserver = new MutationObserver(handleMutations);\n\n\t\tif (container) {\n\t\t\tmutationObserver.observe(container, { childList: true, subtree: true });\n\t\t}\n\n\t\treturn () => {\n\t\t\tdocument.removeEventListener(\"focusin\", handleFocusIn);\n\t\t\tdocument.removeEventListener(\"focusout\", handleFocusOut);\n\t\t\tmutationObserver.disconnect();\n\t\t};\n\t}, [trapped, container, focusScope.paused]);\n\n\tuseEffect(() => {\n\t\tif (!container) return;\n\n\t\tfocusScopesStack.add(focusScope);\n\n\t\tconst previouslyFocusedElement = document.activeElement;\n\t\tconst hasFocusedCandidate = container.contains(previouslyFocusedElement);\n\n\t\tif (!hasFocusedCandidate) {\n\t\t\tconst mountEvent = new CustomEvent(AUTOFOCUS_ON_MOUNT, EVENT_OPTIONS);\n\t\t\tcontainer.addEventListener(AUTOFOCUS_ON_MOUNT, savedOnMountAutoFocus);\n\t\t\tcontainer.dispatchEvent(mountEvent);\n\n\t\t\tif (!mountEvent.defaultPrevented) {\n\t\t\t\tfocusFirst(removeLinks(getTabbableCandidates(container)), { select: true });\n\t\t\t\tdocument.activeElement === previouslyFocusedElement && focusElement(container);\n\t\t\t}\n\t\t}\n\n\t\treturn () => {\n\t\t\tcontainer.removeEventListener(AUTOFOCUS_ON_MOUNT, savedOnMountAutoFocus);\n\n\t\t\t// eslint-disable-next-line react-web-api/no-leaked-timeout -- Allow\n\t\t\tsetTimeout(() => {\n\t\t\t\tconst unmountEvent = new CustomEvent(AUTOFOCUS_ON_UNMOUNT, EVENT_OPTIONS);\n\t\t\t\t// eslint-disable-next-line react-web-api/no-leaked-event-listener -- Allow\n\t\t\t\tcontainer.addEventListener(AUTOFOCUS_ON_UNMOUNT, savedOnUnmountAutoFocus);\n\t\t\t\tcontainer.dispatchEvent(unmountEvent);\n\t\t\t\tif (!unmountEvent.defaultPrevented) {\n\t\t\t\t\tfocusElement(document.body, { select: true });\n\t\t\t\t}\n\t\t\t\tcontainer.removeEventListener(AUTOFOCUS_ON_UNMOUNT, savedOnUnmountAutoFocus);\n\t\t\t\tfocusScopesStack.remove(focusScope);\n\t\t\t}, 0);\n\t\t};\n\t}, [container, savedOnMountAutoFocus, savedOnUnmountAutoFocus, focusScope]);\n\n\tconst handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n\t\tif (!loop && !trapped) return;\n\t\tif (focusScope.paused) return;\n\n\t\tconst isTabKey = event.key === \"Tab\" && !event.altKey && !event.ctrlKey && !event.metaKey;\n\t\tconst focusedElement = document.activeElement;\n\n\t\tif (!(isTabKey && focusedElement)) return;\n\n\t\tconst container2 = event.currentTarget;\n\t\tconst [first, last] = getTabbableEdges(container2);\n\t\tconst hasTabbableElementsInside = first && last;\n\n\t\tif (!hasTabbableElementsInside && focusedElement === container2) {\n\t\t\tevent.preventDefault();\n\t\t\treturn;\n\t\t}\n\n\t\tif (!event.shiftKey && focusedElement === last) {\n\t\t\tevent.preventDefault();\n\t\t\tif (loop && first) {\n\t\t\t\tfocusElement(first, { select: true });\n\t\t\t}\n\t\t}\n\n\t\tif (event.shiftKey && focusedElement === first) {\n\t\t\tevent.preventDefault();\n\t\t\tif (loop && last) {\n\t\t\t\tfocusElement(last, { select: true });\n\t\t\t}\n\t\t}\n\t};\n\n\treturn <div tabIndex={-1} {...scopeProps} onKeyDown={handleKeyDown} ref={composedRefs} />;\n}\n\nexport { FocusScope };\n"]}
@@ -1,4 +1,50 @@
1
- export { show_parts_exports as Show, ShowContent, ShowFallback, ShowRoot } from '../../chunk-FPCKBOJN.js';
2
- import '../../chunk-PZ5AY32C.js';
1
+ import { __export } from '../../chunk-PZ5AY32C.js';
2
+ import 'react';
3
+ import { getSingleSlot, getRegularChildren } from '@zayne-labs/toolkit-react/utils';
4
+ import { isFunction, AssertionError } from '@zayne-labs/toolkit-type-helpers';
5
+
6
+ function ShowRoot({ children, fallback, when }) {
7
+ if ((when == null || when === false) && !isFunction(children)) {
8
+ const fallBackSlot = getSingleSlot(children, ShowFallback, {
9
+ errorMessage: "Only one <Show.Fallback> or <Show.OtherWise> component is allowed",
10
+ throwOnMultipleSlotMatch: true
11
+ });
12
+ if (fallBackSlot && fallback) {
13
+ throw new AssertionError(`
14
+ The fallback prop and <Show.Fallback>/<Show.OtherWise> cannot be used at the same time.
15
+ `);
16
+ }
17
+ return fallBackSlot ?? fallback;
18
+ }
19
+ if (when == null || when === false) {
20
+ return fallback;
21
+ }
22
+ const resolvedChildren = isFunction(children) ? children(when) : children;
23
+ const contentSlot = getSingleSlot(resolvedChildren, ShowContent, {
24
+ errorMessage: "Only one <Show.Content> component is allowed",
25
+ throwOnMultipleSlotMatch: true
26
+ });
27
+ const regularChildren = getRegularChildren(resolvedChildren, [ShowFallback, ShowContent]);
28
+ return contentSlot ?? regularChildren;
29
+ }
30
+ function ShowContent({ children }) {
31
+ return children;
32
+ }
33
+ ShowContent.slotSymbol = Symbol("content");
34
+ function ShowFallback({ children }) {
35
+ return children;
36
+ }
37
+ ShowFallback.slotSymbol = Symbol("show-fallback");
38
+
39
+ // src/components/common/show/show-parts.ts
40
+ var show_parts_exports = {};
41
+ __export(show_parts_exports, {
42
+ Content: () => ShowContent,
43
+ Fallback: () => ShowFallback,
44
+ OtherWise: () => ShowFallback,
45
+ Root: () => ShowRoot
46
+ });
47
+
48
+ export { show_parts_exports as Show, ShowContent, ShowFallback, ShowRoot };
3
49
  //# sourceMappingURL=index.js.map
4
50
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
1
+ {"version":3,"sources":["../../../../src/components/common/show/show.tsx","../../../../src/components/common/show/show-parts.ts"],"names":[],"mappings":";;;;;AAaO,SAAS,QAAgB,CAAA,EAAE,QAAU,EAAA,QAAA,EAAU,MAA0B,EAAA;AAC/E,EAAA,IAAA,CAAK,QAAQ,IAAQ,IAAA,IAAA,KAAS,UAAU,CAAC,UAAA,CAAW,QAAQ,CAAG,EAAA;AAC9D,IAAM,MAAA,YAAA,GAAe,aAAc,CAAA,QAAA,EAAU,YAAc,EAAA;AAAA,MAC1D,YAAc,EAAA,mEAAA;AAAA,MACd,wBAA0B,EAAA;AAAA,KAC1B,CAAA;AAED,IAAA,IAAI,gBAAgB,QAAU,EAAA;AAC7B,MAAA,MAAM,IAAI,cAAe,CAAA;AAAA;AAAA,EAEzB,CAAA,CAAA;AAAA;AAGD,IAAA,OAAO,YAAgB,IAAA,QAAA;AAAA;AAGxB,EAAI,IAAA,IAAA,IAAQ,IAAQ,IAAA,IAAA,KAAS,KAAO,EAAA;AACnC,IAAO,OAAA,QAAA;AAAA;AAGR,EAAA,MAAM,mBAAmB,UAAW,CAAA,QAAQ,CAAI,GAAA,QAAA,CAAS,IAAI,CAAI,GAAA,QAAA;AAEjE,EAAM,MAAA,WAAA,GAAc,aAAc,CAAA,gBAAA,EAAkB,WAAa,EAAA;AAAA,IAChE,YAAc,EAAA,8CAAA;AAAA,IACd,wBAA0B,EAAA;AAAA,GAC1B,CAAA;AAED,EAAA,MAAM,kBAAkB,kBAAmB,CAAA,gBAAA,EAAkB,CAAC,YAAA,EAAc,WAAW,CAAC,CAAA;AAExF,EAAA,OAAO,WAAe,IAAA,eAAA;AACvB;AAEO,SAAS,WAAA,CAAY,EAAE,QAAA,EAA2C,EAAA;AACxE,EAAO,OAAA,QAAA;AACR;AACA,WAAY,CAAA,UAAA,GAAa,OAAO,SAAS,CAAA;AAElC,SAAS,YAAA,CAAa,EAAE,QAAA,EAA2C,EAAA;AACzE,EAAO,OAAA,QAAA;AACR;AACA,YAAa,CAAA,UAAA,GAAa,OAAO,eAAe,CAAA;;;ACrDhD,IAAA,kBAAA,GAAA;AAAA,QAAA,CAAA,kBAAA,EAAA;AAAA,EAAA,OAAA,EAAA,MAAA,WAAA;AAAA,EAAA,QAAA,EAAA,MAAA,YAAA;AAAA,EAAA,SAAA,EAAA,MAAA,YAAA;AAAA,EAAA,IAAA,EAAA,MAAA;AAAA,CAAA,CAAA","file":"index.js","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\nimport { getRegularChildren, getSingleSlot } from \"@zayne-labs/toolkit-react/utils\";\nimport { AssertionError, isFunction } from \"@zayne-labs/toolkit-type-helpers\";\n\ntype ShowProps<TWhen> = {\n\tchildren: React.ReactNode | ((whenValue: TWhen) => React.ReactNode);\n\tfallback?: React.ReactNode;\n\twhen: false | TWhen | null | undefined;\n};\n\nexport function ShowRoot<TWhen>({ children, fallback, when }: ShowProps<TWhen>) {\n\tif ((when == null || when === false) && !isFunction(children)) {\n\t\tconst fallBackSlot = getSingleSlot(children, ShowFallback, {\n\t\t\terrorMessage: \"Only one <Show.Fallback> or <Show.OtherWise> component is allowed\",\n\t\t\tthrowOnMultipleSlotMatch: true,\n\t\t});\n\n\t\tif (fallBackSlot && fallback) {\n\t\t\tthrow new AssertionError(`\n\t\t\tThe fallback prop and <Show.Fallback>/<Show.OtherWise> cannot be used at the same time.\n\t\t`);\n\t\t}\n\n\t\treturn fallBackSlot ?? fallback;\n\t}\n\n\tif (when == null || when === false) {\n\t\treturn fallback;\n\t}\n\n\tconst resolvedChildren = isFunction(children) ? children(when) : children;\n\n\tconst contentSlot = getSingleSlot(resolvedChildren, ShowContent, {\n\t\terrorMessage: \"Only one <Show.Content> component is allowed\",\n\t\tthrowOnMultipleSlotMatch: true,\n\t});\n\n\tconst regularChildren = getRegularChildren(resolvedChildren, [ShowFallback, ShowContent]);\n\n\treturn contentSlot ?? regularChildren;\n}\n\nexport function ShowContent({ children }: { children: React.ReactNode }) {\n\treturn children;\n}\nShowContent.slotSymbol = Symbol(\"content\");\n\nexport function ShowFallback({ children }: { children: React.ReactNode }) {\n\treturn children;\n}\nShowFallback.slotSymbol = Symbol(\"show-fallback\");\n","export {\n\tShowContent as Content,\n\tShowFallback as Fallback,\n\tShowFallback as OtherWise,\n\tShowRoot as Root,\n} from \"./show\";\n"]}
@@ -1,4 +1,4 @@
1
- export { Slot, Slottable } from '../../chunk-ENDWJXPF.js';
1
+ export { Slot, Slottable } from '../../chunk-L2SROZYQ.js';
2
2
  import '../../chunk-PZ5AY32C.js';
3
3
  //# sourceMappingURL=index.js.map
4
4
  //# sourceMappingURL=index.js.map
@@ -1,5 +1,14 @@
1
- export { SuspenseWithBoundary } from '../../chunk-NPIJ4XZP.js';
2
- import '../../chunk-OM4ZFFQS.js';
1
+ import { ErrorBoundary } from '../../chunk-OM4ZFFQS.js';
3
2
  import '../../chunk-PZ5AY32C.js';
3
+ import { Suspense } from 'react';
4
+
5
+ function SuspenseWithBoundary(props) {
6
+ const { children, errorFallback, fallback } = props;
7
+ const errorBoundaryProps = Boolean(errorFallback) && { fallback: errorFallback };
8
+ const suspenseProps = Boolean(fallback) && { fallback };
9
+ return /* @__PURE__ */ React.createElement(ErrorBoundary, { ...errorBoundaryProps }, /* @__PURE__ */ React.createElement(Suspense, { ...suspenseProps }, children));
10
+ }
11
+
12
+ export { SuspenseWithBoundary };
4
13
  //# sourceMappingURL=index.js.map
5
14
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
1
+ {"version":3,"sources":["../../../../src/components/common/suspense-with-boundary/suspense-with-boundary.tsx"],"names":[],"mappings":";;;;AASO,SAAS,qBAAqB,KAAkC,EAAA;AACtE,EAAA,MAAM,EAAE,QAAA,EAAU,aAAe,EAAA,QAAA,EAAa,GAAA,KAAA;AAE9C,EAAA,MAAM,qBAAqB,OAAQ,CAAA,aAAa,CAAK,IAAA,EAAE,UAAU,aAAc,EAAA;AAC/E,EAAA,MAAM,aAAgB,GAAA,OAAA,CAAQ,QAAQ,CAAA,IAAK,EAAE,QAAS,EAAA;AAEtD,EACC,uBAAA,KAAA,CAAA,aAAA,CAAC,iBAAe,GAAG,kBAAA,EAAA,sCACjB,QAAU,EAAA,EAAA,GAAG,aAAgB,EAAA,EAAA,QAAS,CACxC,CAAA;AAEF","file":"index.js","sourcesContent":["import { Suspense } from \"react\";\nimport { ErrorBoundary, type ErrorBoundaryProps } from \"../error-boundary\";\n\nexport type SuspenseWithBoundaryProps = {\n\tchildren: React.ReactNode;\n\terrorFallback?: ErrorBoundaryProps[\"fallback\"];\n\tfallback?: React.ReactNode;\n};\n\nexport function SuspenseWithBoundary(props: SuspenseWithBoundaryProps) {\n\tconst { children, errorFallback, fallback } = props;\n\n\tconst errorBoundaryProps = Boolean(errorFallback) && { fallback: errorFallback };\n\tconst suspenseProps = Boolean(fallback) && { fallback };\n\n\treturn (\n\t\t<ErrorBoundary {...errorBoundaryProps}>\n\t\t\t<Suspense {...suspenseProps}>{children}</Suspense>\n\t\t</ErrorBoundary>\n\t);\n}\n"]}
@@ -1,4 +1,40 @@
1
- export { switch_parts_exports as Switch, SwitchDefault, SwitchMatch, SwitchRoot } from '../../chunk-SVQ4WBSO.js';
2
- import '../../chunk-PZ5AY32C.js';
1
+ import { __export } from '../../chunk-PZ5AY32C.js';
2
+ import 'react';
3
+ import { getSingleSlot, getRegularChildren } from '@zayne-labs/toolkit-react/utils';
4
+ import { isFunction } from '@zayne-labs/toolkit-type-helpers';
5
+
6
+ var defaultConditionSymbol = Symbol("condition-default");
7
+ function SwitchRoot(props) {
8
+ const { children, condition = defaultConditionSymbol } = props;
9
+ const defaultCase = getSingleSlot(children, SwitchDefault, {
10
+ errorMessage: "Only one <Switch.Default> component is allowed",
11
+ throwOnMultipleSlotMatch: true
12
+ });
13
+ const childrenCasesArray = getRegularChildren(children, SwitchDefault);
14
+ const matchedCase = childrenCasesArray.find(
15
+ (child) => condition === defaultConditionSymbol ? child.props.when : child.props.when === condition
16
+ );
17
+ return matchedCase ?? defaultCase;
18
+ }
19
+ function SwitchMatch({ children, when }) {
20
+ if (when == null || when === false) {
21
+ return null;
22
+ }
23
+ return isFunction(children) ? children(when) : children;
24
+ }
25
+ function SwitchDefault({ children }) {
26
+ return children;
27
+ }
28
+ SwitchDefault.slotSymbol = Symbol("switch-default");
29
+
30
+ // src/components/common/switch/switch-parts.ts
31
+ var switch_parts_exports = {};
32
+ __export(switch_parts_exports, {
33
+ Default: () => SwitchDefault,
34
+ Match: () => SwitchMatch,
35
+ Root: () => SwitchRoot
36
+ });
37
+
38
+ export { switch_parts_exports as Switch, SwitchDefault, SwitchMatch, SwitchRoot };
3
39
  //# sourceMappingURL=index.js.map
4
40
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
1
+ {"version":3,"sources":["../../../../src/components/common/switch/switch.tsx","../../../../src/components/common/switch/switch-parts.ts"],"names":[],"mappings":";;;;;AAmBA,IAAM,sBAAA,GAAyB,OAAO,mBAAmB,CAAA;AAElD,SAAS,WAA8B,KAAgC,EAAA;AAC7E,EAAA,MAAM,EAAE,QAAA,EAAU,SAAY,GAAA,sBAAA,EAA2B,GAAA,KAAA;AAEzD,EAAM,MAAA,WAAA,GAAc,aAAc,CAAA,QAAA,EAAU,aAAe,EAAA;AAAA,IAC1D,YAAc,EAAA,gDAAA;AAAA,IACd,wBAA0B,EAAA;AAAA,GAC1B,CAAA;AAED,EAAM,MAAA,kBAAA,GAAqB,kBAAmB,CAAA,QAAA,EAAU,aAAa,CAAA;AAErE,EAAA,MAAM,cAAc,kBAAmB,CAAA,IAAA;AAAA,IAAK,CAAC,UAC5C,SAAc,KAAA,sBAAA,GAAyB,MAAM,KAAM,CAAA,IAAA,GAAO,KAAM,CAAA,KAAA,CAAM,IAAS,KAAA;AAAA,GAChF;AAEA,EAAA,OAAO,WAAe,IAAA,WAAA;AACvB;AAEO,SAAS,WAAmB,CAAA,EAAE,QAAU,EAAA,IAAA,EAAiC,EAAA;AAC/E,EAAI,IAAA,IAAA,IAAQ,IAAQ,IAAA,IAAA,KAAS,KAAO,EAAA;AACnC,IAAO,OAAA,IAAA;AAAA;AAGR,EAAA,OAAO,UAAW,CAAA,QAAQ,CAAI,GAAA,QAAA,CAAS,IAAI,CAAI,GAAA,QAAA;AAChD;AAEO,SAAS,aAAA,CAAc,EAAE,QAAA,EAA2C,EAAA;AAC1E,EAAO,OAAA,QAAA;AACR;AACA,aAAc,CAAA,UAAA,GAAa,OAAO,gBAAgB,CAAA;;;ACjDlD,IAAA,oBAAA,GAAA;AAAA,QAAA,CAAA,oBAAA,EAAA;AAAA,EAAA,OAAA,EAAA,MAAA,aAAA;AAAA,EAAA,KAAA,EAAA,MAAA,WAAA;AAAA,EAAA,IAAA,EAAA,MAAA;AAAA,CAAA,CAAA","file":"index.js","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\nimport { getRegularChildren, getSingleSlot } from \"@zayne-labs/toolkit-react/utils\";\nimport { isFunction } from \"@zayne-labs/toolkit-type-helpers\";\n\ntype ValidSwitchComponentType = React.ReactElement<SwitchMatchProps>;\n\ntype SwitchProps<TCondition> = {\n\tchildren: ValidSwitchComponentType | ValidSwitchComponentType[];\n\tcondition?: TCondition;\n};\n\ntype SwitchMatchProps<TWhen = unknown> = {\n\tchildren: React.ReactNode | ((whenValue: TWhen) => React.ReactNode);\n\twhen: false | TWhen | null | undefined;\n};\n\nconst defaultConditionSymbol = Symbol(\"condition-default\");\n\nexport function SwitchRoot<TCondition = true>(props: SwitchProps<TCondition>) {\n\tconst { children, condition = defaultConditionSymbol } = props;\n\n\tconst defaultCase = getSingleSlot(children, SwitchDefault, {\n\t\terrorMessage: \"Only one <Switch.Default> component is allowed\",\n\t\tthrowOnMultipleSlotMatch: true,\n\t});\n\n\tconst childrenCasesArray = getRegularChildren(children, SwitchDefault);\n\n\tconst matchedCase = childrenCasesArray.find((child) =>\n\t\tcondition === defaultConditionSymbol ? child.props.when : child.props.when === condition\n\t);\n\n\treturn matchedCase ?? defaultCase;\n}\n\nexport function SwitchMatch<TWhen>({ children, when }: SwitchMatchProps<TWhen>) {\n\tif (when == null || when === false) {\n\t\treturn null;\n\t}\n\n\treturn isFunction(children) ? children(when) : children;\n}\n\nexport function SwitchDefault({ children }: { children: React.ReactNode }) {\n\treturn children;\n}\nSwitchDefault.slotSymbol = Symbol(\"switch-default\");\n","export { SwitchDefault as Default, SwitchMatch as Match, SwitchRoot as Root } from \"./switch\";\n"]}
@@ -1,4 +1,31 @@
1
- export { Teleport } from '../../chunk-CB2EZJYW.js';
2
1
  import '../../chunk-PZ5AY32C.js';
2
+ import { useState } from 'react';
3
+ import { useEffectOnce, useMountEffect } from '@zayne-labs/toolkit-react';
4
+ import { isString } from '@zayne-labs/toolkit-type-helpers';
5
+ import { createPortal } from 'react-dom';
6
+
7
+ function Teleport(props) {
8
+ const { children, insertPosition, to } = props;
9
+ const [reactPortal, setReactPortal] = useState(null);
10
+ useEffectOnce(() => {
11
+ if (!to || !insertPosition) return;
12
+ const destination = isString(to) ? document.querySelector(to) : to;
13
+ const tempWrapper = document.createElement("div");
14
+ tempWrapper.style.display = "contents";
15
+ destination?.insertAdjacentElement(insertPosition, tempWrapper);
16
+ setReactPortal(createPortal(children, tempWrapper));
17
+ return () => {
18
+ tempWrapper.remove();
19
+ };
20
+ });
21
+ useMountEffect(() => {
22
+ if (!to || insertPosition) return;
23
+ const destination = isString(to) ? document.querySelector(to) : to;
24
+ destination && setReactPortal(createPortal(children, destination));
25
+ });
26
+ return reactPortal;
27
+ }
28
+
29
+ export { Teleport };
3
30
  //# sourceMappingURL=index.js.map
4
31
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
1
+ {"version":3,"sources":["../../../../src/components/common/teleport/teleport.tsx"],"names":[],"mappings":";;;;;;AAeA,SAAS,SAAS,KAAoB,EAAA;AACrC,EAAA,MAAM,EAAE,QAAA,EAAU,cAAgB,EAAA,EAAA,EAAO,GAAA,KAAA;AAEzC,EAAA,MAAM,CAAC,WAAA,EAAa,cAAc,CAAA,GAAI,SAAmC,IAAI,CAAA;AAE7E,EAAA,aAAA,CAAc,MAAM;AACnB,IAAI,IAAA,CAAC,EAAM,IAAA,CAAC,cAAgB,EAAA;AAE5B,IAAA,MAAM,cAAc,QAAS,CAAA,EAAE,IAAI,QAAS,CAAA,aAAA,CAA2B,EAAE,CAAI,GAAA,EAAA;AAE7E,IAAM,MAAA,WAAA,GAAc,QAAS,CAAA,aAAA,CAAc,KAAK,CAAA;AAChD,IAAA,WAAA,CAAY,MAAM,OAAU,GAAA,UAAA;AAE5B,IAAa,WAAA,EAAA,qBAAA,CAAsB,gBAAgB,WAAW,CAAA;AAE9D,IAAe,cAAA,CAAA,YAAA,CAAa,QAAU,EAAA,WAAW,CAAC,CAAA;AAElD,IAAA,OAAO,MAAM;AACZ,MAAA,WAAA,CAAY,MAAO,EAAA;AAAA,KACpB;AAAA,GACA,CAAA;AAED,EAAA,cAAA,CAAe,MAAM;AACpB,IAAI,IAAA,CAAC,MAAM,cAAgB,EAAA;AAE3B,IAAA,MAAM,cAAc,QAAS,CAAA,EAAE,IAAI,QAAS,CAAA,aAAA,CAA2B,EAAE,CAAI,GAAA,EAAA;AAE7E,IAAA,WAAA,IAAe,cAAe,CAAA,YAAA,CAAa,QAAU,EAAA,WAAW,CAAC,CAAA;AAAA,GACjE,CAAA;AAED,EAAO,OAAA,WAAA;AACR","file":"index.js","sourcesContent":["import * as React from \"react\";\n\nimport { useEffectOnce, useMountEffect } from \"@zayne-labs/toolkit-react\";\nimport { type AnyString, isString } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useState } from \"react\";\nimport { createPortal } from \"react-dom\";\n\ntype ValidHtmlTags = keyof HTMLElementTagNameMap;\n\ntype PortalProps = {\n\tchildren: React.ReactNode;\n\tinsertPosition?: InsertPosition;\n\tto?: AnyString | HTMLElement | ValidHtmlTags | null;\n};\n\nfunction Teleport(props: PortalProps) {\n\tconst { children, insertPosition, to } = props;\n\n\tconst [reactPortal, setReactPortal] = useState<React.ReactPortal | null>(null);\n\n\tuseEffectOnce(() => {\n\t\tif (!to || !insertPosition) return;\n\n\t\tconst destination = isString(to) ? document.querySelector<HTMLElement>(to) : to;\n\n\t\tconst tempWrapper = document.createElement(\"div\");\n\t\ttempWrapper.style.display = \"contents\";\n\n\t\tdestination?.insertAdjacentElement(insertPosition, tempWrapper);\n\n\t\tsetReactPortal(createPortal(children, tempWrapper));\n\n\t\treturn () => {\n\t\t\ttempWrapper.remove();\n\t\t};\n\t});\n\n\tuseMountEffect(() => {\n\t\tif (!to || insertPosition) return;\n\n\t\tconst destination = isString(to) ? document.querySelector<HTMLElement>(to) : to;\n\n\t\tdestination && setReactPortal(createPortal(children, destination));\n\t});\n\n\treturn reactPortal;\n}\n\nexport { Teleport };\n"]}