chore(lib): migrate usage of .d.ts to .ts
This commit is contained in:
parent
c61b6136ff
commit
89b9fa7958
9 changed files with 90 additions and 518 deletions
|
|
@ -25,8 +25,8 @@
|
|||
"default": "./src/native/discord.ts"
|
||||
},
|
||||
"./types/*": {
|
||||
"default": "./types/*.d.ts",
|
||||
"types": "./types/*.d.ts"
|
||||
"default": "./types/*.ts",
|
||||
"types": "./types/*.ts"
|
||||
},
|
||||
"./_/metro": {
|
||||
"default": "./src/metro/_internal.ts"
|
||||
|
|
|
|||
511
lib/modules/types/discord.d.ts
vendored
511
lib/modules/types/discord.d.ts
vendored
|
|
@ -1,511 +0,0 @@
|
|||
import type { ComponentProps, ComponentType, FC, JSX, ReactNode } from 'react'
|
||||
import type {
|
||||
ImageProps,
|
||||
ImageSourcePropType,
|
||||
ImageStyle,
|
||||
PressableProps,
|
||||
TextInputProps,
|
||||
TextProps,
|
||||
TextStyle,
|
||||
ViewProps,
|
||||
ViewStyle,
|
||||
} from 'react-native'
|
||||
|
||||
export namespace DiscordModules {
|
||||
export interface ToastActionCreators {
|
||||
open(options: {
|
||||
/**
|
||||
* The unique key for this toast (so they don't stack up)
|
||||
*/
|
||||
key: string
|
||||
/**
|
||||
* The text to display in the toast
|
||||
*/
|
||||
content?: string
|
||||
/**
|
||||
* @deprecated Likely deprecated, use `IconComponent` instead
|
||||
*/
|
||||
icon?: number | FC
|
||||
IconComponent?: FC
|
||||
/**
|
||||
* The icon's color, same string format as `<Text>`'s color prop
|
||||
*/
|
||||
iconColor?: string
|
||||
containerStyle?: ViewStyle
|
||||
})
|
||||
close(): void
|
||||
}
|
||||
|
||||
export interface AlertActionCreators {
|
||||
/**
|
||||
* Opens an alert modal
|
||||
*
|
||||
* @param key The unique key for this alert (so they don't stack up)
|
||||
* @param alert The JSX element to display in the alert. Usually an `AlertModal` component.
|
||||
*/
|
||||
openAlert(key: string, alert: JSX.Element): void
|
||||
dismissAlerts(): void
|
||||
}
|
||||
|
||||
export interface ActionSheetActionCreators {
|
||||
openLazy<T extends ComponentType>(sheet: Promise<{ default: T }>, key: string, props: ComponentProps<T>): void
|
||||
hideActionSheet(key?: string): void
|
||||
}
|
||||
|
||||
export namespace ActionSheet {
|
||||
interface ShowSimpleActionSheetOption {
|
||||
icon?: number
|
||||
label: string
|
||||
isDestructive?: boolean
|
||||
disabled?: boolean
|
||||
onPress?(): void
|
||||
}
|
||||
|
||||
function showSimpleActionSheet(options: {
|
||||
key: string
|
||||
header: {
|
||||
title: string
|
||||
icon?: ReactNode
|
||||
onClose?(): void
|
||||
}
|
||||
options: SimpleActionSheetOption[]
|
||||
}): void
|
||||
}
|
||||
|
||||
export interface FilePickerUtils {
|
||||
handleDocumentSelection(options?: Options): Promise<File[] | undefined>
|
||||
}
|
||||
|
||||
export namespace FilePickerUtils {
|
||||
export type File = {
|
||||
uri: string
|
||||
name: string
|
||||
type: string
|
||||
size: number
|
||||
fileCopyUri: string | null
|
||||
}
|
||||
|
||||
export type Options = {
|
||||
pickMultiple?: boolean
|
||||
}
|
||||
}
|
||||
|
||||
export interface LinkingUtils {
|
||||
/**
|
||||
* Shows an action sheet with options for the given URL
|
||||
* @param options Options for the action sheet
|
||||
*/
|
||||
showLongPressUrlActionSheet(options: {
|
||||
urlString: string
|
||||
guildId: string
|
||||
channelId: string
|
||||
messageId: string
|
||||
}): void
|
||||
/**
|
||||
* Opens a URL
|
||||
* @param url The URL to open
|
||||
* @param options Options for opening the URL
|
||||
* @param options.allowExternal Whether to allow opening external URLs
|
||||
* @param options.forceExternalBrowser Whether to force opening the URL in an external browser
|
||||
*/
|
||||
openURL(url: string, options?: { allowExternal: boolean; forceExternalBrowser: boolean }): void
|
||||
/**
|
||||
* Opens a deep link
|
||||
* @param link The deep link to open
|
||||
*/
|
||||
openDeeplink(link?: string): void
|
||||
}
|
||||
|
||||
export namespace Flux {
|
||||
export type DispatcherPayload = any
|
||||
export type DispatcherDependency = any
|
||||
|
||||
export interface Dispatcher {
|
||||
_actionHandlers: unknown
|
||||
_interceptors?: ((payload: DispatcherPayload) => undefined | boolean)[]
|
||||
_currentDispatchActionType: undefined | string
|
||||
_processingWaitQueue: boolean
|
||||
_subscriptions: Record<string, Set<(payload: DispatcherPayload) => void>>
|
||||
_waitQueue: unknown[]
|
||||
addDependencies(node1: DispatcherDependency, node2: DispatcherDependency): void
|
||||
dispatch(payload: DispatcherPayload): Promise<void>
|
||||
flushWaitQueue(): void
|
||||
isDispatching(): boolean
|
||||
register(
|
||||
name: string,
|
||||
actionHandler: Record<string, (e: DispatcherPayload) => void>,
|
||||
storeDidChange: (e: DispatcherPayload) => boolean,
|
||||
): string
|
||||
setInterceptor(interceptor?: (payload: DispatcherPayload) => undefined | boolean): void
|
||||
/**
|
||||
* Subscribes to an action type
|
||||
* @param actionType The action type to subscribe to
|
||||
* @param callback The callback to call when the action is dispatched
|
||||
*/
|
||||
subscribe(actionType: string, callback: (payload: DispatcherPayload) => void): void
|
||||
/**
|
||||
* Unsubscribes from an action type
|
||||
* @param actionType The action type to unsubscribe from
|
||||
* @param callback The callback to remove
|
||||
*/
|
||||
unsubscribe(actionType: string, callback: (payload: DispatcherPayload) => void): void
|
||||
wait(cb: () => void): void
|
||||
}
|
||||
}
|
||||
|
||||
export type InviteUtils = {
|
||||
__stub?: any
|
||||
}
|
||||
|
||||
export type ClipboardUtils = typeof import('@react-native-clipboard/clipboard').default
|
||||
|
||||
export type MessageUtils = {
|
||||
__stub?: any
|
||||
}
|
||||
|
||||
/**
|
||||
* Discord's logger
|
||||
*
|
||||
* Logs will be shown in the **Debug Logs** section in settings
|
||||
*/
|
||||
export class Logger {
|
||||
static name: string
|
||||
constructor(tag: string)
|
||||
log(...args: unknown[]): void
|
||||
error(...args: unknown[]): void
|
||||
warn(...args: unknown[]): void
|
||||
info(...args: unknown[]): void
|
||||
debug(...args: unknown[]): void
|
||||
time(...args: unknown[]): void
|
||||
trace(...args: unknown[]): void
|
||||
verbose(...args: unknown[]): void
|
||||
}
|
||||
|
||||
export namespace Styles {
|
||||
export type TextType = 'heading' | 'text'
|
||||
export type BasicTextSize = 'sm' | 'md' | 'lg'
|
||||
export type BasicTextSizeWithExtraLarges = BasicTextSize | 'xl' | 'xxl'
|
||||
export type TextSize = BasicTextSizeWithExtraLarges | 'xs' | 'xxs'
|
||||
export type TextWeight = 'normal' | 'medium' | 'semibold' | 'bold'
|
||||
export type TextWeightWithExtraBold = TextWeight | 'extrabold'
|
||||
export type RedesignTextCategory = 'message-preview' | 'channel-title'
|
||||
|
||||
export type TextVariant =
|
||||
| `heading-${BasicTextSizeWithExtraLarges}/${TextWeightWithExtraBold}`
|
||||
| `text-${TextSize}/${TextWeight}`
|
||||
| `display-${BasicTextSize}`
|
||||
| `redesign/${RedesignTextCategory}/${TextWeight}`
|
||||
| 'redesign/heading-18/bold'
|
||||
| 'eyebrow'
|
||||
|
||||
export type TextStyleSheet = Record<TextVariant, TextProps>
|
||||
export type CreateStylesFn = <const S extends Record<string, TextStyle | ViewStyle | ImageStyle>>(
|
||||
styles: S,
|
||||
) => () => S
|
||||
}
|
||||
|
||||
export namespace Components {
|
||||
export type BaseButtonProps = PressableProps & {
|
||||
disabled?: boolean
|
||||
size?: ButtonSize
|
||||
variant?:
|
||||
| 'primary'
|
||||
| 'secondary'
|
||||
| 'tertiary'
|
||||
| 'destructive'
|
||||
| 'active'
|
||||
| 'primary-overlay'
|
||||
| 'secondary-overlay'
|
||||
loading?: boolean
|
||||
grow?: boolean
|
||||
scaleAmountInPx?: number
|
||||
}
|
||||
|
||||
// Buttons
|
||||
export type ButtonSize = 'sm' | 'md' | 'lg'
|
||||
export type Button = FC<
|
||||
BaseButtonProps & {
|
||||
icon?: number
|
||||
loading?: boolean
|
||||
iconPosition?: 'start' | 'end'
|
||||
renderIcon?(): ReactNode
|
||||
renderRightIcon?(): ReactNode
|
||||
renderShine?(): ReactNode
|
||||
renderLinearGradient?(): ReactNode
|
||||
cornerRadius?: number
|
||||
textStyle?: TextStyle
|
||||
loadingColorLight?: string
|
||||
loadingColorDark?: string
|
||||
text: string
|
||||
}
|
||||
>
|
||||
export type TwinButtons = FC
|
||||
export type IconButton = FC<
|
||||
BaseButtonProps & {
|
||||
icon: number
|
||||
label?: string
|
||||
}
|
||||
>
|
||||
export type RowButton = FC
|
||||
export type ImageButton = FC<
|
||||
BaseButtonProps & {
|
||||
image: ImageSourcePropType
|
||||
}
|
||||
>
|
||||
export type FloatingActionButton = FC
|
||||
|
||||
// Layouts
|
||||
export type Stack = FC<
|
||||
ViewProps & {
|
||||
spacing?: number
|
||||
direction?: 'vertical' | 'horizontal'
|
||||
}
|
||||
>
|
||||
export type Card = FC<
|
||||
ViewProps & {
|
||||
start?: boolean
|
||||
end?: boolean
|
||||
variant?: 'primary' | 'secondary'
|
||||
border?: 'faint' | 'normal' | 'strong' | 'subtle'
|
||||
// TODO(modules/types)
|
||||
shadow?: 'none'
|
||||
children: ReactNode
|
||||
}
|
||||
>
|
||||
export type PressableScale = FC
|
||||
|
||||
// Inputs
|
||||
export type TextFieldProps = {
|
||||
onChange?: (value: string) => void
|
||||
onBlur?: () => void
|
||||
onFocus?: () => void
|
||||
|
||||
leadingIcon?: () => JSX.Element
|
||||
trailingIcon?: () => JSX.Element
|
||||
leadingText?: string
|
||||
trailingText?: string
|
||||
description?: string
|
||||
errorMessage?: string
|
||||
|
||||
isDisabled?: boolean
|
||||
focusable?: boolean
|
||||
editable?: boolean
|
||||
status?: TextFieldStatus
|
||||
|
||||
defaultValue?: string
|
||||
value?: string
|
||||
|
||||
placeholder?: string
|
||||
placeholderTextColor?: string
|
||||
|
||||
maxLength?: number
|
||||
multiline?: boolean
|
||||
|
||||
autoFocus?: boolean
|
||||
secureTextEntry?: boolean
|
||||
returnKeyType?: TextInputProps['returnKeyType']
|
||||
isClearable?: boolean
|
||||
|
||||
size?: TextFieldSize
|
||||
style?: ViewStyle | ViewStyle[]
|
||||
}
|
||||
|
||||
export type TextFieldSize = 'sm' | 'md' | 'lg'
|
||||
|
||||
export type TextFieldStatus = 'default' | 'error'
|
||||
|
||||
export type TextInput = FC<
|
||||
TextFieldProps & {
|
||||
isRound?: boolean
|
||||
label?: string
|
||||
}
|
||||
>
|
||||
export type TextField = FC<TextFieldProps>
|
||||
export type TextArea = FC<Omit<ComponentProps<TextInput>, 'multiline'>>
|
||||
export type GhostInput = FC
|
||||
|
||||
// Forms
|
||||
export type FormSwitch = FC<
|
||||
ViewProps & {
|
||||
value: boolean
|
||||
onValueChange(value: boolean): void
|
||||
disabled?: boolean
|
||||
}
|
||||
>
|
||||
export type FormRadio = FC
|
||||
export type FormCheckbox = FC
|
||||
|
||||
// Segmented controls
|
||||
export type SegmentedControl = FC
|
||||
export type SegmentedControlPages = FC
|
||||
export type SegmentedControlStateArgs = {
|
||||
initialSelectedIndex: number
|
||||
onChange: (index: number) => void
|
||||
}
|
||||
export type SegmentedControlState = {
|
||||
selectedIndex: number
|
||||
}
|
||||
|
||||
// Sheets
|
||||
export type ActionSheet = FC<{ children: ReactNode }>
|
||||
export type ActionSheetCloseButton = FC<Pick<ComponentProps<IconButton>, 'variant' | 'onPress'>>
|
||||
export type ActionSheetRow = FC & {
|
||||
Icon: ActionSheetRowIcon
|
||||
Group: ActionSheetRowGroup
|
||||
}
|
||||
export type ActionSheetRowIcon = TableRowIcon
|
||||
export type ActionSheetRowGroup = TableRowGroup
|
||||
export type ActionSheetSwitchRow = TableSwitchRow
|
||||
// export type ActionSheetIconHeader = FC
|
||||
// export type ActionSheetHeaderBar = FC
|
||||
// export type BottomSheetTitleHeader = FC
|
||||
|
||||
export type IconSize =
|
||||
| 'extraSmall10'
|
||||
| 'extraSmall'
|
||||
| 'small'
|
||||
| 'small20'
|
||||
| 'medium'
|
||||
| 'large'
|
||||
| 'custom'
|
||||
| 'refreshSmall16'
|
||||
| 'small14'
|
||||
|
||||
// Tables
|
||||
export type TableRowVariant = 'default' | 'danger'
|
||||
export type TableRowProps = {
|
||||
label: string
|
||||
subLabel?: string
|
||||
icon?: ReactNode
|
||||
trailing?: ReactNode
|
||||
arrow?: boolean
|
||||
onPress?: PressableProps['onPress']
|
||||
disabled?: boolean
|
||||
draggable?: boolean
|
||||
dragHandlePressableProps?: PressableProps
|
||||
labelLineClamp?: number
|
||||
subLabelLineClamp?: number
|
||||
// TODO(modules/types)
|
||||
start?: unknown
|
||||
end?: unknown
|
||||
variant?: TableRowVariant
|
||||
}
|
||||
export type TableRowGroupProps = {
|
||||
title?: string
|
||||
description?: string
|
||||
hasIcons?: boolean
|
||||
accessibilityLabel?: string
|
||||
accessibilityRole?: string
|
||||
children: ReactNode
|
||||
}
|
||||
export type TableRow = FC<TableRowProps> & {
|
||||
Arrow: FC
|
||||
Icon: TableRowIcon
|
||||
}
|
||||
export type TableSwitchRow = FC<
|
||||
Omit<TableRowProps, 'trailing'> & {
|
||||
accessibilityHint?: string
|
||||
value: boolean
|
||||
onValueChange(value: boolean): void
|
||||
}
|
||||
>
|
||||
export type TableRowGroup = FC<TableRowGroupProps>
|
||||
export type TableRowGroupTitle = FC<{
|
||||
title: string
|
||||
}>
|
||||
export type TableRowIconVariant =
|
||||
| 'default'
|
||||
| 'blurple'
|
||||
| 'boosting-pink'
|
||||
| 'status-online'
|
||||
| 'status-idle'
|
||||
| 'status-dnd'
|
||||
| 'status-offline'
|
||||
| 'xbox'
|
||||
| 'playstation'
|
||||
| 'danger'
|
||||
| 'secondary'
|
||||
| 'translucent'
|
||||
export type TableRowIcon = FC<{
|
||||
source: ImageSourcePropType
|
||||
variant?: TableRowIconVariant
|
||||
}>
|
||||
export type TableRadioGroup<T = unknown> = FC<
|
||||
TableRowGroupProps & {
|
||||
onChange(value: T): void
|
||||
}
|
||||
>
|
||||
export type TableCheckboxRow = FC<
|
||||
Omit<TableRowProps, 'trailing'> & {
|
||||
accessibilityHint?: string
|
||||
checked: boolean
|
||||
// TODO(modules/types)
|
||||
onPress: unknown
|
||||
}
|
||||
>
|
||||
export type TableRadioRow<T = unknown> = FC<
|
||||
Omit<TableRowProps, 'trailing'> & {
|
||||
accessibilityHint?: string
|
||||
value: T
|
||||
}
|
||||
>
|
||||
export type TableRowTrailingText = FC<{
|
||||
text: string
|
||||
}>
|
||||
|
||||
// Alerts
|
||||
export type AlertModal = FC<{
|
||||
title: string
|
||||
content?: ReactNode
|
||||
extraContent?: ReactNode
|
||||
actions?: ReactNode
|
||||
}>
|
||||
export type AlertActionButton = Button
|
||||
|
||||
// Menus
|
||||
export type ContextMenu = FC<{
|
||||
title: ReactNode
|
||||
triggerOnLongPress?: boolean
|
||||
items: Array<ContextMenuItem | ContextMenuItem[]>
|
||||
align?: 'left' | 'right' | 'above' | 'below'
|
||||
children: (props: Partial<BaseButtonProps>) => ReactNode
|
||||
}>
|
||||
|
||||
export type ContextMenuItem = {
|
||||
label: string
|
||||
IconComponent?: FC
|
||||
variant?: 'default' | 'destructive'
|
||||
action(): void
|
||||
}
|
||||
|
||||
// Other
|
||||
export type Slider = FC<{
|
||||
value: number
|
||||
step: number
|
||||
minimumValue: number
|
||||
maximumValue: number
|
||||
onValueChange?: (value: number) => void
|
||||
onSlidingStart?: () => void
|
||||
onSlidingComplete?: () => void
|
||||
startIcon?: ReactNode
|
||||
endIcon?: ReactNode
|
||||
}>
|
||||
|
||||
export type Text = FC<
|
||||
TextProps & {
|
||||
variant?: DiscordModules.Styles.TextVariant
|
||||
color?: string
|
||||
style?: TextStyle
|
||||
lineClamp?: number
|
||||
ellipsizeMode?: 'head' | 'middle' | 'tail' | 'clip'
|
||||
tabularNumbers?: boolean
|
||||
children?: ReactNode
|
||||
}
|
||||
>
|
||||
|
||||
export type IntlLink = FC<{
|
||||
target: string
|
||||
children?: ReactNode
|
||||
}>
|
||||
}
|
||||
}
|
||||
85
lib/modules/types/discord.ts
Normal file
85
lib/modules/types/discord.ts
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
export namespace DiscordModules {
|
||||
export namespace Flux {
|
||||
export type DispatcherPayload = any
|
||||
export type DispatcherDependency = any
|
||||
|
||||
export interface StoreChangeCallbacks {
|
||||
add(cb: () => void): void
|
||||
addConditional(cb: () => boolean): void
|
||||
listeners: Set<() => void>
|
||||
remove(cb: () => void): void
|
||||
has(cb: () => void): boolean
|
||||
hasAny(): boolean
|
||||
invokeAll(): void
|
||||
}
|
||||
|
||||
export type Store<T = object> = T & {
|
||||
addChangeListener(cb: () => void): void
|
||||
removeChangeListener(cb: () => void): void
|
||||
addReactChangeListener(cb: () => void): void
|
||||
removeReactChangeListener(cb: () => void): void
|
||||
addConditionalChangeListener(cb: () => boolean): void
|
||||
|
||||
callback(cb: () => void): void
|
||||
throttledCallback(): unknown
|
||||
|
||||
getName(): string
|
||||
|
||||
__getLocalVars?(): object
|
||||
|
||||
_changeCallbacks: StoreChangeCallbacks
|
||||
_isInitialized: boolean
|
||||
_version: number
|
||||
_reactChangeCallbacks: StoreChangeCallbacks
|
||||
}
|
||||
|
||||
export interface Dispatcher {
|
||||
_actionHandlers: unknown
|
||||
_interceptors?: ((payload: DispatcherPayload) => undefined | boolean)[]
|
||||
_currentDispatchActionType: undefined | string
|
||||
_processingWaitQueue: boolean
|
||||
_subscriptions: Record<string, Set<(payload: DispatcherPayload) => void>>
|
||||
_waitQueue: unknown[]
|
||||
addDependencies(node1: DispatcherDependency, node2: DispatcherDependency): void
|
||||
dispatch(payload: DispatcherPayload): Promise<void>
|
||||
flushWaitQueue(): void
|
||||
isDispatching(): boolean
|
||||
register(
|
||||
name: string,
|
||||
actionHandler: Record<string, (e: DispatcherPayload) => void>,
|
||||
storeDidChange: (e: DispatcherPayload) => boolean,
|
||||
): string
|
||||
setInterceptor(interceptor?: (payload: DispatcherPayload) => undefined | boolean): void
|
||||
/**
|
||||
* Subscribes to an action type
|
||||
* @param actionType The action type to subscribe to
|
||||
* @param callback The callback to call when the action is dispatched
|
||||
*/
|
||||
subscribe(actionType: string, callback: (payload: DispatcherPayload) => void): void
|
||||
/**
|
||||
* Unsubscribes from an action type
|
||||
* @param actionType The action type to unsubscribe from
|
||||
* @param callback The callback to remove
|
||||
*/
|
||||
unsubscribe(actionType: string, callback: (payload: DispatcherPayload) => void): void
|
||||
wait(cb: () => void): void
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Discord's `Logger` class.
|
||||
*
|
||||
* Logs will be shown in the **Debug Logs** section in settings.
|
||||
*/
|
||||
export interface Logger {
|
||||
new (tag: string): void
|
||||
log(...args: unknown[]): void
|
||||
error(...args: unknown[]): void
|
||||
warn(...args: unknown[]): void
|
||||
info(...args: unknown[]): void
|
||||
debug(...args: unknown[]): void
|
||||
time(...args: unknown[]): void
|
||||
trace(...args: unknown[]): void
|
||||
verbose(...args: unknown[]): void
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,3 @@
|
|||
export * from './discord'
|
||||
export * from './discord.native'
|
||||
export * from './filter'
|
||||
export * from './metro'
|
||||
export * from './react-navigation'
|
||||
|
|
@ -48,7 +48,7 @@ export namespace Metro {
|
|||
|
||||
export type Module = {
|
||||
id?: ModuleID
|
||||
exports: Exports
|
||||
exports: ModuleExports
|
||||
}
|
||||
|
||||
export type ModuleList = Map<ModuleID, ModuleDefinition>
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
type FiniteDomain<Key extends PropertyKey> = unknown extends (
|
||||
Key extends unknown
|
||||
? {} extends Record<Key, unknown>
|
||||
? object extends Record<Key, unknown>
|
||||
? unknown
|
||||
: never
|
||||
: never
|
||||
|
|
@ -25,7 +25,7 @@
|
|||
"default": "./src/objects.ts"
|
||||
},
|
||||
"./types": {
|
||||
"types": "./src/types.d.ts"
|
||||
"types": "./src/types.ts"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue