index.mjs 4.2 KB

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