@sprawlify/react 0.0.5 → 0.0.7

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 (127) hide show
  1. package/dist/{collapsible-C5ZpjCRe.mjs → collapsible-B06GGGE7.mjs} +7 -4
  2. package/dist/{collapsible-D_cXuaRy.cjs → collapsible-D5kle6Bc.cjs} +12 -9
  3. package/dist/collection-BKabYqpE.cjs +229 -0
  4. package/dist/collection-DEsp9z6X.mjs +187 -0
  5. package/dist/components/accordion/index.cjs +19 -24
  6. package/dist/components/accordion/index.d.cts +11 -9
  7. package/dist/components/accordion/index.d.mts +11 -9
  8. package/dist/components/accordion/index.mjs +9 -14
  9. package/dist/components/angle-slider/index.cjs +12 -9
  10. package/dist/components/angle-slider/index.d.cts +13 -11
  11. package/dist/components/angle-slider/index.d.mts +13 -11
  12. package/dist/components/angle-slider/index.mjs +7 -4
  13. package/dist/components/avatar/index.cjs +128 -0
  14. package/dist/components/avatar/index.d.cts +49 -0
  15. package/dist/components/avatar/index.d.mts +49 -0
  16. package/dist/components/avatar/index.mjs +110 -0
  17. package/dist/components/bottom-sheet/index.cjs +213 -0
  18. package/dist/components/bottom-sheet/index.d.cts +80 -0
  19. package/dist/components/bottom-sheet/index.d.mts +81 -0
  20. package/dist/components/bottom-sheet/index.mjs +190 -0
  21. package/dist/components/carousel/index.cjs +263 -0
  22. package/dist/components/carousel/index.d.cts +95 -0
  23. package/dist/components/carousel/index.d.mts +95 -0
  24. package/dist/components/carousel/index.mjs +242 -0
  25. package/dist/components/checkbox/index.cjs +308 -0
  26. package/dist/components/checkbox/index.d.cts +115 -0
  27. package/dist/components/checkbox/index.d.mts +115 -0
  28. package/dist/components/checkbox/index.mjs +289 -0
  29. package/dist/components/client-only/index.cjs +14 -0
  30. package/dist/components/client-only/index.d.cts +8 -0
  31. package/dist/components/client-only/index.d.mts +8 -0
  32. package/dist/components/client-only/index.mjs +13 -0
  33. package/dist/components/clipboard/index.cjs +185 -0
  34. package/dist/components/clipboard/index.d.cts +71 -0
  35. package/dist/components/clipboard/index.d.mts +71 -0
  36. package/dist/components/clipboard/index.mjs +163 -0
  37. package/dist/components/collapsible/index.cjs +6 -3
  38. package/dist/components/collapsible/index.d.cts +10 -8
  39. package/dist/components/collapsible/index.d.mts +10 -8
  40. package/dist/components/collapsible/index.mjs +6 -3
  41. package/dist/components/collection/index.cjs +11 -0
  42. package/dist/components/collection/index.d.cts +2 -0
  43. package/dist/components/collection/index.d.mts +2 -0
  44. package/dist/components/collection/index.mjs +5 -0
  45. package/dist/components/color-picker/index.cjs +613 -0
  46. package/dist/components/color-picker/index.d.cts +181 -0
  47. package/dist/components/color-picker/index.d.mts +182 -0
  48. package/dist/components/color-picker/index.mjs +570 -0
  49. package/dist/components/combobox/index.cjs +416 -0
  50. package/dist/components/combobox/index.d.cts +132 -0
  51. package/dist/components/combobox/index.d.mts +133 -0
  52. package/dist/components/combobox/index.mjs +387 -0
  53. package/dist/components/field/index.cjs +27 -0
  54. package/dist/components/field/index.d.cts +116 -0
  55. package/dist/components/field/index.d.mts +116 -0
  56. package/dist/components/field/index.mjs +9 -0
  57. package/dist/components/fieldset/index.cjs +23 -0
  58. package/dist/components/fieldset/index.d.cts +73 -0
  59. package/dist/components/fieldset/index.d.mts +73 -0
  60. package/dist/components/fieldset/index.mjs +9 -0
  61. package/dist/components/highlight/index.cjs +32 -0
  62. package/dist/components/highlight/index.d.cts +14 -0
  63. package/dist/components/highlight/index.d.mts +14 -0
  64. package/dist/components/highlight/index.mjs +30 -0
  65. package/dist/components/portal/index.cjs +32 -0
  66. package/dist/components/portal/index.d.cts +11 -0
  67. package/dist/components/portal/index.d.mts +11 -0
  68. package/dist/components/portal/index.mjs +31 -0
  69. package/dist/components/presence/index.cjs +11 -0
  70. package/dist/components/presence/index.d.cts +2 -0
  71. package/dist/components/presence/index.d.mts +4 -0
  72. package/dist/components/presence/index.mjs +7 -0
  73. package/dist/components/select/index.cjs +419 -0
  74. package/dist/components/select/index.d.cts +132 -0
  75. package/dist/components/select/index.d.mts +133 -0
  76. package/dist/components/select/index.mjs +384 -0
  77. package/dist/{factory-DbgGeb_e.mjs → core-C0F-4KYH.mjs} +4 -154
  78. package/dist/{factory-CfqPG186.cjs → core-CPLjF6nm.cjs} +0 -198
  79. package/dist/{create-context-DCEySQ7J.cjs → create-context-D6DyFRSf.cjs} +1 -1
  80. package/dist/environment-BXkWNF2O.mjs +46 -0
  81. package/dist/environment-DLPiALpf.cjs +58 -0
  82. package/dist/factory-BbbIuDqa.d.mts +15 -0
  83. package/dist/factory-CDX-oCN5.cjs +81 -0
  84. package/dist/factory-DQlmCPH2.mjs +63 -0
  85. package/dist/factory-DaNWFLLN.d.cts +15 -0
  86. package/dist/field-CGCTFCx2.mjs +322 -0
  87. package/dist/field-CXhpW6zO.cjs +404 -0
  88. package/dist/fieldset-CuSSYZxV.cjs +237 -0
  89. package/dist/fieldset-poJ8RDvB.mjs +184 -0
  90. package/dist/index-BUN9wyVM.d.mts +34 -0
  91. package/dist/index-Dhthtdz_.d.mts +74 -0
  92. package/dist/index-DqRXPiW_.d.cts +34 -0
  93. package/dist/index-DsZldSch.d.cts +74 -0
  94. package/dist/index-DtdZfcpz.d.mts +25 -0
  95. package/dist/index.cjs +14 -11
  96. package/dist/index.d.cts +7 -5
  97. package/dist/index.d.mts +7 -5
  98. package/dist/index.mjs +6 -3
  99. package/dist/normalize-props-sqcs77GC.d.cts +13 -0
  100. package/dist/presence-2A4loEJY.mjs +71 -0
  101. package/dist/presence-BX1tNsGA.cjs +101 -0
  102. package/dist/providers-Bk3ALTxZ.cjs +78 -0
  103. package/dist/providers-CyTYcOU1.mjs +54 -0
  104. package/dist/render-strategy-D3w8btTD.mjs +13 -0
  105. package/dist/render-strategy-k1JmEGnq.cjs +30 -0
  106. package/dist/types-DYWV3uAj.d.cts +5 -0
  107. package/dist/types-FLvjyw__.d.mts +5 -0
  108. package/dist/use-event-BcyNH29h.mjs +19 -0
  109. package/dist/use-event-CGMgV6xB.cjs +25 -0
  110. package/dist/use-safe-layout-effect-BlOhFUAp.mjs +17 -0
  111. package/dist/use-safe-layout-effect-vuYaDIpT.cjs +35 -0
  112. package/dist/utils/index.cjs +2 -2
  113. package/dist/utils/index.d.cts +1 -1
  114. package/dist/utils/index.d.mts +1 -1
  115. package/dist/utils/index.mjs +2 -2
  116. package/package.json +152 -2
  117. package/dist/factory-CNfD9NVO.d.mts +0 -41
  118. package/dist/factory-D5qarvEF.d.cts +0 -29
  119. /package/dist/{chunk-DJTHdtxa.mjs → chunk-DLP0tNsH.mjs} +0 -0
  120. /package/dist/{create-context-DLMHiig4.mjs → create-context-CdjrBhu7.mjs} +0 -0
  121. /package/dist/{create-split-props-DvwGh64U.mjs → create-split-props-BJQdOyld.mjs} +0 -0
  122. /package/dist/{create-split-props-CSaOnJRj.cjs → create-split-props-CSkzaUOy.cjs} +0 -0
  123. /package/dist/{index--Dciu8yd.d.mts → index-BwTxN5vG.d.mts} +0 -0
  124. /package/dist/{index-wpUGMM30.d.cts → index-zOmANnUL.d.cts} +0 -0
  125. /package/dist/{render-strategy-G1aEn-1X.d.cts → render-strategy-CdpAg9jb.d.cts} +0 -0
  126. /package/dist/{render-strategy-D37ixdTi.d.mts → render-strategy-GetMScNK.d.mts} +0 -0
  127. /package/dist/{utils-BQjTDAMH.mjs → utils-DflO0-3U.mjs} +0 -0
