@radix-ui/react-primitive 0.1.5-rc.3 → 0.1.5-rc.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -11,6 +11,43 @@ export type PrimitivePropsWithRef<E extends React.ElementType> = React.Component
11
11
  interface PrimitiveForwardRefComponent<E extends React.ElementType> extends React.ForwardRefExoticComponent<PrimitivePropsWithRef<E>> {
12
12
  }
13
13
  export const Primitive: Primitives;
14
+ /**
15
+ * Flush custom event dispatch
16
+ * https://github.com/radix-ui/primitives/pull/1378
17
+ *
18
+ * React batches *all* event handlers since version 18, this introduces certain considerations when using custom event types.
19
+ *
20
+ * Internally, React prioritises events in the following order:
21
+ * - discrete
22
+ * - continuous
23
+ * - default
24
+ *
25
+ * https://github.com/facebook/react/blob/a8a4742f1c54493df00da648a3f9d26e3db9c8b5/packages/react-dom/src/events/ReactDOMEventListener.js#L294-L350
26
+ *
27
+ * `discrete` is an important distinction as updates within these events are applied immediately.
28
+ * React however, is not able to infer the priority of custom event types due to how they are detected internally.
29
+ * Because of this, it's possible for updates from custom events to be unexpectedly batched when
30
+ * dispatched by another `discrete` event.
31
+ *
32
+ * In order to ensure that updates from custom events are applied predictably, we need to manually flush the batch.
33
+ * This utility should be used when dispatching a custom event from within another `discrete` event, this utility
34
+ * is not nessesary when dispatching known event types, or if dispatching a custom type inside a non-discrete event.
35
+ * For example:
36
+ *
37
+ * dispatching a known click 👎
38
+ * target.dispatchEvent(new Event(‘click’))
39
+ *
40
+ * dispatching a custom type within a non-discrete event 👎
41
+ * onScroll={(event) => event.target.dispatchEvent(new CustomEvent(‘customType’))}
42
+ *
43
+ * dispatching a custom type within a `discrete` event 👍
44
+ * onPointerDown={(event) => dispatchDiscreteCustomEvent(event.target, new CustomEvent(‘customType’))}
45
+ *
46
+ * Note: though React classifies `focus`, `focusin` and `focusout` events as `discrete`, it's not recommended to use
47
+ * this utility with them. This is because it's possible for those handlers to be called implicitly during render
48
+ * e.g. when focus is within a component as it is unmounted, or when managing focus on mount.
49
+ */
50
+ export function dispatchDiscreteCustomEvent<E extends CustomEvent>(target: E['target'], event: E): void;
14
51
  export const Root: Primitives;
15
52
 
16
53
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"mappings":";AAGA,QAAA,MAAM,sGAcI,CAAC;AAKX,qBAAqB,CAAC,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC,KAAK,SAAS,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;AAC7G,qCAA8B,CAAC,SAAS,MAAM,WAAW,IAAI,gBAC3D,MAAM,cAAc,CAAC,CAAC,CAAC,CACxB,CAAC;AAEF,kBAAkB;KAAG,CAAC,IAAI,YAAY,CAAC,MAAM,CAAC,GAAG,6BAA6B,CAAC,CAAC;CAAE,CAAC;AACnF,kCAA2B,CAAC,SAAS,MAAM,WAAW,IAAI,MAAM,qBAAqB,CAAC,CAAC,CAAC,GAAG;IACzF,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,uCAAuC,CAAC,SAAS,MAAM,WAAW,CAChE,SAAQ,KAAK,CAAC,yBAAyB,CAAC,sBAAsB,CAAC,CAAC,CAAC;CAAG;AAMtE,OAAA,MAAM,qBAoBL,CAAC;AAMF,OAAA,MAAM,gBAAgB,CAAC","sources":["packages/react/primitive/src/packages/react/primitive/src/Primitive.tsx","packages/react/primitive/src/packages/react/primitive/src/index.ts","packages/react/primitive/src/index.ts"],"sourcesContent":[null,null,"export * from './Primitive';\n"],"names":[],"version":3,"file":"index.d.ts.map"}
1
+ {"mappings":";AAIA,QAAA,MAAM,sGAcI,CAAC;AAKX,qBAAqB,CAAC,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC,KAAK,SAAS,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;AAC7G,qCAA8B,CAAC,SAAS,MAAM,WAAW,IAAI,gBAC3D,MAAM,cAAc,CAAC,CAAC,CAAC,CACxB,CAAC;AAEF,kBAAkB;KAAG,CAAC,IAAI,YAAY,CAAC,MAAM,CAAC,GAAG,6BAA6B,CAAC,CAAC;CAAE,CAAC;AACnF,kCAA2B,CAAC,SAAS,MAAM,WAAW,IAAI,MAAM,qBAAqB,CAAC,CAAC,CAAC,GAAG;IACzF,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,uCAAuC,CAAC,SAAS,MAAM,WAAW,CAChE,SAAQ,KAAK,CAAC,yBAAyB,CAAC,sBAAsB,CAAC,CAAC,CAAC;CAAG;AAMtE,OAAA,MAAM,qBAoBc,CAAC;AAUrB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,4CAAqC,CAAC,SAAS,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAC,QAExF;AAID,OAAA,MAAM,gBAAgB,CAAC","sources":["packages/react/primitive/src/packages/react/primitive/src/Primitive.tsx","packages/react/primitive/src/packages/react/primitive/src/index.ts","packages/react/primitive/src/index.ts"],"sourcesContent":[null,null,"export * from './Primitive';\n"],"names":[],"version":3,"file":"index.d.ts.map"}
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  var $iMixA$babelruntimehelpersextends = require("@babel/runtime/helpers/extends");
2
2
  var $iMixA$react = require("react");
