Initial Commit
This commit is contained in:
5
packages/discord/src/jsx/components/action-row.ts
Normal file
5
packages/discord/src/jsx/components/action-row.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { createActionRow } from '@components';
|
||||
|
||||
export function ActionRow(props: { children: any | any[] }) {
|
||||
return createActionRow(...(Array.isArray(props.children) ? props.children : [props.children]));
|
||||
}
|
||||
6
packages/discord/src/jsx/components/button.ts
Normal file
6
packages/discord/src/jsx/components/button.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { createButton, type ButtonStyle } from '@components';
|
||||
import type { PartialEmoji } from '@projectdysnomia/dysnomia';
|
||||
|
||||
export function Button(props: { label: string; customId: string; style?: ButtonStyle; emoji?: PartialEmoji; disabled?: boolean }) {
|
||||
return createButton(props.label, props.customId, { style: props.style, emoji: props.emoji, disabled: props.disabled });
|
||||
}
|
||||
8
packages/discord/src/jsx/components/container.ts
Normal file
8
packages/discord/src/jsx/components/container.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { createContainer } from '@components';
|
||||
|
||||
export function Container(props: { accent?: number; spoiler?: boolean; children: any | any[] }) {
|
||||
return createContainer(
|
||||
{ accent_color: props.accent, spoiler: props.spoiler },
|
||||
...(Array.isArray(props.children) ? props.children : [props.children]),
|
||||
);
|
||||
}
|
||||
4
packages/discord/src/jsx/components/index.ts
Normal file
4
packages/discord/src/jsx/components/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from './action-row';
|
||||
export * from './button';
|
||||
export * from './container';
|
||||
export * from './text-display';
|
||||
5
packages/discord/src/jsx/components/text-display.ts
Normal file
5
packages/discord/src/jsx/components/text-display.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { createTextDisplay } from '@components/builders';
|
||||
|
||||
export function TextDisplay(props: { content: string }) {
|
||||
return createTextDisplay(props.content);
|
||||
}
|
||||
3
packages/discord/src/jsx/index.ts
Normal file
3
packages/discord/src/jsx/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from './runtime';
|
||||
export * from './components';
|
||||
export * as JSX from './jsx';
|
||||
69
packages/discord/src/jsx/jsx.ts
Normal file
69
packages/discord/src/jsx/jsx.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import {
|
||||
type ActionRow,
|
||||
type Button,
|
||||
type ChannelSelectMenu,
|
||||
type MentionableSelectMenu,
|
||||
type PartialEmoji,
|
||||
type RoleSelectMenu,
|
||||
type StringSelectMenu,
|
||||
type TextInput,
|
||||
type UserSelectMenu,
|
||||
type LabelComponent,
|
||||
type ContainerComponent,
|
||||
type TextDisplayComponent,
|
||||
type SectionComponent,
|
||||
type MediaGalleryComponent,
|
||||
type SeparatorComponent,
|
||||
type FileComponent,
|
||||
type InteractionButton,
|
||||
type URLButton,
|
||||
type PremiumButton,
|
||||
type ThumbnailComponent,
|
||||
} from '@projectdysnomia/dysnomia';
|
||||
|
||||
export type Component =
|
||||
| ActionRow
|
||||
| Button
|
||||
| StringSelectMenu
|
||||
| UserSelectMenu
|
||||
| RoleSelectMenu
|
||||
| MentionableSelectMenu
|
||||
| ChannelSelectMenu
|
||||
| TextInput
|
||||
| LabelComponent
|
||||
| ContainerComponent
|
||||
| TextDisplayComponent
|
||||
| SectionComponent
|
||||
| MediaGalleryComponent
|
||||
| SeparatorComponent
|
||||
| FileComponent
|
||||
| InteractionButton
|
||||
| URLButton
|
||||
| PremiumButton
|
||||
| ThumbnailComponent;
|
||||
|
||||
export type Element = Component | Promise<Component>;
|
||||
|
||||
export interface ElementClass {
|
||||
render: any;
|
||||
}
|
||||
|
||||
export interface ElementAttributesProperty {
|
||||
props: {};
|
||||
}
|
||||
|
||||
export interface IntrinsicElements {
|
||||
// Allow any element, but prefer known elements
|
||||
[elemName: string]: any;
|
||||
// Known elements
|
||||
ActionRow: { children: any | any[] };
|
||||
Button: {
|
||||
label: string;
|
||||
customId: string;
|
||||
style?: number;
|
||||
emoji?: PartialEmoji;
|
||||
disabled?: boolean;
|
||||
};
|
||||
Container: { color?: string; accent?: number; spoiler?: boolean; children: any | any[] };
|
||||
TextDisplay: { content: string };
|
||||
}
|
||||
30
packages/discord/src/jsx/runtime.ts
Normal file
30
packages/discord/src/jsx/runtime.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
export function jsx(type: any, props: Record<string, any>) {
|
||||
console.log('JSX', type, props);
|
||||
if (typeof type === 'function') {
|
||||
return type(props);
|
||||
}
|
||||
return {
|
||||
type,
|
||||
props,
|
||||
};
|
||||
}
|
||||
|
||||
export function jsxDEV(
|
||||
type: any,
|
||||
props: Record<string, any>,
|
||||
key: string | number | symbol,
|
||||
isStaticChildren: boolean,
|
||||
source: any,
|
||||
self: any,
|
||||
) {
|
||||
console.log('JSX DEV', type, props);
|
||||
if (typeof type === 'function') {
|
||||
return type(props);
|
||||
}
|
||||
return {
|
||||
type,
|
||||
props: { ...props, key },
|
||||
_source: source,
|
||||
_self: self,
|
||||
};
|
||||
}
|
||||
8
packages/discord/src/jsx/types.d.ts
vendored
Normal file
8
packages/discord/src/jsx/types.d.ts
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import type { Component, IntrinsicElements as StarKittenIntrinsicElements } from './jsx';
|
||||
|
||||
declare global {
|
||||
namespace JSX {
|
||||
type Element = Component;
|
||||
interface IntrinsicElements extends StarKittenIntrinsicElements {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user