@sanity/ui 5.0.0-alpha.5 → 5.0.0-alpha.6

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.
@@ -0,0 +1,66 @@
1
+ function isReactEventHandler(key: string, value: unknown): value is (e: never) => void {
2
+ return /^on[A-Z]/.test(key) && typeof value === 'function'
3
+ }
4
+
5
+ function chainEventHandlers<E>(
6
+ ...handlers: (((e: E) => void) | undefined)[]
7
+ ): ((e: E) => void) | undefined {
8
+ const defined = handlers.filter(Boolean) as ((e: E) => void)[]
9
+
10
+ if (defined.length === 0) {
11
+ return undefined
12
+ }
13
+
14
+ if (defined.length === 1) {
15
+ return defined[0]
16
+ }
17
+
18
+ return (e: E) => {
19
+ for (const handler of defined) {
20
+ handler(e)
21
+ }
22
+ }
23
+ }
24
+
25
+ export function mergeTriggerProps(
26
+ childProps: Record<string, unknown>,
27
+ forwardedProps?: Record<string, unknown>,
28
+ ownProps?: Record<string, unknown>,
29
+ ) {
30
+ const result: Record<string, unknown> = {}
31
+
32
+ for (const source of [forwardedProps, ownProps]) {
33
+ if (!source) {
34
+ continue
35
+ }
36
+
37
+ for (const [key, value] of Object.entries(source)) {
38
+ if (key === 'style') {
39
+ continue
40
+ }
41
+
42
+ if (isReactEventHandler(key, value)) {
43
+ result[key] = chainEventHandlers(result[key] as (e: never) => void, value)
44
+ continue
45
+ }
46
+
47
+ if (value !== undefined) {
48
+ result[key] = value
49
+ }
50
+ }
51
+ }
52
+
53
+ result['style'] = {
54
+ ...(childProps['style'] as object),
55
+ ...(forwardedProps?.['style'] as object),
56
+ ...(ownProps?.['style'] as object),
57
+ }
58
+
59
+ for (const [key, value] of Object.entries(childProps)) {
60
+ if (isReactEventHandler(key, value)) {
61
+ result[key] = chainEventHandlers(result[key] as (e: never) => void, value)
62
+ }
63
+ }
64
+
65
+ return result
66
+ }
@@ -0,0 +1,14 @@
1
+ import {type ReactNode} from 'react'
2
+ import {createPortal} from 'react-dom'
3
+
4
+ export function renderPortal(node: ReactNode, mounted: boolean, portal?: boolean) {
5
+ if (!portal) {
6
+ return node
7
+ }
8
+
9
+ if (!mounted) {
10
+ return null
11
+ }
12
+
13
+ return createPortal(node, document.body)
14
+ }
package/src/version.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  // This file is generated by scripts/write-version.js. Do not edit.
2
- export const VERSION = '500alpha5'
3
- export const HASH = '024922'
2
+ export const VERSION = '500alpha6'
3
+ export const HASH = '71d7e5'