|
| 1 | +const fs = require('fs'); |
| 2 | +const path = require('path'); |
| 3 | + |
| 4 | +// Create build/index.d.ts |
| 5 | +const indexDts = `export * from './context-menu'; |
| 6 | +`; |
| 7 | +fs.writeFileSync(path.join(__dirname, '../build/index.d.ts'), indexDts); |
| 8 | + |
| 9 | +// Create build/context-menu/index.d.ts |
| 10 | +const contextMenuIndexDts = `export { |
| 11 | + ContextMenu, |
| 12 | + ContextMenuTrigger, |
| 13 | + ContextMenuContent, |
| 14 | + ContextMenuItem, |
| 15 | + ContextMenuSeparator, |
| 16 | + ContextMenuSubmenu, |
| 17 | + ContextMenuSection, |
| 18 | + ContextMenuContext, |
| 19 | + useContextMenu, |
| 20 | +} from './ContextMenu'; |
| 21 | +
|
| 22 | +export type { |
| 23 | + ContextMenuProps, |
| 24 | + ContextMenuTriggerProps, |
| 25 | + ContextMenuContentProps, |
| 26 | + ContextMenuItemProps, |
| 27 | + ContextMenuSeparatorProps, |
| 28 | + ContextMenuSubmenuProps, |
| 29 | + ContextMenuSectionProps, |
| 30 | +} from './ContextMenu'; |
| 31 | +`; |
| 32 | +fs.writeFileSync(path.join(__dirname, '../build/context-menu/index.d.ts'), contextMenuIndexDts); |
| 33 | + |
| 34 | +// Create build/context-menu/ContextMenu.d.ts |
| 35 | +const contextMenuDts = `import * as React from 'react'; |
| 36 | +import { ViewProps } from 'react-native'; |
| 37 | +
|
| 38 | +type SubmenuIndicatorProp = React.ReactNode | ((isOpen: boolean) => React.ReactNode); |
| 39 | +
|
| 40 | +export type ContextMenuProps = ViewProps & { |
| 41 | + open?: boolean; |
| 42 | + defaultOpen?: boolean; |
| 43 | + onOpenChange?: (open: boolean) => void; |
| 44 | + children: React.ReactNode; |
| 45 | + submenuIndicator?: SubmenuIndicatorProp; |
| 46 | +}; |
| 47 | +
|
| 48 | +export type ContextMenuTriggerProps = ViewProps & { |
| 49 | + children: React.ReactNode; |
| 50 | + disabled?: boolean; |
| 51 | +}; |
| 52 | +
|
| 53 | +export type ContextMenuContentProps = ViewProps & { |
| 54 | + children: React.ReactNode; |
| 55 | + forceMount?: boolean; |
| 56 | +}; |
| 57 | +
|
| 58 | +export type ContextMenuItemProps = ViewProps & { |
| 59 | + disabled?: boolean; |
| 60 | + destructive?: boolean; |
| 61 | + onPress?: () => void; |
| 62 | + icon?: React.ReactNode; |
| 63 | + iosIcon?: string; |
| 64 | + androidIcon?: string; |
| 65 | + children: React.ReactNode; |
| 66 | +}; |
| 67 | +
|
| 68 | +export type ContextMenuSeparatorProps = ViewProps; |
| 69 | +
|
| 70 | +export type ContextMenuSubmenuProps = ViewProps & { |
| 71 | + label: string; |
| 72 | + disabled?: boolean; |
| 73 | + icon?: React.ReactNode; |
| 74 | + iosIcon?: string; |
| 75 | + androidIcon?: string; |
| 76 | + children: React.ReactNode; |
| 77 | +}; |
| 78 | +
|
| 79 | +export type ContextMenuSectionProps = ViewProps & { |
| 80 | + title?: string; |
| 81 | + children: React.ReactNode; |
| 82 | +}; |
| 83 | +
|
| 84 | +type MenuItem = { |
| 85 | + label: string; |
| 86 | + onPress?: () => void; |
| 87 | + destructive?: boolean; |
| 88 | + disabled?: boolean; |
| 89 | + icon?: React.ReactNode; |
| 90 | + iosIcon?: string; |
| 91 | + androidIcon?: string; |
| 92 | + submenu?: MenuItem[]; |
| 93 | + isSeparator?: boolean; |
| 94 | + isSection?: boolean; |
| 95 | + sectionTitle?: string; |
| 96 | +}; |
| 97 | +
|
| 98 | +export const ContextMenuContext: React.Context<{ |
| 99 | + open: boolean; |
| 100 | + onOpenChange: (open: boolean) => void; |
| 101 | + menuItems: MenuItem[]; |
| 102 | + registerMenuItem: (item: MenuItem) => void; |
| 103 | + registerSubmenu: (label: string, items: MenuItem[], icon?: React.ReactNode, iosIcon?: string, androidIcon?: string, disabled?: boolean) => void; |
| 104 | + registerSeparator: () => void; |
| 105 | + registerSection: (title: string, items: MenuItem[]) => void; |
| 106 | + clearMenuItems: () => void; |
| 107 | + isInSubmenu: boolean; |
| 108 | + setIsInSubmenu: (value: boolean) => void; |
| 109 | + itemsToRemoveRef?: React.MutableRefObject<Set<string>>; |
| 110 | + mousePosition?: { x: number; y: number }; |
| 111 | + setMousePosition?: (pos: { x: number; y: number }) => void; |
| 112 | + submenuIndicator?: SubmenuIndicatorProp; |
| 113 | +}>; |
| 114 | +
|
| 115 | +export declare const useContextMenu: () => { |
| 116 | + open: boolean; |
| 117 | + onOpenChange: (open: boolean) => void; |
| 118 | + menuItems: MenuItem[]; |
| 119 | + registerMenuItem: (item: MenuItem) => void; |
| 120 | + registerSubmenu: (label: string, items: MenuItem[], icon?: React.ReactNode, iosIcon?: string, androidIcon?: string, disabled?: boolean) => void; |
| 121 | + registerSeparator: () => void; |
| 122 | + registerSection: (title: string, items: MenuItem[]) => void; |
| 123 | + clearMenuItems: () => void; |
| 124 | + isInSubmenu: boolean; |
| 125 | + setIsInSubmenu: (value: boolean) => void; |
| 126 | + itemsToRemoveRef?: React.MutableRefObject<Set<string>>; |
| 127 | + mousePosition?: { x: number; y: number }; |
| 128 | + setMousePosition?: (pos: { x: number; y: number }) => void; |
| 129 | + submenuIndicator?: SubmenuIndicatorProp; |
| 130 | +}; |
| 131 | +
|
| 132 | +export declare const ContextMenu: React.ForwardRefExoticComponent<ContextMenuProps & React.RefAttributes<any>>; |
| 133 | +export declare const ContextMenuTrigger: React.ForwardRefExoticComponent<ContextMenuTriggerProps & { _menuItems?: MenuItem[], _onOpenChange?: (open: boolean) => void } & React.RefAttributes<any>>; |
| 134 | +export declare const ContextMenuContent: React.ForwardRefExoticComponent<ContextMenuContentProps & React.RefAttributes<any>>; |
| 135 | +export declare const ContextMenuItem: React.ForwardRefExoticComponent<ContextMenuItemProps & React.RefAttributes<any>>; |
| 136 | +export declare const ContextMenuSeparator: React.ForwardRefExoticComponent<ContextMenuSeparatorProps & React.RefAttributes<any>>; |
| 137 | +export declare const ContextMenuSubmenu: React.ForwardRefExoticComponent<ContextMenuSubmenuProps & React.RefAttributes<any>>; |
| 138 | +export declare const ContextMenuSection: React.ForwardRefExoticComponent<ContextMenuSectionProps & React.RefAttributes<any>>; |
| 139 | +`; |
| 140 | +fs.writeFileSync(path.join(__dirname, '../build/context-menu/ContextMenu.d.ts'), contextMenuDts); |
| 141 | + |
| 142 | +console.log('✅ TypeScript declaration files generated successfully'); |
| 143 | + |
0 commit comments