@@ -1,13 +1,10 @@
1
- import { t as createContext$1 } from "./create-context-DLMHiig4.mjs";
2
- import { INIT_STATE, MachineStatus, createScope, mergeProps, mergeProps as mergeProps$1 } from "@sprawlify/primitives/core";
1
+ import { INIT_STATE, MachineStatus, createScope, mergeProps as mergeProps$1 } from "@sprawlify/primitives/core";
3
2
  import { compact, ensure, identity, isFunction, isString, toArray, warn } from "@sprawlify/primitives/utils";
4
3
  import * as React$1 from "react";
5
- import { Children, cloneElement, createElement, forwardRef, isValidElement, memo, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
4
+ import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
6
5
  import { createPortal, flushSync } from "react-dom";
7
6
  import { createNormalizer } from "@sprawlify/primitives/types";
8
- import { jsx, jsxs } from "react/jsx-runtime";
9
- import { getDocument, getWindow } from "@sprawlify/primitives/dom-query";
10
- import { createCollator, createFilter, isRTL } from "@sprawlify/primitives/i18n-utils";
7
+ import { jsx } from "react/jsx-runtime";
11
8
 
12
9
  //#region src/core/use-layout-effect.ts
13
10
  const useSafeLayoutEffect = typeof globalThis.document !== "undefined" ? useLayoutEffect : useEffect;
@@ -349,151 +346,4 @@ const Portal = (props) => {
349
346
  };
350
347
 
351
348
  //#endregion
352
- //#region src/utils/run-if-fn.ts
353
- const isFunction$1 = (value) => typeof value === "function";
354
- const runIfFn = (valueOrFn, ...args) => isFunction$1(valueOrFn) ? valueOrFn(...args) : valueOrFn;
355
-
356
- //#endregion
357
- //#region src/providers/environment/use-environment-context.ts
358
- const [EnvironmentContextProvider, useEnvironmentContext] = createContext$1({
359
- name: "EnvironmentContext",
360
- hookName: "useEnvironmentContext",
361
- providerName: "<EnvironmentProvider />",
362
- strict: false,
363
- defaultValue: {
364
- getRootNode: () => document,
365
- getDocument: () => document,
366
- getWindow: () => window
367
- }
368
- });
369
-
370
- //#endregion
371
- //#region src/providers/environment/environment-provider.tsx
372
- const EnvironmentProvider = (props) => {
373
- const { value, children } = props;
374
- const [spanRef, setSpanRef] = useState();
375
- const getRootNode = useMemo(() => {
376
- return () => runIfFn(value) ?? spanRef?.getRootNode() ?? document;
377
- }, [value, spanRef]);
378
- return /* @__PURE__ */ jsxs(EnvironmentContextProvider, {
379
- value: useMemo(() => ({
380
- getRootNode,
381
- getWindow: () => getWindow(getRootNode()),
382
- getDocument: () => getDocument(getRootNode())
383
- }), [getRootNode]),
384
- children: [children, !value && /* @__PURE__ */ jsx("span", {
385
- hidden: true,
386
- ref: setSpanRef
387
- })]
388
- });
389
- };
390
-
391
- //#endregion
392
- //#region src/providers/locale/use-locale-context.ts
393
- const [LocaleContextProvider, useLocaleContext] = createContext$1({
394
- name: "LocaleContext",
395
- hookName: "useLocaleContext",
396
- providerName: "<LocaleProvider />",
397
- strict: false,
398
- defaultValue: {
399
- dir: "ltr",
400
- locale: "en-US"
401
- }
402
- });
403
-
404
- //#endregion
405
- //#region src/providers/locale/locale-provider.tsx
406
- const LocaleProvider = (props) => {
407
- const { children, locale } = props;
408
- return /* @__PURE__ */ jsx(LocaleContextProvider, {
409
- value: {
410
- locale,
411
- dir: isRTL(locale) ? "rtl" : "ltr"
412
- },
413
- children
414
- });
415
- };
416
-
417
- //#endregion
418
- //#region src/providers/locale/use-collator.ts
419
- function useCollator(props = {}) {
420
- const env = useLocaleContext();
421
- const locale = props.locale ?? env.locale;
422
- return useMemo(() => {
423
- const { locale: _, ...options } = props;
424
- return createCollator(locale, options);
425
- }, [locale, props]);
426
- }
427
-
428
- //#endregion
429
- //#region src/providers/locale/use-filter.ts
430
- function useFilter(props) {
431
- const env = useLocaleContext();
432
- const locale = props.locale ?? env.locale;
433
- return useMemo(() => createFilter({
434
- ...props,
435
- locale
436
- }), [locale, props]);
437
- }
438
-
439
- //#endregion
440
- //#region src/utils/compose-refs.ts
441
- function composeRefs(...refs) {
442
- return (node) => {
443
- const cleanUps = [];
444
- for (const ref of refs) if (typeof ref === "function") {
445
- const cb = ref(node);
446
- if (typeof cb === "function") cleanUps.push(cb);
447
- } else if (ref) ref.current = node;
448
- if (cleanUps.length) return () => {
449
- for (const cleanUp of cleanUps) cleanUp();
450
- };
451
- };
452
- }
453
-
454
- //#endregion
455
- //#region src/components/factory.ts
456
- function getRef(element) {
457
- let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
458
- let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
459
- if (mayWarn) return element.ref;
460
- getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
461
- mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
462
- if (mayWarn) return element.props.ref;
463
- return element.props.ref || element.ref;
464
- }
465
- const withAsChild = (Component) => {
466
- const Comp = memo(forwardRef((props, ref) => {
467
- const { asChild, children, ...restProps } = props;
468
- if (!asChild) return createElement(Component, {
469
- ...restProps,
470
- ref
471
- }, children);
472
- if (!isValidElement(children)) return null;
473
- const onlyChild = Children.only(children);
474
- const childRef = getRef(onlyChild);
475
- return cloneElement(onlyChild, {
476
- ...mergeProps(restProps, onlyChild.props),
477
- ref: ref ? composeRefs(ref, childRef) : childRef
478
- });
479
- }));
480
- Comp.displayName = typeof Component === "string" ? Component : Component.displayName || Component.name;
481
- return Comp;
482
- };
483
- const jsxFactory = () => {
484
- const cache = /* @__PURE__ */ new Map();
485
- return new Proxy(withAsChild, {
486
- apply(_target, _thisArg, argArray) {
487
- return withAsChild(argArray[0]);
488
- },
489
- get(_, element) {
490
- const asElement = element;
491
- if (!cache.has(asElement)) cache.set(asElement, withAsChild(asElement));
492
- return cache.get(asElement);
493
- }
494
- });
495
- };
496
- const sprawlify = jsxFactory();
497
-
498
- //#endregion
499
- export { LocaleProvider as a, useEnvironmentContext as c, normalizeProps as d, useMachine as f, useCollator as i, mergeProps$1 as l, sprawlify as n, useLocaleContext as o, useFilter as r, EnvironmentProvider as s, jsxFactory as t, Portal as u };
349
+ export { useMachine as i, Portal as n, normalizeProps as r, mergeProps$1 as t };
@@ -38,7 +38,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
38
38
  }) : target, mod));
