@radix-ui/react-primitive 1.0.3-rc.9 → 1.1.0-rc.1
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.mts +10 -9
- package/dist/index.d.ts +10 -9
- package/dist/index.js +68 -101
- package/dist/index.js.map +7 -1
- package/dist/index.mjs +42 -93
- package/dist/index.mjs.map +7 -1
- package/package.json +3 -4
- package/dist/index.d.ts.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import * as React from
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
2
3
|
declare const NODES: readonly ["a", "button", "div", "form", "h2", "h3", "img", "input", "label", "li", "nav", "ol", "p", "span", "svg", "ul"];
|
|
3
|
-
type PropsWithoutRef<P> = P extends any ? ('ref' extends keyof P ? Pick<P, Exclude<keyof P, 'ref'>> : P) : P;
|
|
4
|
-
|
|
5
|
-
type Primitives = {
|
|
4
|
+
declare type PropsWithoutRef<P> = P extends any ? ('ref' extends keyof P ? Pick<P, Exclude<keyof P, 'ref'>> : P) : P;
|
|
5
|
+
declare type ComponentPropsWithoutRef<T extends React.ElementType> = PropsWithoutRef<React.ComponentProps<T>>;
|
|
6
|
+
declare type Primitives = {
|
|
6
7
|
[E in typeof NODES[number]]: PrimitiveForwardRefComponent<E>;
|
|
7
8
|
};
|
|
8
|
-
|
|
9
|
+
declare type PrimitivePropsWithRef<E extends React.ElementType> = React.ComponentPropsWithRef<E> & {
|
|
9
10
|
asChild?: boolean;
|
|
10
11
|
};
|
|
11
12
|
interface PrimitiveForwardRefComponent<E extends React.ElementType> extends React.ForwardRefExoticComponent<PrimitivePropsWithRef<E>> {
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
+
declare const Primitive: Primitives;
|
|
14
15
|
/**
|
|
15
16
|
* Flush custom event dispatch
|
|
16
17
|
* https://github.com/radix-ui/primitives/pull/1378
|
|
@@ -47,7 +48,7 @@ export const Primitive: Primitives;
|
|
|
47
48
|
* this utility with them. This is because it's possible for those handlers to be called implicitly during render
|
|
48
49
|
* e.g. when focus is within a component as it is unmounted, or when managing focus on mount.
|
|
49
50
|
*/
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
declare function dispatchDiscreteCustomEvent<E extends CustomEvent>(target: E['target'], event: E): void;
|
|
52
|
+
declare const Root: Primitives;
|
|
52
53
|
|
|
53
|
-
|
|
54
|
+
export { type ComponentPropsWithoutRef, Primitive, type PrimitivePropsWithRef, Root, dispatchDiscreteCustomEvent };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import * as React from
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
2
3
|
declare const NODES: readonly ["a", "button", "div", "form", "h2", "h3", "img", "input", "label", "li", "nav", "ol", "p", "span", "svg", "ul"];
|
|
3
|
-
type PropsWithoutRef<P> = P extends any ? ('ref' extends keyof P ? Pick<P, Exclude<keyof P, 'ref'>> : P) : P;
|
|
4
|
-
|
|
5
|
-
type Primitives = {
|
|
4
|
+
declare type PropsWithoutRef<P> = P extends any ? ('ref' extends keyof P ? Pick<P, Exclude<keyof P, 'ref'>> : P) : P;
|
|
5
|
+
declare type ComponentPropsWithoutRef<T extends React.ElementType> = PropsWithoutRef<React.ComponentProps<T>>;
|
|
6
|
+
declare type Primitives = {
|
|
6
7
|
[E in typeof NODES[number]]: PrimitiveForwardRefComponent<E>;
|
|
7
8
|
};
|
|
8
|
-
|
|
9
|
+
declare type PrimitivePropsWithRef<E extends React.ElementType> = React.ComponentPropsWithRef<E> & {
|
|
9
10
|
asChild?: boolean;
|
|
10
11
|
};
|
|
11
12
|
interface PrimitiveForwardRefComponent<E extends React.ElementType> extends React.ForwardRefExoticComponent<PrimitivePropsWithRef<E>> {
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
+
declare const Primitive: Primitives;
|
|
14
15
|
/**
|
|
15
16
|
* Flush custom event dispatch
|
|
16
17
|
* https://github.com/radix-ui/primitives/pull/1378
|
|
@@ -47,7 +48,7 @@ export const Primitive: Primitives;
|
|
|
47
48
|
* this utility with them. This is because it's possible for those handlers to be called implicitly during render
|
|
48
49
|
* e.g. when focus is within a component as it is unmounted, or when managing focus on mount.
|
|
49
50
|
*/
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
declare function dispatchDiscreteCustomEvent<E extends CustomEvent>(target: E['target'], event: E): void;
|
|
52
|
+
declare const Root: Primitives;
|
|
52
53
|
|
|
53
|
-
|
|
54
|
+
export { type ComponentPropsWithoutRef, Primitive, type PrimitivePropsWithRef, Root, dispatchDiscreteCustomEvent };
|
package/dist/index.js
CHANGED
|
@@ -1,105 +1,72 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
1
|
+
"use strict";
|
|
2
|
+
(() => {
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
10
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
11
|
+
}) : x)(function(x) {
|
|
12
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
13
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
14
|
+
});
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
5
31
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
]; // Temporary while we await merge of this fix:
|
|
38
|
-
// https://github.com/DefinitelyTyped/DefinitelyTyped/pull/55396
|
|
39
|
-
// prettier-ignore
|
|
40
|
-
/* -------------------------------------------------------------------------------------------------
|
|
41
|
-
* Primitive
|
|
42
|
-
* -----------------------------------------------------------------------------------------------*/ const $c3def6332c2749a6$export$250ffa63cdc0d034 = $c3def6332c2749a6$var$NODES.reduce((primitive, node)=>{
|
|
43
|
-
const Node = /*#__PURE__*/ $iMixA$react.forwardRef((props, forwardedRef)=>{
|
|
44
|
-
const { asChild: asChild , ...primitiveProps } = props;
|
|
45
|
-
const Comp = asChild ? $iMixA$radixuireactslot.Slot : node;
|
|
46
|
-
$iMixA$react.useEffect(()=>{
|
|
47
|
-
window[Symbol.for('radix-ui')] = true;
|
|
48
|
-
}, []);
|
|
49
|
-
return /*#__PURE__*/ $iMixA$react.createElement(Comp, ($parcel$interopDefault($iMixA$babelruntimehelpersextends))({}, primitiveProps, {
|
|
50
|
-
ref: forwardedRef
|
|
51
|
-
}));
|
|
32
|
+
// packages/react/primitive/src/Primitive.tsx
|
|
33
|
+
var React = __toESM(__require("react"));
|
|
34
|
+
var ReactDOM = __toESM(__require("react-dom"));
|
|
35
|
+
var import_react_slot = __require("@radix-ui/react-slot");
|
|
36
|
+
var import_jsx_runtime = __require("react/jsx-runtime");
|
|
37
|
+
var NODES = [
|
|
38
|
+
"a",
|
|
39
|
+
"button",
|
|
40
|
+
"div",
|
|
41
|
+
"form",
|
|
42
|
+
"h2",
|
|
43
|
+
"h3",
|
|
44
|
+
"img",
|
|
45
|
+
"input",
|
|
46
|
+
"label",
|
|
47
|
+
"li",
|
|
48
|
+
"nav",
|
|
49
|
+
"ol",
|
|
50
|
+
"p",
|
|
51
|
+
"span",
|
|
52
|
+
"svg",
|
|
53
|
+
"ul"
|
|
54
|
+
];
|
|
55
|
+
var Primitive = NODES.reduce((primitive, node) => {
|
|
56
|
+
const Node = React.forwardRef((props, forwardedRef) => {
|
|
57
|
+
const { asChild, ...primitiveProps } = props;
|
|
58
|
+
const Comp = asChild ? import_react_slot.Slot : node;
|
|
59
|
+
React.useEffect(() => {
|
|
60
|
+
window[Symbol.for("radix-ui")] = true;
|
|
61
|
+
}, []);
|
|
62
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Comp, { ...primitiveProps, ref: forwardedRef });
|
|
52
63
|
});
|
|
53
64
|
Node.displayName = `Primitive.${node}`;
|
|
54
|
-
return {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
* -----------------------------------------------------------------------------------------------*/ /**
|
|
62
|
-
* Flush custom event dispatch
|
|
63
|
-
* https://github.com/radix-ui/primitives/pull/1378
|
|
64
|
-
*
|
|
65
|
-
* React batches *all* event handlers since version 18, this introduces certain considerations when using custom event types.
|
|
66
|
-
*
|
|
67
|
-
* Internally, React prioritises events in the following order:
|
|
68
|
-
* - discrete
|
|
69
|
-
* - continuous
|
|
70
|
-
* - default
|
|
71
|
-
*
|
|
72
|
-
* https://github.com/facebook/react/blob/a8a4742f1c54493df00da648a3f9d26e3db9c8b5/packages/react-dom/src/events/ReactDOMEventListener.js#L294-L350
|
|
73
|
-
*
|
|
74
|
-
* `discrete` is an important distinction as updates within these events are applied immediately.
|
|
75
|
-
* React however, is not able to infer the priority of custom event types due to how they are detected internally.
|
|
76
|
-
* Because of this, it's possible for updates from custom events to be unexpectedly batched when
|
|
77
|
-
* dispatched by another `discrete` event.
|
|
78
|
-
*
|
|
79
|
-
* In order to ensure that updates from custom events are applied predictably, we need to manually flush the batch.
|
|
80
|
-
* This utility should be used when dispatching a custom event from within another `discrete` event, this utility
|
|
81
|
-
* is not nessesary when dispatching known event types, or if dispatching a custom type inside a non-discrete event.
|
|
82
|
-
* For example:
|
|
83
|
-
*
|
|
84
|
-
* dispatching a known click 👎
|
|
85
|
-
* target.dispatchEvent(new Event(‘click’))
|
|
86
|
-
*
|
|
87
|
-
* dispatching a custom type within a non-discrete event 👎
|
|
88
|
-
* onScroll={(event) => event.target.dispatchEvent(new CustomEvent(‘customType’))}
|
|
89
|
-
*
|
|
90
|
-
* dispatching a custom type within a `discrete` event 👍
|
|
91
|
-
* onPointerDown={(event) => dispatchDiscreteCustomEvent(event.target, new CustomEvent(‘customType’))}
|
|
92
|
-
*
|
|
93
|
-
* Note: though React classifies `focus`, `focusin` and `focusout` events as `discrete`, it's not recommended to use
|
|
94
|
-
* this utility with them. This is because it's possible for those handlers to be called implicitly during render
|
|
95
|
-
* e.g. when focus is within a component as it is unmounted, or when managing focus on mount.
|
|
96
|
-
*/ function $c3def6332c2749a6$export$6d1a0317bde7de7f(target, event) {
|
|
97
|
-
if (target) $iMixA$reactdom.flushSync(()=>target.dispatchEvent(event)
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
/* -----------------------------------------------------------------------------------------------*/ const $c3def6332c2749a6$export$be92b6f5f03c0fe9 = $c3def6332c2749a6$export$250ffa63cdc0d034;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
65
|
+
return { ...primitive, [node]: Node };
|
|
66
|
+
}, {});
|
|
67
|
+
function dispatchDiscreteCustomEvent(target, event) {
|
|
68
|
+
if (target) ReactDOM.flushSync(() => target.dispatchEvent(event));
|
|
69
|
+
}
|
|
70
|
+
var Root = Primitive;
|
|
71
|
+
})();
|
|
105
72
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/Primitive.tsx"],
|
|
4
|
+
"sourcesContent": ["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 'form',\n 'h2',\n 'h3',\n 'img',\n 'input',\n 'label',\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 return <Comp {...primitiveProps} ref={forwardedRef} />;\n });\n\n Node.displayName = `Primitive.${node}`;\n\n return { ...primitive, [node]: Node };\n}, {} as Primitives);\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 \uD83D\uDC4E\n * target.dispatchEvent(new Event(\u2018click\u2019))\n *\n * dispatching a custom type within a non-discrete event \uD83D\uDC4E\n * onScroll={(event) => event.target.dispatchEvent(new CustomEvent(\u2018customType\u2019))}\n *\n * dispatching a custom type within a `discrete` event \uD83D\uDC4D\n * onPointerDown={(event) => dispatchDiscreteCustomEvent(event.target, new CustomEvent(\u2018customType\u2019))}\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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,cAAuB;AACvB,iBAA0B;AAC1B,0BAAqB;AAkDV;AAhDX,MAAM,QAAQ;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAsBA,MAAM,YAAY,MAAM,OAAO,CAAC,WAAW,SAAS;AAClD,UAAM,OAAa,iBAAW,CAAC,OAA2C,iBAAsB;AAC9F,YAAM,EAAE,SAAS,GAAG,eAAe,IAAI;AACvC,YAAM,OAAY,UAAU,yBAAO;AAEnC,MAAM,gBAAU,MAAM;AACpB,QAAC,OAAe,OAAO,IAAI,UAAU,CAAC,IAAI;AAAA,MAC5C,GAAG,CAAC,CAAC;AAEL,aAAO,4CAAC,QAAM,GAAG,gBAAgB,KAAK,cAAc;AAAA,IACtD,CAAC;AAED,SAAK,cAAc,aAAa,IAAI;AAEpC,WAAO,EAAE,GAAG,WAAW,CAAC,IAAI,GAAG,KAAK;AAAA,EACtC,GAAG,CAAC,CAAe;AA2CnB,WAAS,4BAAmD,QAAqB,OAAU;AACzF,QAAI,OAAQ,CAAS,mBAAU,MAAM,OAAO,cAAc,KAAK,CAAC;AAAA,EAClE;AAIA,MAAM,OAAO;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,96 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {Slot
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const Comp = asChild ? $4q5Fq$Slot : node;
|
|
36
|
-
$4q5Fq$useEffect(()=>{
|
|
37
|
-
window[Symbol.for('radix-ui')] = true;
|
|
38
|
-
}, []);
|
|
39
|
-
return /*#__PURE__*/ $4q5Fq$createElement(Comp, $4q5Fq$babelruntimehelpersesmextends({}, primitiveProps, {
|
|
40
|
-
ref: forwardedRef
|
|
41
|
-
}));
|
|
42
|
-
});
|
|
43
|
-
Node.displayName = `Primitive.${node}`;
|
|
44
|
-
return {
|
|
45
|
-
...primitive,
|
|
46
|
-
[node]: Node
|
|
47
|
-
};
|
|
1
|
+
// packages/react/primitive/src/Primitive.tsx
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import * as ReactDOM from "react-dom";
|
|
4
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
var NODES = [
|
|
7
|
+
"a",
|
|
8
|
+
"button",
|
|
9
|
+
"div",
|
|
10
|
+
"form",
|
|
11
|
+
"h2",
|
|
12
|
+
"h3",
|
|
13
|
+
"img",
|
|
14
|
+
"input",
|
|
15
|
+
"label",
|
|
16
|
+
"li",
|
|
17
|
+
"nav",
|
|
18
|
+
"ol",
|
|
19
|
+
"p",
|
|
20
|
+
"span",
|
|
21
|
+
"svg",
|
|
22
|
+
"ul"
|
|
23
|
+
];
|
|
24
|
+
var Primitive = NODES.reduce((primitive, node) => {
|
|
25
|
+
const Node = React.forwardRef((props, forwardedRef) => {
|
|
26
|
+
const { asChild, ...primitiveProps } = props;
|
|
27
|
+
const Comp = asChild ? Slot : node;
|
|
28
|
+
React.useEffect(() => {
|
|
29
|
+
window[Symbol.for("radix-ui")] = true;
|
|
30
|
+
}, []);
|
|
31
|
+
return /* @__PURE__ */ jsx(Comp, { ...primitiveProps, ref: forwardedRef });
|
|
32
|
+
});
|
|
33
|
+
Node.displayName = `Primitive.${node}`;
|
|
34
|
+
return { ...primitive, [node]: Node };
|
|
48
35
|
}, {});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
* -----------------------------------------------------------------------------------------------*/ /**
|
|
52
|
-
* Flush custom event dispatch
|
|
53
|
-
* https://github.com/radix-ui/primitives/pull/1378
|
|
54
|
-
*
|
|
55
|
-
* React batches *all* event handlers since version 18, this introduces certain considerations when using custom event types.
|
|
56
|
-
*
|
|
57
|
-
* Internally, React prioritises events in the following order:
|
|
58
|
-
* - discrete
|
|
59
|
-
* - continuous
|
|
60
|
-
* - default
|
|
61
|
-
*
|
|
62
|
-
* https://github.com/facebook/react/blob/a8a4742f1c54493df00da648a3f9d26e3db9c8b5/packages/react-dom/src/events/ReactDOMEventListener.js#L294-L350
|
|
63
|
-
*
|
|
64
|
-
* `discrete` is an important distinction as updates within these events are applied immediately.
|
|
65
|
-
* React however, is not able to infer the priority of custom event types due to how they are detected internally.
|
|
66
|
-
* Because of this, it's possible for updates from custom events to be unexpectedly batched when
|
|
67
|
-
* dispatched by another `discrete` event.
|
|
68
|
-
*
|
|
69
|
-
* In order to ensure that updates from custom events are applied predictably, we need to manually flush the batch.
|
|
70
|
-
* This utility should be used when dispatching a custom event from within another `discrete` event, this utility
|
|
71
|
-
* is not nessesary when dispatching known event types, or if dispatching a custom type inside a non-discrete event.
|
|
72
|
-
* For example:
|
|
73
|
-
*
|
|
74
|
-
* dispatching a known click 👎
|
|
75
|
-
* target.dispatchEvent(new Event(‘click’))
|
|
76
|
-
*
|
|
77
|
-
* dispatching a custom type within a non-discrete event 👎
|
|
78
|
-
* onScroll={(event) => event.target.dispatchEvent(new CustomEvent(‘customType’))}
|
|
79
|
-
*
|
|
80
|
-
* dispatching a custom type within a `discrete` event 👍
|
|
81
|
-
* onPointerDown={(event) => dispatchDiscreteCustomEvent(event.target, new CustomEvent(‘customType’))}
|
|
82
|
-
*
|
|
83
|
-
* Note: though React classifies `focus`, `focusin` and `focusout` events as `discrete`, it's not recommended to use
|
|
84
|
-
* this utility with them. This is because it's possible for those handlers to be called implicitly during render
|
|
85
|
-
* e.g. when focus is within a component as it is unmounted, or when managing focus on mount.
|
|
86
|
-
*/ function $8927f6f2acc4f386$export$6d1a0317bde7de7f(target, event) {
|
|
87
|
-
if (target) $4q5Fq$flushSync(()=>target.dispatchEvent(event)
|
|
88
|
-
);
|
|
36
|
+
function dispatchDiscreteCustomEvent(target, event) {
|
|
37
|
+
if (target) ReactDOM.flushSync(() => target.dispatchEvent(event));
|
|
89
38
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
39
|
+
var Root = Primitive;
|
|
40
|
+
export {
|
|
41
|
+
Primitive,
|
|
42
|
+
Root,
|
|
43
|
+
dispatchDiscreteCustomEvent
|
|
44
|
+
};
|
|
96
45
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/Primitive.tsx"],
|
|
4
|
+
"sourcesContent": ["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 'form',\n 'h2',\n 'h3',\n 'img',\n 'input',\n 'label',\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 return <Comp {...primitiveProps} ref={forwardedRef} />;\n });\n\n Node.displayName = `Primitive.${node}`;\n\n return { ...primitive, [node]: Node };\n}, {} as Primitives);\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 \uD83D\uDC4E\n * target.dispatchEvent(new Event(\u2018click\u2019))\n *\n * dispatching a custom type within a non-discrete event \uD83D\uDC4E\n * onScroll={(event) => event.target.dispatchEvent(new CustomEvent(\u2018customType\u2019))}\n *\n * dispatching a custom type within a `discrete` event \uD83D\uDC4D\n * onPointerDown={(event) => dispatchDiscreteCustomEvent(event.target, new CustomEvent(\u2018customType\u2019))}\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"],
|
|
5
|
+
"mappings": ";AAAA,YAAY,WAAW;AACvB,YAAY,cAAc;AAC1B,SAAS,YAAY;AAkDV;AAhDX,IAAM,QAAQ;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAsBA,IAAM,YAAY,MAAM,OAAO,CAAC,WAAW,SAAS;AAClD,QAAM,OAAa,iBAAW,CAAC,OAA2C,iBAAsB;AAC9F,UAAM,EAAE,SAAS,GAAG,eAAe,IAAI;AACvC,UAAM,OAAY,UAAU,OAAO;AAEnC,IAAM,gBAAU,MAAM;AACpB,MAAC,OAAe,OAAO,IAAI,UAAU,CAAC,IAAI;AAAA,IAC5C,GAAG,CAAC,CAAC;AAEL,WAAO,oBAAC,QAAM,GAAG,gBAAgB,KAAK,cAAc;AAAA,EACtD,CAAC;AAED,OAAK,cAAc,aAAa,IAAI;AAEpC,SAAO,EAAE,GAAG,WAAW,CAAC,IAAI,GAAG,KAAK;AACtC,GAAG,CAAC,CAAe;AA2CnB,SAAS,4BAAmD,QAAqB,OAAU;AACzF,MAAI,OAAQ,CAAS,mBAAU,MAAM,OAAO,cAAc,KAAK,CAAC;AAClE;AAIA,IAAM,OAAO;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@radix-ui/react-primitive",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0-rc.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -28,8 +28,7 @@
|
|
|
28
28
|
"version": "yarn version"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@
|
|
32
|
-
"@radix-ui/react-slot": "1.0.2-rc.9"
|
|
31
|
+
"@radix-ui/react-slot": "1.1.0-rc.1"
|
|
33
32
|
},
|
|
34
33
|
"devDependencies": {
|
|
35
34
|
"@testing-library/react": "^10.4.8"
|
|
@@ -56,5 +55,5 @@
|
|
|
56
55
|
"bugs": {
|
|
57
56
|
"url": "https://github.com/radix-ui/primitives/issues"
|
|
58
57
|
},
|
|
59
|
-
"stableVersion": "1.0.
|
|
58
|
+
"stableVersion": "1.0.3"
|
|
60
59
|
}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";AAIA,QAAA,MAAM,gIAiBI,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,qBAec,CAAC;AAMrB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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 {\n Primitive,\n //\n Root,\n //\n dispatchDiscreteCustomEvent,\n} from './Primitive';\nexport type { ComponentPropsWithoutRef, PrimitivePropsWithRef } from './Primitive';\n"],"names":[],"version":3,"file":"index.d.ts.map"}
|