index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. var $iMixA$babelruntimehelpersextends = require("@babel/runtime/helpers/extends");
  2. var $iMixA$react = require("react");
  3. var $iMixA$reactdom = require("react-dom");
  4. var $iMixA$radixuireactslot = require("@radix-ui/react-slot");
  5. function $parcel$export(e, n, v, s) {
  6. Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
  7. }
  8. function $parcel$interopDefault(a) {
  9. return a && a.__esModule ? a.default : a;
  10. }
  11. $parcel$export(module.exports, "Primitive", () => $c3def6332c2749a6$export$250ffa63cdc0d034);
  12. $parcel$export(module.exports, "Root", () => $c3def6332c2749a6$export$be92b6f5f03c0fe9);
  13. $parcel$export(module.exports, "dispatchDiscreteCustomEvent", () => $c3def6332c2749a6$export$6d1a0317bde7de7f);
  14. const $c3def6332c2749a6$var$NODES = [
  15. 'a',
  16. 'button',
  17. 'div',
  18. 'form',
  19. 'h2',
  20. 'h3',
  21. 'img',
  22. 'input',
  23. 'label',
  24. 'li',
  25. 'nav',
  26. 'ol',
  27. 'p',
  28. 'span',
  29. 'svg',
  30. 'ul'
  31. ]; // Temporary while we await merge of this fix:
  32. // https://github.com/DefinitelyTyped/DefinitelyTyped/pull/55396
  33. // prettier-ignore
  34. /* -------------------------------------------------------------------------------------------------
  35. * Primitive
  36. * -----------------------------------------------------------------------------------------------*/ const $c3def6332c2749a6$export$250ffa63cdc0d034 = $c3def6332c2749a6$var$NODES.reduce((primitive, node)=>{
  37. const Node = /*#__PURE__*/ $iMixA$react.forwardRef((props, forwardedRef)=>{
  38. const { asChild: asChild , ...primitiveProps } = props;
  39. const Comp = asChild ? $iMixA$radixuireactslot.Slot : node;
  40. $iMixA$react.useEffect(()=>{
  41. window[Symbol.for('radix-ui')] = true;
  42. }, []);
  43. return /*#__PURE__*/ $iMixA$react.createElement(Comp, ($parcel$interopDefault($iMixA$babelruntimehelpersextends))({}, primitiveProps, {
  44. ref: forwardedRef
  45. }));
  46. });
  47. Node.displayName = `Primitive.${node}`;
  48. return {
  49. ...primitive,
  50. [node]: Node
  51. };
  52. }, {});
  53. /* -------------------------------------------------------------------------------------------------
  54. * Utils
  55. * -----------------------------------------------------------------------------------------------*/ /**
  56. * Flush custom event dispatch
  57. * https://github.com/radix-ui/primitives/pull/1378
  58. *
  59. * React batches *all* event handlers since version 18, this introduces certain considerations when using custom event types.
  60. *
  61. * Internally, React prioritises events in the following order:
  62. * - discrete
  63. * - continuous
  64. * - default
  65. *
  66. * https://github.com/facebook/react/blob/a8a4742f1c54493df00da648a3f9d26e3db9c8b5/packages/react-dom/src/events/ReactDOMEventListener.js#L294-L350
  67. *
  68. * `discrete` is an important distinction as updates within these events are applied immediately.
  69. * React however, is not able to infer the priority of custom event types due to how they are detected internally.
  70. * Because of this, it's possible for updates from custom events to be unexpectedly batched when
  71. * dispatched by another `discrete` event.
  72. *
  73. * In order to ensure that updates from custom events are applied predictably, we need to manually flush the batch.
  74. * This utility should be used when dispatching a custom event from within another `discrete` event, this utility
  75. * is not nessesary when dispatching known event types, or if dispatching a custom type inside a non-discrete event.
  76. * For example:
  77. *
  78. * dispatching a known click 👎
  79. * target.dispatchEvent(new Event(‘click’))
  80. *
  81. * dispatching a custom type within a non-discrete event 👎
  82. * onScroll={(event) => event.target.dispatchEvent(new CustomEvent(‘customType’))}
  83. *
  84. * dispatching a custom type within a `discrete` event 👍
  85. * onPointerDown={(event) => dispatchDiscreteCustomEvent(event.target, new CustomEvent(‘customType’))}
  86. *
  87. * Note: though React classifies `focus`, `focusin` and `focusout` events as `discrete`, it's not recommended to use
  88. * this utility with them. This is because it's possible for those handlers to be called implicitly during render
  89. * e.g. when focus is within a component as it is unmounted, or when managing focus on mount.
  90. */ function $c3def6332c2749a6$export$6d1a0317bde7de7f(target, event) {
  91. if (target) $iMixA$reactdom.flushSync(()=>target.dispatchEvent(event)
  92. );
  93. }
  94. /* -----------------------------------------------------------------------------------------------*/ const $c3def6332c2749a6$export$be92b6f5f03c0fe9 = $c3def6332c2749a6$export$250ffa63cdc0d034;
  95. //# sourceMappingURL=index.js.map