3
+ var $iMixA$reactdom = require("react-dom");
3
4
  var $iMixA$radixuireactslot = require("@radix-ui/react-slot");
4
5
 
5
6
  function $parcel$exportWildcard(dest, source) {
@@ -27,10 +28,12 @@ function $parcel$export(e, n, v, s) {
27
28
  var $c3def6332c2749a6$exports = {};
28
29
 
29
30
  $parcel$export($c3def6332c2749a6$exports, "Primitive", () => $c3def6332c2749a6$export$250ffa63cdc0d034);
31
+ $parcel$export($c3def6332c2749a6$exports, "dispatchDiscreteCustomEvent", () => $c3def6332c2749a6$export$6d1a0317bde7de7f);
30
32
  $parcel$export($c3def6332c2749a6$exports, "Root", () => $c3def6332c2749a6$export$be92b6f5f03c0fe9);
31
33
 
32
34
 
33
35
 
36
+
34
37
  const $c3def6332c2749a6$var$NODES = [
35
38
  'a',
36
39
  'button',
@@ -50,22 +53,66 @@ const $c3def6332c2749a6$var$NODES = [
50
53
  // prettier-ignore
51
54
  /* -------------------------------------------------------------------------------------------------
52
55
  * Primitive
53
- * -----------------------------------------------------------------------------------------------*/ const $c3def6332c2749a6$export$250ffa63cdc0d034 = $c3def6332c2749a6$var$NODES.reduce((primitive, node)=>({
56
+ * -----------------------------------------------------------------------------------------------*/ const $c3def6332c2749a6$export$250ffa63cdc0d034 = $c3def6332c2749a6$var$NODES.reduce((primitive, node)=>{
57
+ const Node = /*#__PURE__*/ $iMixA$react.forwardRef((props, forwardedRef)=>{
58
+ const { asChild: asChild , ...primitiveProps } = props;
59
+ const Comp = asChild ? $iMixA$radixuireactslot.Slot : node;
60
+ $iMixA$react.useEffect(()=>{
61
+ window[Symbol.for('radix-ui')] = true;
62
+ }, []); // DEPRECATED
63
+ return /*#__PURE__*/ $iMixA$react.createElement(Comp, ($parcel$interopDefault($iMixA$babelruntimehelpersextends))({}, primitiveProps, {
64
+ ref: forwardedRef
65
+ }));
66
+ });
67
+ Node.displayName = `Primitive.${node}`;
68
+ return {
54
69
  ...primitive,
55
- [node]: /*#__PURE__*/ $iMixA$react.forwardRef((props, forwardedRef)=>{
56
- const { asChild: asChild , ...primitiveProps } = props;
57
- const Comp = asChild ? $iMixA$radixuireactslot.Slot : node;
58
- $iMixA$react.useEffect(()=>{
59
- window[Symbol.for('radix-ui')] = true;
60
- }, []); // DEPRECATED
61
- return /*#__PURE__*/ $iMixA$react.createElement(Comp, ($parcel$interopDefault($iMixA$babelruntimehelpersextends))({}, primitiveProps, {
62
- ref: forwardedRef
63
- }));
64
- })
65
- })
66
- , {});
70
+ [node]: Node
71
+ };
72
+ }, {});
67
73
  /* -----------------------------------------------------------------------------------------------*/ const $c3def6332c2749a6$var$AS_ERROR = `Warning: The \`as\` prop has been removed in favour of \`asChild\`. For details, see https://radix-ui.com/docs/primitives/overview/styling#changing-the-rendered-element`;
68
- const $c3def6332c2749a6$export$be92b6f5f03c0fe9 = $c3def6332c2749a6$export$250ffa63cdc0d034;
74
+ /* -------------------------------------------------------------------------------------------------
75
+ * Utils
76
+ * -----------------------------------------------------------------------------------------------*/ /**
77
+ * Flush custom event dispatch
78
+ * https://github.com/radix-ui/primitives/pull/1378
79
+ *
80
+ * React batches *all* event handlers since version 18, this introduces certain considerations when using custom event types.
81
+ *
82
+ * Internally, React prioritises events in the following order:
83
+ * - discrete
84
+ * - continuous
85
+ * - default
86
+ *
87
+ * https://github.com/facebook/react/blob/a8a4742f1c54493df00da648a3f9d26e3db9c8b5/packages/react-dom/src/events/ReactDOMEventListener.js#L294-L350
88
+ *
89
+ * `discrete` is an important distinction as updates within these events are applied immediately.
90
+ * React however, is not able to infer the priority of custom event types due to how they are detected internally.
91
+ * Because of this, it's possible for updates from custom events to be unexpectedly batched when
92
+ * dispatched by another `discrete` event.
93
+ *
94
+ * In order to ensure that updates from custom events are applied predictably, we need to manually flush the batch.
95
+ * This utility should be used when dispatching a custom event from within another `discrete` event, this utility
96
+ * is not nessesary when dispatching known event types, or if dispatching a custom type inside a non-discrete event.
97
+ * For example:
98
+ *
99
+ * dispatching a known click 👎
100
+ * target.dispatchEvent(new Event(‘click’))
101
+ *
102
+ * dispatching a custom type within a non-discrete event 👎
103
+ * onScroll={(event) => event.target.dispatchEvent(new CustomEvent(‘customType’))}
104
+ *
105
+ * dispatching a custom type within a `discrete` event 👍
106
+ * onPointerDown={(event) => dispatchDiscreteCustomEvent(event.target, new CustomEvent(‘customType’))}
107
+ *
108
+ * Note: though React classifies `focus`, `focusin` and `focusout` events as `discrete`, it's not recommended to use
109
+ * this utility with them. This is because it's possible for those handlers to be called implicitly during render
110
+ * e.g. when focus is within a component as it is unmounted, or when managing focus on mount.
111
+ */ function $c3def6332c2749a6$export$6d1a0317bde7de7f(target, event) {
112
+ if (target) $iMixA$reactdom.flushSync(()=>target.dispatchEvent(event)
113
+ );
114
+ }
115
+ /* -----------------------------------------------------------------------------------------------*/ const $c3def6332c2749a6$export$be92b6f5f03c0fe9 = $c3def6332c2749a6$export$250ffa63cdc0d034;
69
116
 
70
117
 
71
118
  $parcel$exportWildcard(module.exports, $c3def6332c2749a6$exports);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;A;;;ACGA,MAAME,2BAAK,GAAG;IACZ,GADY;IAEZ,QAFY;IAGZ,KAHY;IAIZ,IAJY;IAKZ,IALY;IAMZ,KANY;IAOZ,IAPY;IAQZ,KARY;IASZ,IATY;IAUZ,GAVY;IAWZ,MAXY;IAYZ,KAZY;IAaZ,IAbY;CAAd,A,EAgBA,8CAhBA;AAiBA,gEAAA;AACA,kBAAA;AAcA;;oGAEA,CAEA,MAAMC,yCAAS,GAAGD,2BAAK,CAACE,MAAN,CAChB,CAACC,SAAD,EAAYC,IAAZ,GAAsB,CAAA;QACpB,GAAGD,SADiB;QAEpB,CAACC,IAAD,CAAA,EAAA,aAAQN,CAAAA,uBAAA,CAAiB,CAACQ,KAAD,EAA4CC,YAA5C,GAAkE;YACzF,MAAM,E,SAAEC,OAAF,CAAA,EAAW,GAAGC,cAAH,EAAX,GAAiCH,KAAvC,AAAM;YACN,MAAMI,IAAS,GAAGF,OAAO,GAAGT,4BAAH,GAAUK,IAAnC,AAAA;YAEAN,sBAAA,CAAgB,IAAM;gBACnBc,MAAD,CAAgBC,MAAM,CAACC,GAAP,CAAW,UAAX,CAAhB,CAAA,GAA0C,IAA1C,CAACF;aADH,EAEG,EAFH,CAAA,CAJyF,CAQzF,aAFC;YAOD,OAAA,aAAO,CAAA,0BAAA,CAAC,IAAD,EAAA,2DAAA,CAAA,EAAA,EAAUH,cAAV,EAAP;gBAAiC,GAAG,EAAEF,YAAL;aAA1B,CAAA,CAAP,CAAO;SAbD,CAcP;KAhBH,CAAA;AADgB,EAmBhB,EAnBgB,CAAlB,AACwB;AAqBxB,oGAAA,CAEA,MAAMc,8BAAQ,GAAI,CAAA,wKAAA,CAAlB,AAAA;AAEA,MAAMC,yCAAI,GAAGrB,yCAAb,AAAA;;ADjEA","sources":["packages/react/primitive/src/index.ts","packages/react/primitive/src/Primitive.tsx"],"sourcesContent":["export * from './Primitive';\n","import * as React from 'react';\nimport { Slot } from '@radix-ui/react-slot';\n\nconst NODES = [\n 'a',\n 'button',\n 'div',\n 'h2',\n 'h3',\n 'img',\n 'li',\n 'nav',\n 'ol',\n 'p',\n 'span',\n 'svg',\n 'ul',\n] as const;\n\n// Temporary while we await merge of this fix:\n// https://github.com/DefinitelyTyped/DefinitelyTyped/pull/55396\n// prettier-ignore\ntype PropsWithoutRef<P> = P extends any ? ('ref' extends keyof P ? Pick<P, Exclude<keyof P, 'ref'>> : P) : P;\ntype ComponentPropsWithoutRef<T extends React.ElementType> = PropsWithoutRef<\n React.ComponentProps<T>\n>;\n\ntype Primitives = { [E in typeof NODES[number]]: PrimitiveForwardRefComponent<E> };\ntype PrimitivePropsWithRef<E extends React.ElementType> = React.ComponentPropsWithRef<E> & {\n asChild?: boolean;\n};\n\ninterface PrimitiveForwardRefComponent<E extends React.ElementType>\n extends React.ForwardRefExoticComponent<PrimitivePropsWithRef<E>> {}\n\n/* -------------------------------------------------------------------------------------------------\n * Primitive\n * -----------------------------------------------------------------------------------------------*/\n\nconst Primitive = NODES.reduce(\n (primitive, node) => ({\n ...primitive,\n [node]: React.forwardRef((props: PrimitivePropsWithRef<typeof node>, forwardedRef: any) => {\n const { asChild, ...primitiveProps } = props;\n const Comp: any = asChild ? Slot : node;\n\n React.useEffect(() => {\n (window as any)[Symbol.for('radix-ui')] = true;\n }, []);\n\n // DEPRECATED\n if (process.env.NODE_ENV === 'development' && (props as any).as) {\n console.warn(AS_ERROR);\n }\n\n return <Comp {...primitiveProps} ref={forwardedRef} />;\n }),\n }),\n {} as Primitives\n);\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst AS_ERROR = `Warning: The \\`as\\` prop has been removed in favour of \\`asChild\\`. For details, see https://radix-ui.com/docs/primitives/overview/styling#changing-the-rendered-element`;\n\nconst Root = Primitive;\n\nexport {\n Primitive,\n //\n Root,\n};\nexport type { ComponentPropsWithoutRef, PrimitivePropsWithRef };\n"],"names":["React","Slot","NODES","Primitive","reduce","primitive","node","forwardRef","props","forwardedRef","asChild","primitiveProps","Comp","useEffect","window","Symbol","for","process","env","NODE_ENV","as","console","warn","AS_ERROR","Root"],"version":3,"file":"index.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;A;;;;ACIA,MAAMG,2BAAK,GAAG;IACZ,GADY;IAEZ,QAFY;IAGZ,KAHY;IAIZ,IAJY;IAKZ,IALY;IAMZ,KANY;IAOZ,IAPY;IAQZ,KARY;IASZ,IATY;IAUZ,GAVY;IAWZ,MAXY;IAYZ,KAZY;IAaZ,IAbY;CAAd,A,EAgBA,8CAhBA;AAiBA,gEAAA;AACA,kBAAA;AAcA;;oGAEA,CAEA,MAAMC,yCAAS,GAAGD,2BAAK,CAACE,MAAN,CAAa,CAACC,SAAD,EAAYC,IAAZ,GAAqB;IAClD,MAAMC,IAAI,GAAA,aAAGR,CAAAA,uBAAA,CAAiB,CAACU,KAAD,EAA4CC,YAA5C,GAAkE;QAC9F,MAAM,E,SAAEC,OAAF,CAAA,EAAW,GAAGC,cAAH,EAAX,GAAiCH,KAAvC,AAAM;QACN,MAAMI,IAAS,GAAGF,OAAO,GAAGV,4BAAH,GAAUK,IAAnC,AAAA;QAEAP,sBAAA,CAAgB,IAAM;YACnBgB,MAAD,CAAgBC,MAAM,CAACC,GAAP,CAAW,UAAX,CAAhB,CAAA,GAA0C,IAA1C,CAACF;SADH,EAEG,EAFH,CAAA,CAJ8F,CAQ9F,aAFC;QAOD,OAAA,aAAO,CAAA,0BAAA,CAAC,IAAD,EAAA,2DAAA,CAAA,EAAA,EAAUH,cAAV,EAAP;YAAiC,GAAG,EAAEF,YAAL;SAA1B,CAAA,CAAP,CAAO;KAbI,CAAb,AAcC;IAEDH,IAAI,CAACkB,WAAL,GAAoB,CAAA,UAAA,EAAYnB,IAAK,CAAA,CAArC,CAAAC;IAEA,OAAO;QAAE,GAAGF,SAAL;QAAgB,CAACC,IAAD,CAAA,EAAQC,IAAR;KAAvB,CAAO;CAnBS,EAoBf,EApBe,CAAlB,AAoBC;AAED,oGAAA,CAEA,MAAMiB,8BAAQ,GAAI,CAAA,wKAAA,CAAlB,AAAA;AAEA;;oGAEA,CAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCA,CAEA,SAASE,yCAAT,CAA4DC,MAA5D,EAAiFC,KAAjF,EAA2F;IACzF,IAAID,MAAJ,EAAY3B,yBAAA,CAAmB,IAAM2B,MAAM,CAACG,aAAP,CAAqBF,KAArB,CAAzB;IAAA,CAAZ,CAAA;CACD;AAED,oGAAA,CAEA,MAAMG,yCAAI,GAAG5B,yCAAb,AAAA;;ADjHA","sources":["packages/react/primitive/src/index.ts","packages/react/primitive/src/Primitive.tsx"],"sourcesContent":["export * from './Primitive';\n","import * as React from 'react';\nimport * as ReactDOM from 'react-dom';\nimport { Slot } from '@radix-ui/react-slot';\n\nconst NODES = [\n 'a',\n 'button',\n 'div',\n 'h2',\n 'h3',\n 'img',\n 'li',\n 'nav',\n 'ol',\n 'p',\n 'span',\n 'svg',\n 'ul',\n] as const;\n\n// Temporary while we await merge of this fix:\n// https://github.com/DefinitelyTyped/DefinitelyTyped/pull/55396\n// prettier-ignore\ntype PropsWithoutRef<P> = P extends any ? ('ref' extends keyof P ? Pick<P, Exclude<keyof P, 'ref'>> : P) : P;\ntype ComponentPropsWithoutRef<T extends React.ElementType> = PropsWithoutRef<\n React.ComponentProps<T>\n>;\n\ntype Primitives = { [E in typeof NODES[number]]: PrimitiveForwardRefComponent<E> };\ntype PrimitivePropsWithRef<E extends React.ElementType> = React.ComponentPropsWithRef<E> & {\n asChild?: boolean;\n};\n\ninterface PrimitiveForwardRefComponent<E extends React.ElementType>\n extends React.ForwardRefExoticComponent<PrimitivePropsWithRef<E>> {}\n\n/* -------------------------------------------------------------------------------------------------\n * Primitive\n * -----------------------------------------------------------------------------------------------*/\n\nconst Primitive = NODES.reduce((primitive, node) => {\n const Node = React.forwardRef((props: PrimitivePropsWithRef<typeof node>, forwardedRef: any) => {\n const { asChild, ...primitiveProps } = props;\n const Comp: any = asChild ? Slot : node;\n\n React.useEffect(() => {\n (window as any)[Symbol.for('radix-ui')] = true;\n }, []);\n\n // DEPRECATED\n if (process.env.NODE_ENV === 'development' && (props as any).as) {\n console.warn(AS_ERROR);\n }\n\n return <Comp {...primitiveProps} ref={forwardedRef} />;\n });\n\n Node.displayName = `Primitive.${node}`;\n\n return { ...primitive, [node]: Node };\n}, {} as Primitives);\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst AS_ERROR = `Warning: The \\`as\\` prop has been removed in favour of \\`asChild\\`. For details, see https://radix-ui.com/docs/primitives/overview/styling#changing-the-rendered-element`;\n\n/* -------------------------------------------------------------------------------------------------\n * Utils\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * Flush custom event dispatch\n * https://github.com/radix-ui/primitives/pull/1378\n *\n * React batches *all* event handlers since version 18, this introduces certain considerations when using custom event types.\n *\n * Internally, React prioritises events in the following order:\n * - discrete\n * - continuous\n * - default\n *\n * https://github.com/facebook/react/blob/a8a4742f1c54493df00da648a3f9d26e3db9c8b5/packages/react-dom/src/events/ReactDOMEventListener.js#L294-L350\n *\n * `discrete` is an important distinction as updates within these events are applied immediately.\n * React however, is not able to infer the priority of custom event types due to how they are detected internally.\n * Because of this, it's possible for updates from custom events to be unexpectedly batched when\n * dispatched by another `discrete` event.\n *\n * In order to ensure that updates from custom events are applied predictably, we need to manually flush the batch.\n * This utility should be used when dispatching a custom event from within another `discrete` event, this utility\n * is not nessesary when dispatching known event types, or if dispatching a custom type inside a non-discrete event.\n * For example:\n *\n * dispatching a known click 👎\n * target.dispatchEvent(new Event(‘click’))\n *\n * dispatching a custom type within a non-discrete event 👎\n * onScroll={(event) => event.target.dispatchEvent(new CustomEvent(‘customType’))}\n *\n * dispatching a custom type within a `discrete` event 👍\n * onPointerDown={(event) => dispatchDiscreteCustomEvent(event.target, new CustomEvent(‘customType’))}\n *\n * Note: though React classifies `focus`, `focusin` and `focusout` events as `discrete`, it's not recommended to use\n * this utility with them. This is because it's possible for those handlers to be called implicitly during render\n * e.g. when focus is within a component as it is unmounted, or when managing focus on mount.\n */\n\nfunction dispatchDiscreteCustomEvent<E extends CustomEvent>(target: E['target'], event: E) {\n if (target) ReactDOM.flushSync(() => target.dispatchEvent(event));\n}\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst Root = Primitive;\n\nexport {\n Primitive,\n //\n Root,\n //\n dispatchDiscreteCustomEvent,\n};\nexport type { ComponentPropsWithoutRef, PrimitivePropsWithRef };\n"],"names":["React","ReactDOM","Slot","NODES","Primitive","reduce","primitive","node","Node","forwardRef","props","forwardedRef","asChild","primitiveProps","Comp","useEffect","window","Symbol","for","process","env","NODE_ENV","as","console","warn","AS_ERROR","displayName","dispatchDiscreteCustomEvent","target","event","flushSync","dispatchEvent","Root"],"version":3,"file":"index.js.map"}
@@ -1,5 +1,6 @@
1
1
  import $4q5Fq$babelruntimehelpersesmextends from "@babel/runtime/helpers/esm/extends";
2
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";
3
4
  import {Slot as $4q5Fq$Slot} from "@radix-ui/react-slot";
4
5
 
5
6
  function $parcel$export(e, n, v, s) {
@@ -8,10 +9,12 @@ function $parcel$export(e, n, v, s) {
8
9
  var $8927f6f2acc4f386$exports = {};
9
10
 
10
11
  $parcel$export($8927f6f2acc4f386$exports, "Primitive", () => $8927f6f2acc4f386$export$250ffa63cdc0d034);
12
+ $parcel$export($8927f6f2acc4f386$exports, "dispatchDiscreteCustomEvent", () => $8927f6f2acc4f386$export$6d1a0317bde7de7f);
11
13
  $parcel$export($8927f6f2acc4f386$exports, "Root", () => $8927f6f2acc4f386$export$be92b6f5f03c0fe9);
12
14
 
13
15
 
14
16
 
17
+
15
18
  const $8927f6f2acc4f386$var$NODES = [
16
19
  'a',
17
20
  'button',
@@ -31,25 +34,69 @@ const $8927f6f2acc4f386$var$NODES = [
31
34
  // prettier-ignore
32
35
  /* -------------------------------------------------------------------------------------------------
33
36
  * Primitive
34
- * -----------------------------------------------------------------------------------------------*/ const $8927f6f2acc4f386$export$250ffa63cdc0d034 = $8927f6f2acc4f386$var$NODES.reduce((primitive, node)=>({
37
+ * -----------------------------------------------------------------------------------------------*/ const $8927f6f2acc4f386$export$250ffa63cdc0d034 = $8927f6f2acc4f386$var$NODES.reduce((primitive, node)=>{
38
+ const Node = /*#__PURE__*/ $4q5Fq$forwardRef((props, forwardedRef)=>{
39
+ const { asChild: asChild , ...primitiveProps } = props;
40
+ const Comp = asChild ? $4q5Fq$Slot : node;
41
+ $4q5Fq$useEffect(()=>{
42
+ window[Symbol.for('radix-ui')] = true;
43
+ }, []); // DEPRECATED
44
+ return /*#__PURE__*/ $4q5Fq$createElement(Comp, $4q5Fq$babelruntimehelpersesmextends({}, primitiveProps, {
45
+ ref: forwardedRef
46
+ }));
47
+ });
48
+ Node.displayName = `Primitive.${node}`;
49
+ return {
35
50
  ...primitive,
36
- [node]: /*#__PURE__*/ $4q5Fq$forwardRef((props, forwardedRef)=>{
37
- const { asChild: asChild , ...primitiveProps } = props;
38
- const Comp = asChild ? $4q5Fq$Slot : node;
39
- $4q5Fq$useEffect(()=>{
40
- window[Symbol.for('radix-ui')] = true;
41
- }, []); // DEPRECATED
42
- return /*#__PURE__*/ $4q5Fq$createElement(Comp, $4q5Fq$babelruntimehelpersesmextends({}, primitiveProps, {
43
- ref: forwardedRef
44
- }));
45
- })
46
- })
47
- , {});
51
+ [node]: Node
52
+ };
53
+ }, {});
48
54
  /* -----------------------------------------------------------------------------------------------*/ const $8927f6f2acc4f386$var$AS_ERROR = `Warning: The \`as\` prop has been removed in favour of \`asChild\`. For details, see https://radix-ui.com/docs/primitives/overview/styling#changing-the-rendered-element`;
49
- const $8927f6f2acc4f386$export$be92b6f5f03c0fe9 = $8927f6f2acc4f386$export$250ffa63cdc0d034;
55
+ /* -------------------------------------------------------------------------------------------------
56
+ * Utils
57
+ * -----------------------------------------------------------------------------------------------*/ /**
58
+ * Flush custom event dispatch
59
+ * https://github.com/radix-ui/primitives/pull/1378
60
+ *
61
+ * React batches *all* event handlers since version 18, this introduces certain considerations when using custom event types.
62
+ *
63
+ * Internally, React prioritises events in the following order:
64
+ * - discrete
65
+ * - continuous
66
+ * - default
67
+ *
68
+ * https://github.com/facebook/react/blob/a8a4742f1c54493df00da648a3f9d26e3db9c8b5/packages/react-dom/src/events/ReactDOMEventListener.js#L294-L350
69
+ *
70
+ * `discrete` is an important distinction as updates within these events are applied immediately.
71
+ * React however, is not able to infer the priority of custom event types due to how they are detected internally.
72
+ * Because of this, it's possible for updates from custom events to be unexpectedly batched when
73
+ * dispatched by another `discrete` event.
74
+ *
75
+ * In order to ensure that updates from custom events are applied predictably, we need to manually flush the batch.
76
+ * This utility should be used when dispatching a custom event from within another `discrete` event, this utility
77
+ * is not nessesary when dispatching known event types, or if dispatching a custom type inside a non-discrete event.
78
+ * For example:
79
+ *
80
+ * dispatching a known click 👎
81
+ * target.dispatchEvent(new Event(‘click’))
82
+ *
83
+ * dispatching a custom type within a non-discrete event 👎
84
+ * onScroll={(event) => event.target.dispatchEvent(new CustomEvent(‘customType’))}
85
+ *
86
+ * dispatching a custom type within a `discrete` event 👍
87
+ * onPointerDown={(event) => dispatchDiscreteCustomEvent(event.target, new CustomEvent(‘customType’))}
88
+ *
89
+ * Note: though React classifies `focus`, `focusin` and `focusout` events as `discrete`, it's not recommended to use
90
+ * this utility with them. This is because it's possible for those handlers to be called implicitly during render
91
+ * e.g. when focus is within a component as it is unmounted, or when managing focus on mount.
92
+ */ function $8927f6f2acc4f386$export$6d1a0317bde7de7f(target, event) {
93
+ if (target) $4q5Fq$flushSync(()=>target.dispatchEvent(event)
94
+ );
95
+ }
96
+ /* -----------------------------------------------------------------------------------------------*/ const $8927f6f2acc4f386$export$be92b6f5f03c0fe9 = $8927f6f2acc4f386$export$250ffa63cdc0d034;
50
97
 
51
98
 
52
99
 
53
100
 
54
- export {$8927f6f2acc4f386$export$250ffa63cdc0d034 as Primitive, $8927f6f2acc4f386$export$be92b6f5f03c0fe9 as Root};
101
+ export {$8927f6f2acc4f386$export$250ffa63cdc0d034 as Primitive, $8927f6f2acc4f386$export$6d1a0317bde7de7f as dispatchDiscreteCustomEvent, $8927f6f2acc4f386$export$be92b6f5f03c0fe9 as Root};
55
102
  //# sourceMappingURL=index.module.js.map
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;A;;;ACGA,MAAME,2BAAK,GAAG;IACZ,GADY;IAEZ,QAFY;IAGZ,KAHY;IAIZ,IAJY;IAKZ,IALY;IAMZ,KANY;IAOZ,IAPY;IAQZ,KARY;IASZ,IATY;IAUZ,GAVY;IAWZ,MAXY;IAYZ,KAZY;IAaZ,IAbY;CAAd,A,EAgBA,8CAhBA;AAiBA,gEAAA;AACA,kBAAA;AAcA;;oGAEA,CAEA,MAAMC,yCAAS,GAAGD,2BAAK,CAACE,MAAN,CAChB,CAACC,SAAD,EAAYC,IAAZ,GAAsB,CAAA;QACpB,GAAGD,SADiB;QAEpB,CAACC,IAAD,CAAA,EAAA,aAAQN,CAAAA,iBAAA,CAAiB,CAACQ,KAAD,EAA4CC,YAA5C,GAAkE;YACzF,MAAM,E,SAAEC,OAAF,CAAA,EAAW,GAAGC,cAAH,EAAX,GAAiCH,KAAvC,AAAM;YACN,MAAMI,IAAS,GAAGF,OAAO,GAAGT,WAAH,GAAUK,IAAnC,AAAA;YAEAN,gBAAA,CAAgB,IAAM;gBACnBc,MAAD,CAAgBC,MAAM,CAACC,GAAP,CAAW,UAAX,CAAhB,CAAA,GAA0C,IAA1C,CAACF;aADH,EAEG,EAFH,CAAA,CAJyF,CAQzF,aAFC;YAOD,OAAA,aAAO,CAAA,oBAAA,CAAC,IAAD,EAAA,oCAAA,CAAA,EAAA,EAAUH,cAAV,EAAP;gBAAiC,GAAG,EAAEF,YAAL;aAA1B,CAAA,CAAP,CAAO;SAbD,CAcP;KAhBH,CAAA;AADgB,EAmBhB,EAnBgB,CAAlB,AACwB;AAqBxB,oGAAA,CAEA,MAAMc,8BAAQ,GAAI,CAAA,wKAAA,CAAlB,AAAA;AAEA,MAAMC,yCAAI,GAAGrB,yCAAb,AAAA;;ADjEA","sources":["packages/react/primitive/src/index.ts","packages/react/primitive/src/Primitive.tsx"],"sourcesContent":["export * from './Primitive';\n","import * as React from 'react';\nimport { Slot } from '@radix-ui/react-slot';\n\nconst NODES = [\n 'a',\n 'button',\n 'div',\n 'h2',\n 'h3',\n 'img',\n 'li',\n 'nav',\n 'ol',\n 'p',\n 'span',\n 'svg',\n 'ul',\n] as const;\n\n// Temporary while we await merge of this fix:\n// https://github.com/DefinitelyTyped/DefinitelyTyped/pull/55396\n// prettier-ignore\ntype PropsWithoutRef<P> = P extends any ? ('ref' extends keyof P ? Pick<P, Exclude<keyof P, 'ref'>> : P) : P;\ntype ComponentPropsWithoutRef<T extends React.ElementType> = PropsWithoutRef<\n React.ComponentProps<T>\n>;\n\ntype Primitives = { [E in typeof NODES[number]]: PrimitiveForwardRefComponent<E> };\ntype PrimitivePropsWithRef<E extends React.ElementType> = React.ComponentPropsWithRef<E> & {\n asChild?: boolean;\n};\n\ninterface PrimitiveForwardRefComponent<E extends React.ElementType>\n extends React.ForwardRefExoticComponent<PrimitivePropsWithRef<E>> {}\n\n/* -------------------------------------------------------------------------------------------------\n * Primitive\n * -----------------------------------------------------------------------------------------------*/\n\nconst Primitive = NODES.reduce(\n (primitive, node) => ({\n ...primitive,\n [node]: React.forwardRef((props: PrimitivePropsWithRef<typeof node>, forwardedRef: any) => {\n const { asChild, ...primitiveProps } = props;\n const Comp: any = asChild ? Slot : node;\n\n React.useEffect(() => {\n (window as any)[Symbol.for('radix-ui')] = true;\n }, []);\n\n // DEPRECATED\n if (process.env.NODE_ENV === 'development' && (props as any).as) {\n console.warn(AS_ERROR);\n }\n\n return <Comp {...primitiveProps} ref={forwardedRef} />;\n }),\n }),\n {} as Primitives\n);\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst AS_ERROR = `Warning: The \\`as\\` prop has been removed in favour of \\`asChild\\`. For details, see https://radix-ui.com/docs/primitives/overview/styling#changing-the-rendered-element`;\n\nconst Root = Primitive;\n\nexport {\n Primitive,\n //\n Root,\n};\nexport type { ComponentPropsWithoutRef, PrimitivePropsWithRef };\n"],"names":["React","Slot","NODES","Primitive","reduce","primitive","node","forwardRef","props","forwardedRef","asChild","primitiveProps","Comp","useEffect","window","Symbol","for","process","env","NODE_ENV","as","console","warn","AS_ERROR","Root"],"version":3,"file":"index.module.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;A;;;;ACIA,MAAMG,2BAAK,GAAG;IACZ,GADY;IAEZ,QAFY;IAGZ,KAHY;IAIZ,IAJY;IAKZ,IALY;IAMZ,KANY;IAOZ,IAPY;IAQZ,KARY;IASZ,IATY;IAUZ,GAVY;IAWZ,MAXY;IAYZ,KAZY;IAaZ,IAbY;CAAd,A,EAgBA,8CAhBA;AAiBA,gEAAA;AACA,kBAAA;AAcA;;oGAEA,CAEA,MAAMC,yCAAS,GAAGD,2BAAK,CAACE,MAAN,CAAa,CAACC,SAAD,EAAYC,IAAZ,GAAqB;IAClD,MAAMC,IAAI,GAAA,aAAGR,CAAAA,iBAAA,CAAiB,CAACU,KAAD,EAA4CC,YAA5C,GAAkE;QAC9F,MAAM,E,SAAEC,OAAF,CAAA,EAAW,GAAGC,cAAH,EAAX,GAAiCH,KAAvC,AAAM;QACN,MAAMI,IAAS,GAAGF,OAAO,GAAGV,WAAH,GAAUK,IAAnC,AAAA;QAEAP,gBAAA,CAAgB,IAAM;YACnBgB,MAAD,CAAgBC,MAAM,CAACC,GAAP,CAAW,UAAX,CAAhB,CAAA,GAA0C,IAA1C,CAACF;SADH,EAEG,EAFH,CAAA,CAJ8F,CAQ9F,aAFC;QAOD,OAAA,aAAO,CAAA,oBAAA,CAAC,IAAD,EAAA,oCAAA,CAAA,EAAA,EAAUH,cAAV,EAAP;YAAiC,GAAG,EAAEF,YAAL;SAA1B,CAAA,CAAP,CAAO;KAbI,CAAb,AAcC;IAEDH,IAAI,CAACkB,WAAL,GAAoB,CAAA,UAAA,EAAYnB,IAAK,CAAA,CAArC,CAAAC;IAEA,OAAO;QAAE,GAAGF,SAAL;QAAgB,CAACC,IAAD,CAAA,EAAQC,IAAR;KAAvB,CAAO;CAnBS,EAoBf,EApBe,CAAlB,AAoBC;AAED,oGAAA,CAEA,MAAMiB,8BAAQ,GAAI,CAAA,wKAAA,CAAlB,AAAA;AAEA;;oGAEA,CAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCA,CAEA,SAASE,yCAAT,CAA4DC,MAA5D,EAAiFC,KAAjF,EAA2F;IACzF,IAAID,MAAJ,EAAY3B,gBAAA,CAAmB,IAAM2B,MAAM,CAACG,aAAP,CAAqBF,KAArB,CAAzB;IAAA,CAAZ,CAAA;CACD;AAED,oGAAA,CAEA,MAAMG,yCAAI,GAAG5B,yCAAb,AAAA;;ADjHA","sources":["packages/react/primitive/src/index.ts","packages/react/primitive/src/Primitive.tsx"],"sourcesContent":["export * from './Primitive';\n","import * as React from 'react';\nimport * as ReactDOM from 'react-dom';\nimport { Slot } from '@radix-ui/react-slot';\n\nconst NODES = [\n 'a',\n 'button',\n 'div',\n 'h2',\n 'h3',\n 'img',\n 'li',\n 'nav',\n 'ol',\n 'p',\n 'span',\n 'svg',\n 'ul',\n] as const;\n\n// Temporary while we await merge of this fix:\n// https://github.com/DefinitelyTyped/DefinitelyTyped/pull/55396\n// prettier-ignore\ntype PropsWithoutRef<P> = P extends any ? ('ref' extends keyof P ? Pick<P, Exclude<keyof P, 'ref'>> : P) : P;\ntype ComponentPropsWithoutRef<T extends React.ElementType> = PropsWithoutRef<\n React.ComponentProps<T>\n>;\n\ntype Primitives = { [E in typeof NODES[number]]: PrimitiveForwardRefComponent<E> };\ntype PrimitivePropsWithRef<E extends React.ElementType> = React.ComponentPropsWithRef<E> & {\n asChild?: boolean;\n};\n\ninterface PrimitiveForwardRefComponent<E extends React.ElementType>\n extends React.ForwardRefExoticComponent<PrimitivePropsWithRef<E>> {}\n\n/* -------------------------------------------------------------------------------------------------\n * Primitive\n * -----------------------------------------------------------------------------------------------*/\n\nconst Primitive = NODES.reduce((primitive, node) => {\n const Node = React.forwardRef((props: PrimitivePropsWithRef<typeof node>, forwardedRef: any) => {\n const { asChild, ...primitiveProps } = props;\n const Comp: any = asChild ? Slot : node;\n\n React.useEffect(() => {\n (window as any)[Symbol.for('radix-ui')] = true;\n }, []);\n\n // DEPRECATED\n if (process.env.NODE_ENV === 'development' && (props as any).as) {\n console.warn(AS_ERROR);\n }\n\n return <Comp {...primitiveProps} ref={forwardedRef} />;\n });\n\n Node.displayName = `Primitive.${node}`;\n\n return { ...primitive, [node]: Node };\n}, {} as Primitives);\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst AS_ERROR = `Warning: The \\`as\\` prop has been removed in favour of \\`asChild\\`. For details, see https://radix-ui.com/docs/primitives/overview/styling#changing-the-rendered-element`;\n\n/* -------------------------------------------------------------------------------------------------\n * Utils\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * Flush custom event dispatch\n * https://github.com/radix-ui/primitives/pull/1378\n *\n * React batches *all* event handlers since version 18, this introduces certain considerations when using custom event types.\n *\n * Internally, React prioritises events in the following order:\n * - discrete\n * - continuous\n * - default\n *\n * https://github.com/facebook/react/blob/a8a4742f1c54493df00da648a3f9d26e3db9c8b5/packages/react-dom/src/events/ReactDOMEventListener.js#L294-L350\n *\n * `discrete` is an important distinction as updates within these events are applied immediately.\n * React however, is not able to infer the priority of custom event types due to how they are detected internally.\n * Because of this, it's possible for updates from custom events to be unexpectedly batched when\n * dispatched by another `discrete` event.\n *\n * In order to ensure that updates from custom events are applied predictably, we need to manually flush the batch.\n * This utility should be used when dispatching a custom event from within another `discrete` event, this utility\n * is not nessesary when dispatching known event types, or if dispatching a custom type inside a non-discrete event.\n * For example:\n *\n * dispatching a known click 👎\n * target.dispatchEvent(new Event(‘click’))\n *\n * dispatching a custom type within a non-discrete event 👎\n * onScroll={(event) => event.target.dispatchEvent(new CustomEvent(‘customType’))}\n *\n * dispatching a custom type within a `discrete` event 👍\n * onPointerDown={(event) => dispatchDiscreteCustomEvent(event.target, new CustomEvent(‘customType’))}\n *\n * Note: though React classifies `focus`, `focusin` and `focusout` events as `discrete`, it's not recommended to use\n * this utility with them. This is because it's possible for those handlers to be called implicitly during render\n * e.g. when focus is within a component as it is unmounted, or when managing focus on mount.\n */\n\nfunction dispatchDiscreteCustomEvent<E extends CustomEvent>(target: E['target'], event: E) {\n if (target) ReactDOM.flushSync(() => target.dispatchEvent(event));\n}\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst Root = Primitive;\n\nexport {\n Primitive,\n //\n Root,\n //\n dispatchDiscreteCustomEvent,\n};\nexport type { ComponentPropsWithoutRef, PrimitivePropsWithRef };\n"],"names":["React","ReactDOM","Slot","NODES","Primitive","reduce","primitive","node","Node","forwardRef","props","forwardedRef","asChild","primitiveProps","Comp","useEffect","window","Symbol","for","process","env","NODE_ENV","as","console","warn","AS_ERROR","displayName","dispatchDiscreteCustomEvent","target","event","flushSync","dispatchEvent","Root"],"version":3,"file":"index.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radix-ui/react-primitive",
3
- "version": "0.1.5-rc.3",
3
+ "version": "0.1.5-rc.32",
4
4
  "license": "MIT",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -17,13 +17,14 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@babel/runtime": "^7.13.10",
20
- "@radix-ui/react-slot": "0.1.3-rc.3"
20
+ "@radix-ui/react-slot": "0.1.3-rc.32"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@testing-library/react": "^10.4.8"
24
24
  },
25
25
  "peerDependencies": {
26
- "react": "^16.8 || ^17.0 || ^18.0"
26
+ "react": "^16.8 || ^17.0 || ^18.0",
27
+ "react-dom": "^16.8 || ^17.0 || ^18.0"
27
28
  },
28
29
  "homepage": "https://radix-ui.com/primitives",
29
30
  "repository": {