39
39
 
40
40
  //#endregion
41
- const require_create_context = require('./create-context-DCEySQ7J.cjs');
42
41
  let __sprawlify_primitives_core = require("@sprawlify/primitives/core");
43
42
  let __sprawlify_primitives_utils = require("@sprawlify/primitives/utils");
44
43
  let react = require("react");
@@ -46,8 +45,6 @@ react = __toESM(react);
46
45
  let react_dom = require("react-dom");
47
46
  let __sprawlify_primitives_types = require("@sprawlify/primitives/types");
48
47
  let react_jsx_runtime = require("react/jsx-runtime");
49
- let __sprawlify_primitives_dom_query = require("@sprawlify/primitives/dom-query");
50
- let __sprawlify_primitives_i18n_utils = require("@sprawlify/primitives/i18n-utils");
51
48
 
52
49
  //#region src/core/use-layout-effect.ts
53
50
  const useSafeLayoutEffect = typeof globalThis.document !== "undefined" ? react.useLayoutEffect : react.useEffect;
@@ -389,165 +386,6 @@ const Portal = (props) => {
389
386
  };
390
387
 
391
388
  //#endregion
392
- //#region src/utils/run-if-fn.ts
393
- const isFunction = (value) => typeof value === "function";
394
- const runIfFn = (valueOrFn, ...args) => isFunction(valueOrFn) ? valueOrFn(...args) : valueOrFn;
395
-
396
- //#endregion
397
- //#region src/providers/environment/use-environment-context.ts
398
- const [EnvironmentContextProvider, useEnvironmentContext] = require_create_context.createContext({
399
- name: "EnvironmentContext",
400
- hookName: "useEnvironmentContext",
401
- providerName: "<EnvironmentProvider />",
402
- strict: false,
403
- defaultValue: {
404
- getRootNode: () => document,
405
- getDocument: () => document,
406
- getWindow: () => window
407
- }
408
- });
409
-
410
- //#endregion
411
- //#region src/providers/environment/environment-provider.tsx
412
- const EnvironmentProvider = (props) => {
413
- const { value, children } = props;
414
- const [spanRef, setSpanRef] = (0, react.useState)();
415
- const getRootNode = (0, react.useMemo)(() => {
416
- return () => runIfFn(value) ?? spanRef?.getRootNode() ?? document;
417
- }, [value, spanRef]);
418
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(EnvironmentContextProvider, {
419
- value: (0, react.useMemo)(() => ({
420
- getRootNode,
421
- getWindow: () => (0, __sprawlify_primitives_dom_query.getWindow)(getRootNode()),
422
- getDocument: () => (0, __sprawlify_primitives_dom_query.getDocument)(getRootNode())
423
- }), [getRootNode]),
424
- children: [children, !value && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
425
- hidden: true,
426
- ref: setSpanRef
427
- })]
428
- });
429
- };
430
-
431
- //#endregion
432
- //#region src/providers/locale/use-locale-context.ts
433
- const [LocaleContextProvider, useLocaleContext] = require_create_context.createContext({
434
- name: "LocaleContext",
435
- hookName: "useLocaleContext",
436
- providerName: "<LocaleProvider />",
437
- strict: false,
438
- defaultValue: {
439
- dir: "ltr",
440
- locale: "en-US"
441
- }
442
- });
443
-
444
- //#endregion
445
- //#region src/providers/locale/locale-provider.tsx
446
- const LocaleProvider = (props) => {
447
- const { children, locale } = props;
448
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LocaleContextProvider, {
449
- value: {
450
- locale,
451
- dir: (0, __sprawlify_primitives_i18n_utils.isRTL)(locale) ? "rtl" : "ltr"
452
- },
453
- children
454
- });
455
- };
456
-
457
- //#endregion
458
- //#region src/providers/locale/use-collator.ts
459
- function useCollator(props = {}) {
460
- const env = useLocaleContext();
461
- const locale = props.locale ?? env.locale;
462
- return (0, react.useMemo)(() => {
463
- const { locale: _, ...options } = props;
464
- return (0, __sprawlify_primitives_i18n_utils.createCollator)(locale, options);
465
- }, [locale, props]);
466
- }
467
-
468
- //#endregion
469
- //#region src/providers/locale/use-filter.ts
470
- function useFilter(props) {
471
- const env = useLocaleContext();
472
- const locale = props.locale ?? env.locale;
473
- return (0, react.useMemo)(() => (0, __sprawlify_primitives_i18n_utils.createFilter)({
474
- ...props,
475
- locale
476
- }), [locale, props]);
477
- }
478
-
479
- //#endregion
480
- //#region src/utils/compose-refs.ts
481
- function composeRefs(...refs) {
482
- return (node) => {
483
- const cleanUps = [];
484
- for (const ref of refs) if (typeof ref === "function") {
485
- const cb = ref(node);
486
- if (typeof cb === "function") cleanUps.push(cb);
487
- } else if (ref) ref.current = node;
488
- if (cleanUps.length) return () => {
489
- for (const cleanUp of cleanUps) cleanUp();
490
- };
491
- };
492
- }
493
-
494
- //#endregion
495
- //#region src/components/factory.ts
496
- function getRef(element) {
497
- let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
498
- let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
499
- if (mayWarn) return element.ref;
500
- getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
501
- mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
502
- if (mayWarn) return element.props.ref;
503
- return element.props.ref || element.ref;
504
- }
505
- const withAsChild = (Component) => {
506
- const Comp = (0, react.memo)((0, react.forwardRef)((props, ref) => {
507
- const { asChild, children, ...restProps } = props;
508
- if (!asChild) return (0, react.createElement)(Component, {
509
- ...restProps,
510
- ref
511
- }, children);
512
- if (!(0, react.isValidElement)(children)) return null;
513
- const onlyChild = react.Children.only(children);
514
- const childRef = getRef(onlyChild);
515
- return (0, react.cloneElement)(onlyChild, {
516
- ...(0, __sprawlify_primitives_core.mergeProps)(restProps, onlyChild.props),
517
- ref: ref ? composeRefs(ref, childRef) : childRef
518
- });
519
- }));
520
- Comp.displayName = typeof Component === "string" ? Component : Component.displayName || Component.name;
521
- return Comp;
522
- };
523
- const jsxFactory = () => {
524
- const cache = /* @__PURE__ */ new Map();
525
- return new Proxy(withAsChild, {
526
- apply(_target, _thisArg, argArray) {
527
- return withAsChild(argArray[0]);
528
- },
529
- get(_, element) {
530
- const asElement = element;
531
- if (!cache.has(asElement)) cache.set(asElement, withAsChild(asElement));
532
- return cache.get(asElement);
533
- }
534
- });
535
- };
536
- const sprawlify = jsxFactory();
537
-
538
- //#endregion
539
- Object.defineProperty(exports, 'EnvironmentProvider', {
540
- enumerable: true,
541
- get: function () {
542
- return EnvironmentProvider;
543
- }
544
- });
545
- Object.defineProperty(exports, 'LocaleProvider', {
546
- enumerable: true,
547
- get: function () {
548
- return LocaleProvider;
549
- }
550
- });
551
389
  Object.defineProperty(exports, 'Portal', {
552
390
  enumerable: true,
553
391
  get: function () {
@@ -566,48 +404,12 @@ Object.defineProperty(exports, '__toESM', {
566
404
  return __toESM;
567
405
  }
568
406
  });
569
- Object.defineProperty(exports, 'jsxFactory', {
570
- enumerable: true,
571
- get: function () {
572
- return jsxFactory;
573
- }
574
- });
575
407
  Object.defineProperty(exports, 'normalizeProps', {
576
408
  enumerable: true,
577
409
  get: function () {
578
410
  return normalizeProps;
579
411
  }
580
412
  });
581
- Object.defineProperty(exports, 'sprawlify', {
582
- enumerable: true,
583
- get: function () {
584
- return sprawlify;
585
- }
586
- });
587
- Object.defineProperty(exports, 'useCollator', {
588
- enumerable: true,
589
- get: function () {
590
- return useCollator;
591
- }
592
- });
593
- Object.defineProperty(exports, 'useEnvironmentContext', {
594
- enumerable: true,
595
- get: function () {
596
- return useEnvironmentContext;
597
- }
598
- });
599
- Object.defineProperty(exports, 'useFilter', {
600
- enumerable: true,
601
- get: function () {
602
- return useFilter;
603
- }
604
- });
605
- Object.defineProperty(exports, 'useLocaleContext', {
606
- enumerable: true,
607
- get: function () {
608
- return useLocaleContext;
609
- }
610
- });
611
413
  Object.defineProperty(exports, 'useMachine', {
612
414
  enumerable: true,
613
415
  get: function () {
@@ -1,4 +1,4 @@
1
- const require_factory = require('./factory-CfqPG186.cjs');
1
+ const require_core = require('./core-CPLjF6nm.cjs');
2
2
  let __sprawlify_primitives_utils = require("@sprawlify/primitives/utils");
3
3
  let react = require("react");
4
4
 
@@ -0,0 +1,46 @@
1
+ import { t as createContext$1 } from "./create-context-CdjrBhu7.mjs";
2
+ import { useMemo, useState } from "react";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ import { getDocument, getWindow } from "@sprawlify/primitives/dom-query";
5
+
6
+ //#region src/utils/run-if-fn.ts
7
+ const isFunction = (value) => typeof value === "function";
8
+ const runIfFn = (valueOrFn, ...args) => isFunction(valueOrFn) ? valueOrFn(...args) : valueOrFn;
9
+
10
+ //#endregion
11
+ //#region src/providers/environment/use-environment-context.ts
12
+ const [EnvironmentContextProvider, useEnvironmentContext] = createContext$1({
13
+ name: "EnvironmentContext",
14
+ hookName: "useEnvironmentContext",
15
+ providerName: "<EnvironmentProvider />",
16
+ strict: false,
17
+ defaultValue: {
18
+ getRootNode: () => document,
19
+ getDocument: () => document,
20
+ getWindow: () => window
21
+ }
22
+ });
23
+
24
+ //#endregion
25
+ //#region src/providers/environment/environment-provider.tsx
26
+ const EnvironmentProvider = (props) => {
27
+ const { value, children } = props;
28
+ const [spanRef, setSpanRef] = useState();
29
+ const getRootNode = useMemo(() => {
30
+ return () => runIfFn(value) ?? spanRef?.getRootNode() ?? document;
31
+ }, [value, spanRef]);
32
+ return /* @__PURE__ */ jsxs(EnvironmentContextProvider, {
33
+ value: useMemo(() => ({
34
+ getRootNode,
35
+ getWindow: () => getWindow(getRootNode()),
36
+ getDocument: () => getDocument(getRootNode())
37
+ }), [getRootNode]),
38
+ children: [children, !value && /* @__PURE__ */ jsx("span", {
39
+ hidden: true,
40
+ ref: setSpanRef
41
+ })]
42
+ });
43
+ };
44
+
45
+ //#endregion
46
+ export { useEnvironmentContext as n, EnvironmentProvider as t };
@@ -0,0 +1,58 @@
1
+ const require_core = require('./core-CPLjF6nm.cjs');
2
+ const require_create_context = require('./create-context-D6DyFRSf.cjs');
3
+ let react = require("react");
4
+ let react_jsx_runtime = require("react/jsx-runtime");
5
+ let __sprawlify_primitives_dom_query = require("@sprawlify/primitives/dom-query");
6
+
7
+ //#region src/utils/run-if-fn.ts
8
+ const isFunction = (value) => typeof value === "function";
9
+ const runIfFn = (valueOrFn, ...args) => isFunction(valueOrFn) ? valueOrFn(...args) : valueOrFn;
10
+
11
+ //#endregion
12
+ //#region src/providers/environment/use-environment-context.ts
13
+ const [EnvironmentContextProvider, useEnvironmentContext] = require_create_context.createContext({
14
+ name: "EnvironmentContext",
15
+ hookName: "useEnvironmentContext",
16
+ providerName: "<EnvironmentProvider />",
17
+ strict: false,
18
+ defaultValue: {
19
+ getRootNode: () => document,
20
+ getDocument: () => document,
21
+ getWindow: () => window
22
+ }
23
+ });
24
+
25
+ //#endregion
26
+ //#region src/providers/environment/environment-provider.tsx
27
+ const EnvironmentProvider = (props) => {
28
+ const { value, children } = props;
29
+ const [spanRef, setSpanRef] = (0, react.useState)();
30
+ const getRootNode = (0, react.useMemo)(() => {
31
+ return () => runIfFn(value) ?? spanRef?.getRootNode() ?? document;
32
+ }, [value, spanRef]);
33
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(EnvironmentContextProvider, {
34
+ value: (0, react.useMemo)(() => ({
35
+ getRootNode,
36
+ getWindow: () => (0, __sprawlify_primitives_dom_query.getWindow)(getRootNode()),
37
+ getDocument: () => (0, __sprawlify_primitives_dom_query.getDocument)(getRootNode())
38
+ }), [getRootNode]),
39
+ children: [children, !value && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
40
+ hidden: true,
41
+ ref: setSpanRef
42
+ })]
43
+ });
44
+ };
45
+
46
+ //#endregion
47
+ Object.defineProperty(exports, 'EnvironmentProvider', {
48
+ enumerable: true,
49
+ get: function () {
50
+ return EnvironmentProvider;
51
+ }
52
+ });
53
+ Object.defineProperty(exports, 'useEnvironmentContext', {
54
+ enumerable: true,
55
+ get: function () {
56
+ return useEnvironmentContext;
57
+ }
58
+ });
@@ -0,0 +1,15 @@
1
+ import React, { ComponentPropsWithoutRef, JSX } from "react";
2
+
3
+ //#region src/components/factory.d.ts
4
+ interface PolymorphicProps {
5
+ asChild?: boolean | undefined;
6
+ }
7
+ type JsxElements = { [E in keyof JSX.IntrinsicElements]: SprawlifyForwardRefComponent<E> };
8
+ type SprawlifyForwardRefComponent<E$1 extends React.ElementType> = React.ForwardRefExoticComponent<SprawlifyPropsWithRef<E$1>>;
9
+ type SprawlifyPropsWithRef<E$1 extends React.ElementType> = React.ComponentPropsWithRef<E$1> & PolymorphicProps;
10
+ type HTMLProps<T extends keyof JSX.IntrinsicElements> = ComponentPropsWithoutRef<T>;
11
+ type HTMLSprawlifyProps<T extends keyof JSX.IntrinsicElements> = HTMLProps<T> & PolymorphicProps;
12
+ declare const jsxFactory: () => JsxElements;
13
+ declare const sprawlify: JsxElements;
14
+ //#endregion
15
+ export { sprawlify as a, jsxFactory as i, HTMLSprawlifyProps as n, PolymorphicProps as r, HTMLProps as t };
@@ -0,0 +1,81 @@
1
+ const require_core = require('./core-CPLjF6nm.cjs');
2
+ let __sprawlify_primitives_core = require("@sprawlify/primitives/core");
3
+ let react = require("react");
4
+
5
+ //#region src/utils/compose-refs.ts
6
+ function composeRefs(...refs) {
7
+ return (node) => {
8
+ const cleanUps = [];
9
+ for (const ref of refs) if (typeof ref === "function") {
10
+ const cb = ref(node);
11
+ if (typeof cb === "function") cleanUps.push(cb);
12
+ } else if (ref) ref.current = node;
13
+ if (cleanUps.length) return () => {
14
+ for (const cleanUp of cleanUps) cleanUp();
15
+ };
16
+ };
17
+ }
18
+
19
+ //#endregion
20
+ //#region src/components/factory.ts
21
+ function getRef(element) {
22
+ let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
23
+ let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
24
+ if (mayWarn) return element.ref;
25
+ getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
26
+ mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
27
+ if (mayWarn) return element.props.ref;
28
+ return element.props.ref || element.ref;
29
+ }
30
+ const withAsChild = (Component) => {
31
+ const Comp = (0, react.memo)((0, react.forwardRef)((props, ref) => {
32
+ const { asChild, children, ...restProps } = props;
33
+ if (!asChild) return (0, react.createElement)(Component, {
34
+ ...restProps,
35
+ ref
36
+ }, children);
37
+ if (!(0, react.isValidElement)(children)) return null;
38
+ const onlyChild = react.Children.only(children);
39
+ const childRef = getRef(onlyChild);
40
+ return (0, react.cloneElement)(onlyChild, {
41
+ ...(0, __sprawlify_primitives_core.mergeProps)(restProps, onlyChild.props),
42
+ ref: ref ? composeRefs(ref, childRef) : childRef
43
+ });
44
+ }));
45
+ Comp.displayName = typeof Component === "string" ? Component : Component.displayName || Component.name;
46
+ return Comp;
47
+ };
48
+ const jsxFactory = () => {
49
+ const cache = /* @__PURE__ */ new Map();
50
+ return new Proxy(withAsChild, {
51
+ apply(_target, _thisArg, argArray) {
52
+ return withAsChild(argArray[0]);
53
+ },
54
+ get(_, element) {
55
+ const asElement = element;
56
+ if (!cache.has(asElement)) cache.set(asElement, withAsChild(asElement));
57
+ return cache.get(asElement);
58
+ }
59
+ });
60
+ };
61
+ const sprawlify = jsxFactory();
62
+
63
+ //#endregion
64
+ Object.defineProperty(exports, 'composeRefs', {
65
+ enumerable: true,
66
+ get: function () {
67
+ return composeRefs;
68
+ }
69
+ });
70
+ Object.defineProperty(exports, 'jsxFactory', {
71
+ enumerable: true,
72
+ get: function () {
73
+ return jsxFactory;
74
+ }
75
+ });
76
+ Object.defineProperty(exports, 'sprawlify', {
77
+ enumerable: true,
78
+ get: function () {
79
+ return sprawlify;
80
+ }
81
+ });
@@ -0,0 +1,63 @@
1
+ import { mergeProps } from "@sprawlify/primitives/core";
2
+ import { Children, cloneElement, createElement, forwardRef, isValidElement, memo } from "react";
3
+
4
+ //#region src/utils/compose-refs.ts
5
+ function composeRefs(...refs) {
6
+ return (node) => {
7
+ const cleanUps = [];
8
+ for (const ref of refs) if (typeof ref === "function") {
9
+ const cb = ref(node);
10
+ if (typeof cb === "function") cleanUps.push(cb);
11
+ } else if (ref) ref.current = node;
12
+ if (cleanUps.length) return () => {
13
+ for (const cleanUp of cleanUps) cleanUp();
14
+ };
15
+ };
16
+ }
17
+
18
+ //#endregion
19
+ //#region src/components/factory.ts
20
+ function getRef(element) {
21
+ let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
22
+ let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
23
+ if (mayWarn) return element.ref;
24
+ getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
25
+ mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
26
+ if (mayWarn) return element.props.ref;
27
+ return element.props.ref || element.ref;
28
+ }
29
+ const withAsChild = (Component) => {
30
+ const Comp = memo(forwardRef((props, ref) => {
31
+ const { asChild, children, ...restProps } = props;
32
+ if (!asChild) return createElement(Component, {
33
+ ...restProps,
34
+ ref
35
+ }, children);
36
+ if (!isValidElement(children)) return null;
37
+ const onlyChild = Children.only(children);
38
+ const childRef = getRef(onlyChild);
39
+ return cloneElement(onlyChild, {
40
+ ...mergeProps(restProps, onlyChild.props),
41
+ ref: ref ? composeRefs(ref, childRef) : childRef
42
+ });
43
+ }));
44
+ Comp.displayName = typeof Component === "string" ? Component : Component.displayName || Component.name;
45
+ return Comp;
46
+ };
47
+ const jsxFactory = () => {
48
+ const cache = /* @__PURE__ */ new Map();
49
+ return new Proxy(withAsChild, {
50
+ apply(_target, _thisArg, argArray) {
51
+ return withAsChild(argArray[0]);
52
+ },
53
+ get(_, element) {
54
+ const asElement = element;
55
+ if (!cache.has(asElement)) cache.set(asElement, withAsChild(asElement));
56
+ return cache.get(asElement);
57
+ }
58
+ });
59
+ };
60
+ const sprawlify = jsxFactory();
61
+
62
+ //#endregion
63
+ export { sprawlify as n, composeRefs as r, jsxFactory as t };
@@ -0,0 +1,15 @@
1
+ import React, { ComponentPropsWithoutRef, JSX } from "react";
2
+
3
+ //#region src/components/factory.d.ts
4
+ interface PolymorphicProps {
5
+ asChild?: boolean | undefined;
6
+ }
7
+ type JsxElements = { [E in keyof JSX.IntrinsicElements]: SprawlifyForwardRefComponent<E> };
8
+ type SprawlifyForwardRefComponent<E$1 extends React.ElementType> = React.ForwardRefExoticComponent<SprawlifyPropsWithRef<E$1>>;
9
+ type SprawlifyPropsWithRef<E$1 extends React.ElementType> = React.ComponentPropsWithRef<E$1> & PolymorphicProps;
10
+ type HTMLProps<T extends keyof JSX.IntrinsicElements> = ComponentPropsWithoutRef<T>;
11
+ type HTMLSprawlifyProps<T extends keyof JSX.IntrinsicElements> = HTMLProps<T> & PolymorphicProps;
12
+ declare const jsxFactory: () => JsxElements;
13
+ declare const sprawlify: JsxElements;
14
+ //#endregion
15
+ export { sprawlify as a, jsxFactory as i, HTMLSprawlifyProps as n, PolymorphicProps as r, HTMLProps as t };