Compare commits
189 Commits
new-api-pa
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 061608323f | |||
| d1611d8f64 | |||
|
|
b641885112 | ||
|
|
2a8ee7885d | ||
|
|
6c71073d10 | ||
|
|
5674e3c1b6 | ||
|
|
a41c825cdd | ||
|
|
a00fbc0631 | ||
|
|
a713f17a5c | ||
|
|
44795cd7cc | ||
|
|
17978a5252 | ||
|
|
95fb342183 | ||
|
|
0772ca4502 | ||
|
|
11153dfe0f | ||
|
|
fb0a997855 | ||
|
|
da1c62f2f0 | ||
|
|
cdc22b7916 | ||
|
|
7fee69c8ae | ||
|
|
c2e5dc04dd | ||
|
|
390da4cab6 | ||
|
|
def0c46f13 | ||
|
|
8b6e283810 | ||
|
|
13fcf7ddc9 | ||
|
|
ce12351a24 | ||
|
|
73bb098774 | ||
|
|
4ee4d4ab91 | ||
|
|
f998a0e09a | ||
|
|
453192cc96 | ||
|
|
d387f669ab | ||
|
|
9aec87ae9f | ||
|
|
65d1d68bb0 | ||
|
|
dfb7562c97 | ||
|
|
9e2be6c2e0 | ||
|
|
d078995516 | ||
|
|
82b3575f2d | ||
|
|
82b811c98b | ||
|
|
3a786310b1 | ||
|
|
ced48a3ecb | ||
|
|
37b75a99e2 | ||
|
|
f2f215d6b9 | ||
|
|
1f67e7c263 | ||
|
|
d4f1bb4d4b | ||
|
|
47c9b75940 | ||
|
|
41c87e3dcc | ||
|
|
b210670b2a | ||
|
|
2b9110bf2c | ||
|
|
5d4dde4e0c | ||
|
|
31baa23076 | ||
|
|
d76f316bb7 | ||
|
|
47b0645a90 | ||
|
|
0bab505994 | ||
|
|
104b175931 | ||
|
|
156cf90919 | ||
|
|
b463ce3cf4 | ||
|
|
576dd2e35e | ||
|
|
0d4294ee8c | ||
|
|
25fcc53d91 | ||
|
|
34bc293df5 | ||
|
|
b7b237f2f5 | ||
|
|
e2c3de4fae | ||
|
|
ffe0a86a33 | ||
|
|
6ce9241080 | ||
|
|
5d96d517df | ||
|
|
2c706f6791 | ||
|
|
2abb61493e | ||
|
|
3db1013b74 | ||
|
|
3e2c6ba5d6 | ||
|
|
0172534d13 | ||
|
|
1a49423beb | ||
|
|
3824859352 | ||
|
|
0dad3c9ecd | ||
|
|
eea1a7ee9d | ||
|
|
e9e5a1617b | ||
|
|
7ac1a9cdce | ||
|
|
33841a0c84 | ||
|
|
69b3112d32 | ||
|
|
b4fb6bc47c | ||
|
|
7aaef5f85f | ||
|
|
b755290569 | ||
|
|
f0ad743080 | ||
|
|
af3d1c5058 | ||
|
|
bdee9454f2 | ||
|
|
84348d287f | ||
|
|
6da6008d2c | ||
|
|
bece6c42fc | ||
|
|
abc809c9fb | ||
|
|
d35659f6f6 | ||
|
|
3969e6471f | ||
|
|
95041acfd4 | ||
|
|
eb0409f1a2 | ||
|
|
fbab145f39 | ||
|
|
f59323f245 | ||
|
|
1c37d37c28 | ||
|
|
408ab4ce89 | ||
|
|
a8a64e601a | ||
|
|
d88b982830 | ||
|
|
d87c27183a | ||
|
|
b141ca1868 | ||
|
|
dfa7f8090c | ||
|
|
82068d2d83 | ||
|
|
216ae7a29a | ||
|
|
9813a01a19 | ||
|
|
0be321b64e | ||
|
|
acbf21842f | ||
|
|
65be2ef201 | ||
|
|
c244124f6f | ||
|
|
4db8db0f2d | ||
|
|
1fa4bc800b | ||
|
|
e3351654ea | ||
|
|
d1ca002939 | ||
|
|
38a86bb783 | ||
|
|
72f4a4afff | ||
|
|
eed5715f1f | ||
|
|
e486da0881 | ||
|
|
b275d9b330 | ||
|
|
bab134d697 | ||
|
|
df9bdfaf77 | ||
|
|
35d7f0b33f | ||
|
|
4f9fb4310f | ||
|
|
7b74628732 | ||
|
|
7536bdee43 | ||
|
|
ef8d915e3b | ||
|
|
3f078c91d2 | ||
|
|
8df7bc9baa | ||
|
|
52e587e70f | ||
|
|
3152b1b79e | ||
|
|
d20afb094c | ||
|
|
118f567e8d | ||
|
|
a447fefc7b | ||
|
|
9efc61d8eb | ||
|
|
aa65da59df | ||
|
|
bc91080eca | ||
|
|
9afe6fe0fa | ||
|
|
abc60528d5 | ||
|
|
413f88c7b8 | ||
|
|
b482f07788 | ||
|
|
3b191d274e | ||
|
|
be5ec7c545 | ||
|
|
c93815b9f9 | ||
|
|
1e527993e5 | ||
|
|
f4eae8da75 | ||
|
|
62505ca98c | ||
|
|
cc1bc0932f | ||
|
|
c08f5621ef | ||
|
|
b6d2aac7a3 | ||
|
|
51ac0c89da | ||
|
|
f4985b1d87 | ||
|
|
96affac979 | ||
|
|
93b321dc36 | ||
|
|
e313399a5a | ||
|
|
90744ebe47 | ||
|
|
33bb2ee196 | ||
|
|
eb97b2d23d | ||
|
|
5aaaffbda9 | ||
|
|
43029019f4 | ||
|
|
8c481f18c6 | ||
|
|
87ecb20f7a | ||
|
|
2324f3c89f | ||
|
|
c35c32bddd | ||
|
|
6eb36b44f3 | ||
|
|
a1fc0287fc | ||
|
|
02dd763e63 | ||
|
|
a4024394e3 | ||
|
|
c72096058a | ||
|
|
672fcd5bc4 | ||
|
|
25f34b3715 | ||
|
|
8a7557f0eb | ||
|
|
fc3025baaf | ||
|
|
81f32794b4 | ||
|
|
dbf9640b16 | ||
|
|
a485ebaf74 | ||
|
|
7ef5a7ac9d | ||
|
|
6715756c2b | ||
|
|
6851c5419a | ||
|
|
1ba75492e5 | ||
|
|
aced338d72 | ||
|
|
512c0649d8 | ||
|
|
91b82ca41f | ||
|
|
752ccc080d | ||
|
|
3c2d3b4683 | ||
|
|
ad57674d6e | ||
|
|
065bec9a37 | ||
|
|
d3ccafc6d5 | ||
|
|
c71d70bbb4 | ||
|
|
5ba12af699 | ||
|
|
ff39ef753f | ||
|
|
2288c27e1e | ||
|
|
c86648f44e | ||
|
|
0edf702b5f |
8
.changeset/README.md
Normal file
8
.changeset/README.md
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# Changesets
|
||||||
|
|
||||||
|
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
|
||||||
|
with multi-package repos, or single-package repos to help you version and publish your code. You can
|
||||||
|
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
|
||||||
|
|
||||||
|
We have a quick list of common questions to get you started engaging with this project in
|
||||||
|
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
|
||||||
11
.changeset/config.json
Normal file
11
.changeset/config.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://unpkg.com/@changesets/config@2.1.0/schema.json",
|
||||||
|
"changelog": "@changesets/cli/changelog",
|
||||||
|
"commit": false,
|
||||||
|
"fixed": [],
|
||||||
|
"linked": [],
|
||||||
|
"access": "public",
|
||||||
|
"baseBranch": "main",
|
||||||
|
"updateInternalDependencies": "patch",
|
||||||
|
"ignore": []
|
||||||
|
}
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": ["./node_modules/@itsmapleleaf/configs/eslint"],
|
|
||||||
"ignorePatterns": [
|
|
||||||
"**/node_modules/**",
|
|
||||||
"**/.cache/**",
|
|
||||||
"**/build/**",
|
|
||||||
"**/dist/**",
|
|
||||||
"**/coverage/**",
|
|
||||||
"**/public/**"
|
|
||||||
],
|
|
||||||
"parserOptions": {
|
|
||||||
"project": "./tsconfig.base.json"
|
|
||||||
},
|
|
||||||
"rules": {
|
|
||||||
"import/no-unused-modules": "off",
|
|
||||||
"unicorn/prevent-abbreviations": "off"
|
|
||||||
},
|
|
||||||
"overrides": [
|
|
||||||
{
|
|
||||||
"files": ["packages/website/cypress/**"],
|
|
||||||
"parserOptions": {
|
|
||||||
"project": "./packages/website/cypress/tsconfig.json"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
17
.github/workflows/deploy-website.yml
vendored
17
.github/workflows/deploy-website.yml
vendored
@@ -1,17 +0,0 @@
|
|||||||
name: deploy website
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [main]
|
|
||||||
paths:
|
|
||||||
- "packages/website/**"
|
|
||||||
- "reacord/library/**/*.{ts,tsx}"
|
|
||||||
jobs:
|
|
||||||
deploy:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- uses: superfly/flyctl-actions@master
|
|
||||||
env:
|
|
||||||
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
|
|
||||||
with:
|
|
||||||
args: "deploy"
|
|
||||||
41
.github/workflows/main.yml
vendored
41
.github/workflows/main.yml
vendored
@@ -1,41 +0,0 @@
|
|||||||
name: main
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [main]
|
|
||||||
pull_request:
|
|
||||||
|
|
||||||
env:
|
|
||||||
TEST_BOT_TOKEN: ${{ secrets.TEST_BOT_TOKEN }}
|
|
||||||
TEST_CHANNEL_ID: ${{ secrets.TEST_CHANNEL_ID }}
|
|
||||||
TEST_GUILD_ID: ${{ secrets.TEST_GUILD_ID }}
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
run-commands:
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
command:
|
|
||||||
# if these run in the same process, it dies,
|
|
||||||
# so we test them separate
|
|
||||||
- name: test reacord
|
|
||||||
run: pnpm test -C packages/reacord
|
|
||||||
- name: test website
|
|
||||||
run: pnpm test -C packages/website
|
|
||||||
- name: build
|
|
||||||
run: pnpm build --recursive
|
|
||||||
- name: lint
|
|
||||||
run: pnpm lint
|
|
||||||
- name: typecheck
|
|
||||||
run: pnpm typecheck --parallel
|
|
||||||
name: ${{ matrix.command.name }}
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- uses: actions/setup-node@v2
|
|
||||||
with:
|
|
||||||
# https://github.com/actions/setup-node#supported-version-syntax
|
|
||||||
node-version: "16"
|
|
||||||
- run: npm i -g pnpm
|
|
||||||
- run: pnpm install --frozen-lockfile
|
|
||||||
- run: ${{ matrix.command.run }}
|
|
||||||
33
.github/workflows/release.yml
vendored
Normal file
33
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# https://pnpm.io/using-changesets
|
||||||
|
name: release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
concurrency: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
name: release
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: pnpm/action-setup@v2
|
||||||
|
with:
|
||||||
|
version: 8
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 18
|
||||||
|
cache: pnpm
|
||||||
|
- run: pnpm install --frozen-lockfile
|
||||||
|
|
||||||
|
- name: changesets release
|
||||||
|
id: changesets
|
||||||
|
uses: changesets/action@v1
|
||||||
|
with:
|
||||||
|
publish: pnpm run release
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
44
.github/workflows/tests.yml
vendored
Normal file
44
.github/workflows/tests.yml
vendored
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
name: tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
env:
|
||||||
|
TEST_BOT_TOKEN: ${{ secrets.TEST_BOT_TOKEN }}
|
||||||
|
TEST_CHANNEL_ID: ${{ secrets.TEST_CHANNEL_ID }}
|
||||||
|
TEST_GUILD_ID: ${{ secrets.TEST_GUILD_ID }}
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
tests:
|
||||||
|
name: ${{ matrix.script }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
script:
|
||||||
|
- lint
|
||||||
|
- build
|
||||||
|
- test
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: node_modules
|
||||||
|
key: ${{ runner.os }}-node-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||||||
|
- uses: pnpm/action-setup@v2
|
||||||
|
with:
|
||||||
|
version: 8
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 18
|
||||||
|
cache: pnpm
|
||||||
|
- run: pnpm install --frozen-lockfile
|
||||||
|
- run: pnpm run ${{ matrix.script }}
|
||||||
|
- uses: stefanzweifel/git-auto-commit-action@v4
|
||||||
|
if: always()
|
||||||
7
.gitignore
vendored
7
.gitignore
vendored
@@ -3,4 +3,9 @@ node_modules
|
|||||||
.vscode
|
.vscode
|
||||||
coverage
|
coverage
|
||||||
.env
|
.env
|
||||||
|
*.code-workspace
|
||||||
|
.pnpm-debug.log
|
||||||
|
build
|
||||||
|
.cache
|
||||||
|
.vercel
|
||||||
|
*.tsbuildinfo
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
node_modules
|
|
||||||
dist
|
|
||||||
coverage
|
|
||||||
pnpm-lock.yaml
|
pnpm-lock.yaml
|
||||||
build
|
/packages/website/public/api
|
||||||
.cache
|
.astro
|
||||||
|
|||||||
15
Dockerfile
15
Dockerfile
@@ -1,15 +0,0 @@
|
|||||||
FROM node:lts-slim
|
|
||||||
|
|
||||||
ENV CYPRESS_INSTALL_BINARY=0
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
COPY / ./
|
|
||||||
RUN ls -R
|
|
||||||
|
|
||||||
RUN npm install -g pnpm
|
|
||||||
RUN pnpm install --unsafe-perm --frozen-lockfile
|
|
||||||
RUN pnpm run build -C packages/website
|
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
|
||||||
CMD [ "pnpm", "-C", "packages/website", "start" ]
|
|
||||||
30
README.md
30
README.md
@@ -1,42 +1,30 @@
|
|||||||
<center>
|
|
||||||
<img src="./packages/website/app/assets/banner.png" alt="Reacord: Create interactive Discord messages using React">
|
|
||||||
</center>
|
|
||||||
|
|
||||||
## Installation ∙ [](https://www.npmjs.com/package/reacord)
|
## Installation ∙ [](https://www.npmjs.com/package/reacord)
|
||||||
|
|
||||||
```console
|
```console
|
||||||
# npm
|
# bun
|
||||||
npm install reacord react discord.js
|
bun add reacord react discord.js
|
||||||
|
|
||||||
# yarn
|
|
||||||
yarn add reacord react discord.js
|
|
||||||
|
|
||||||
# pnpm
|
|
||||||
pnpm add reacord react discord.js
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Get Started
|
|
||||||
|
|
||||||
[Visit the docs to get started.](https://reacord.fly.dev/guides/getting-started)
|
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
<!-- prettier-ignore -->
|
<!-- prettier-ignore -->
|
||||||
```tsx
|
```tsx
|
||||||
import * as React from "react"
|
import { useState } from "react"
|
||||||
import { Embed, Button } from "reacord"
|
import { Embed, Button } from "reacord"
|
||||||
|
|
||||||
function Counter() {
|
function Counter() {
|
||||||
const [count, setCount] = React.useState(0)
|
const [count, setCount] = useState(0)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Embed title="Counter">
|
<Embed title="Counter">
|
||||||
This button has been clicked {count} times.
|
This button has been clicked {count} times.
|
||||||
</Embed>
|
</Embed>
|
||||||
<Button onClick={() => setCount(count + 1)}>
|
<Button
|
||||||
+1
|
label="+1"
|
||||||
</Button>
|
onClick={() => setCount(count + 1)}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
40
fly.toml
40
fly.toml
@@ -1,40 +0,0 @@
|
|||||||
# fly.toml file generated for reacord on 2021-12-29T14:06:41-06:00
|
|
||||||
|
|
||||||
app = "reacord"
|
|
||||||
|
|
||||||
kill_signal = "SIGINT"
|
|
||||||
kill_timeout = 5
|
|
||||||
processes = []
|
|
||||||
|
|
||||||
[env]
|
|
||||||
PORT = 8080
|
|
||||||
|
|
||||||
[experimental]
|
|
||||||
allowed_public_ports = []
|
|
||||||
auto_rollback = true
|
|
||||||
|
|
||||||
[[services]]
|
|
||||||
http_checks = []
|
|
||||||
internal_port = 8080
|
|
||||||
processes = ["app"]
|
|
||||||
protocol = "tcp"
|
|
||||||
script_checks = []
|
|
||||||
|
|
||||||
[services.concurrency]
|
|
||||||
hard_limit = 25
|
|
||||||
soft_limit = 20
|
|
||||||
type = "connections"
|
|
||||||
|
|
||||||
[[services.ports]]
|
|
||||||
handlers = ["http"]
|
|
||||||
port = 80
|
|
||||||
|
|
||||||
[[services.ports]]
|
|
||||||
handlers = ["tls", "http"]
|
|
||||||
port = 443
|
|
||||||
|
|
||||||
[[services.tcp_checks]]
|
|
||||||
grace_period = "1s"
|
|
||||||
interval = "15s"
|
|
||||||
restart_limit = 0
|
|
||||||
timeout = "2s"
|
|
||||||
56
package.json
56
package.json
@@ -1,29 +1,41 @@
|
|||||||
{
|
{
|
||||||
|
"name": "reacord-monorepo",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
"workspaces": [
|
||||||
|
"packages/*"
|
||||||
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint --ext js,ts,tsx .",
|
"lint": "run-s --continue-on-error lint:*",
|
||||||
"lint-fix": "pnpm lint -- --fix",
|
"lint:eslint": "eslint . --fix --cache --cache-file=node_modules/.cache/.eslintcache --report-unused-disable-directives",
|
||||||
"format": "prettier --write ."
|
"lint:prettier": "prettier . \"**/*.astro\" --write --cache --list-different",
|
||||||
},
|
"lint:types": "bun run --cwd packages/helpers typecheck && bun run --cwd packages/reacord typecheck",
|
||||||
"dependencies": {
|
"test": "vitest",
|
||||||
"@itsmapleleaf/configs": "^1.1.2"
|
"build": "bun run --cwd packages/reacord build",
|
||||||
|
"release": "bun run build && changeset publish"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@typescript-eslint/eslint-plugin": "^5.9.1",
|
"@changesets/cli": "^2.26.2",
|
||||||
"@typescript-eslint/parser": "^5.9.1",
|
"@itsmapleleaf/configs": "github:itsMapleLeaf/configs",
|
||||||
"eslint": "^8.6.0",
|
"eslint": "^8.51.0",
|
||||||
"eslint-config-prettier": "^8.3.0",
|
"npm-run-all": "^4.1.5",
|
||||||
"eslint-import-resolver-typescript": "^2.5.0",
|
"prettier": "^3.0.3",
|
||||||
"eslint-plugin-import": "^2.25.4",
|
"react": "^18.2.0",
|
||||||
"eslint-plugin-jsx-a11y": "^6.5.1",
|
"typescript": "^5.2.2",
|
||||||
"eslint-plugin-react": "^7.28.0",
|
"vitest": "^0.34.6"
|
||||||
"eslint-plugin-react-hooks": "^4.3.0",
|
|
||||||
"eslint-plugin-unicorn": "^40.0.0",
|
|
||||||
"prettier": "^2.5.1",
|
|
||||||
"typescript": "^4.5.4"
|
|
||||||
},
|
},
|
||||||
"resolutions": {
|
"prettier": "@itsmapleleaf/configs/prettier",
|
||||||
"esbuild": "latest"
|
"eslintConfig": {
|
||||||
},
|
"extends": [
|
||||||
"prettier": "@itsmapleleaf/configs/prettier"
|
"./node_modules/@itsmapleleaf/configs/eslint.config.cjs",
|
||||||
|
"./node_modules/@itsmapleleaf/configs/eslint.config.react.cjs"
|
||||||
|
],
|
||||||
|
"ignorePatterns": [
|
||||||
|
"node_modules",
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
|
"rules": {
|
||||||
|
"@typescript-eslint/no-non-null-assertion": "warn",
|
||||||
|
"@typescript-eslint/require-await": "off"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
42
packages/helpers/convert-object-property-case.test.ts
Normal file
42
packages/helpers/convert-object-property-case.test.ts
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import { camelCaseDeep, snakeCaseDeep } from "./convert-object-property-case"
|
||||||
|
import type {
|
||||||
|
CamelCasedPropertiesDeep,
|
||||||
|
SnakeCasedPropertiesDeep,
|
||||||
|
} from "type-fest"
|
||||||
|
import { expect, test } from "vitest"
|
||||||
|
|
||||||
|
test("camelCaseDeep", () => {
|
||||||
|
const input = {
|
||||||
|
some_prop: {
|
||||||
|
some_deep_prop: "some_deep_value",
|
||||||
|
},
|
||||||
|
someOtherProp: "someOtherValue",
|
||||||
|
}
|
||||||
|
|
||||||
|
const expected: CamelCasedPropertiesDeep<typeof input> = {
|
||||||
|
someProp: {
|
||||||
|
someDeepProp: "some_deep_value",
|
||||||
|
},
|
||||||
|
someOtherProp: "someOtherValue",
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(camelCaseDeep(input)).toEqual(expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("snakeCaseDeep", () => {
|
||||||
|
const input = {
|
||||||
|
someProp: {
|
||||||
|
someDeepProp: "someDeepValue",
|
||||||
|
},
|
||||||
|
some_other_prop: "someOtherValue",
|
||||||
|
}
|
||||||
|
|
||||||
|
const expected: SnakeCasedPropertiesDeep<typeof input> = {
|
||||||
|
some_prop: {
|
||||||
|
some_deep_prop: "someDeepValue",
|
||||||
|
},
|
||||||
|
some_other_prop: "someOtherValue",
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(snakeCaseDeep(input)).toEqual(expected)
|
||||||
|
})
|
||||||
35
packages/helpers/convert-object-property-case.ts
Normal file
35
packages/helpers/convert-object-property-case.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import { camelCase, isObject, snakeCase } from "lodash-es"
|
||||||
|
import type {
|
||||||
|
CamelCasedPropertiesDeep,
|
||||||
|
SnakeCasedPropertiesDeep,
|
||||||
|
UnknownRecord,
|
||||||
|
} from "type-fest"
|
||||||
|
|
||||||
|
function convertKeyCaseDeep<Input, Output>(
|
||||||
|
input: Input,
|
||||||
|
convertKey: (key: string) => string,
|
||||||
|
): Output {
|
||||||
|
if (!isObject(input)) {
|
||||||
|
return input as unknown as Output
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(input)) {
|
||||||
|
return input.map((item) =>
|
||||||
|
convertKeyCaseDeep(item, convertKey),
|
||||||
|
) as unknown as Output
|
||||||
|
}
|
||||||
|
|
||||||
|
const output = {} as UnknownRecord
|
||||||
|
for (const [key, value] of Object.entries(input)) {
|
||||||
|
output[convertKey(key)] = convertKeyCaseDeep(value, convertKey)
|
||||||
|
}
|
||||||
|
return output as Output
|
||||||
|
}
|
||||||
|
|
||||||
|
export function camelCaseDeep<T>(input: T): CamelCasedPropertiesDeep<T> {
|
||||||
|
return convertKeyCaseDeep(input, camelCase)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function snakeCaseDeep<T>(input: T): SnakeCasedPropertiesDeep<T> {
|
||||||
|
return convertKeyCaseDeep(input, snakeCase)
|
||||||
|
}
|
||||||
7
packages/helpers/is-instance-of.ts
Normal file
7
packages/helpers/is-instance-of.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
/** For narrowing instance types with array.filter */
|
||||||
|
export const isInstanceOf =
|
||||||
|
<Instance, Args extends unknown[]>(
|
||||||
|
constructor: new (...args: Args) => Instance,
|
||||||
|
) =>
|
||||||
|
(value: unknown): value is Instance =>
|
||||||
|
value instanceof constructor
|
||||||
3
packages/helpers/is-object.ts
Normal file
3
packages/helpers/is-object.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export function isObject(value: unknown): value is object {
|
||||||
|
return typeof value === "object" && value !== null
|
||||||
|
}
|
||||||
7
packages/helpers/json.ts
Normal file
7
packages/helpers/json.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
export function safeJsonStringify(value: unknown): string {
|
||||||
|
try {
|
||||||
|
return JSON.stringify(value)
|
||||||
|
} catch {
|
||||||
|
return String(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
11
packages/helpers/log-pretty.ts
Normal file
11
packages/helpers/log-pretty.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { inspect } from "node:util"
|
||||||
|
|
||||||
|
export function logPretty(value: unknown) {
|
||||||
|
console.info(
|
||||||
|
inspect(value, {
|
||||||
|
// depth: Number.POSITIVE_INFINITY,
|
||||||
|
depth: 10,
|
||||||
|
colors: true,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
7
packages/helpers/omit.test.ts
Normal file
7
packages/helpers/omit.test.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { expect, test } from "vitest"
|
||||||
|
import { omit } from "./omit.ts"
|
||||||
|
|
||||||
|
test("omit", () => {
|
||||||
|
const subject = { a: 1, b: true }
|
||||||
|
expect(omit(subject, ["a"])).toStrictEqual({ b: true })
|
||||||
|
})
|
||||||
3
packages/helpers/omit.test.types.ts
Normal file
3
packages/helpers/omit.test.types.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import { omit } from "./omit.ts"
|
||||||
|
|
||||||
|
omit({ a: 1, b: true }, ["a"]) satisfies { b: boolean }
|
||||||
10
packages/helpers/omit.ts
Normal file
10
packages/helpers/omit.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
export function omit<Subject extends object, Key extends PropertyKey>(
|
||||||
|
subject: Subject,
|
||||||
|
keys: Key[],
|
||||||
|
) {
|
||||||
|
const keySet = new Set<PropertyKey>(keys)
|
||||||
|
return Object.fromEntries(
|
||||||
|
Object.entries(subject).filter(([key]) => !keySet.has(key)),
|
||||||
|
// hack: conditional type preserves unions
|
||||||
|
) as Subject extends unknown ? Omit<Subject, Key> : never
|
||||||
|
}
|
||||||
15
packages/helpers/package.json
Normal file
15
packages/helpers/package.json
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "@reacord/helpers",
|
||||||
|
"type": "module",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"typecheck": "tsc -b"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@types/lodash-es": "^4.17.9",
|
||||||
|
"lodash-es": "^4.17.21",
|
||||||
|
"type-fest": "^4.4.0",
|
||||||
|
"vitest": "^0.34.6"
|
||||||
|
}
|
||||||
|
}
|
||||||
11
packages/helpers/pick.ts
Normal file
11
packages/helpers/pick.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import type { LoosePick } from "./types"
|
||||||
|
|
||||||
|
export function pick<T extends object, K extends keyof T | PropertyKey>(
|
||||||
|
object: T,
|
||||||
|
keys: K[],
|
||||||
|
) {
|
||||||
|
const keySet = new Set<PropertyKey>(keys)
|
||||||
|
return Object.fromEntries(
|
||||||
|
Object.entries(object).filter(([key]) => keySet.has(key)),
|
||||||
|
) as LoosePick<T, K>
|
||||||
|
}
|
||||||
34
packages/helpers/prune-nullish-values.test.ts
Normal file
34
packages/helpers/prune-nullish-values.test.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { expect, test } from "vitest"
|
||||||
|
import type { PruneNullishValues } from "./prune-nullish-values"
|
||||||
|
import { pruneNullishValues } from "./prune-nullish-values"
|
||||||
|
|
||||||
|
test("pruneNullishValues", () => {
|
||||||
|
interface InputType {
|
||||||
|
a: string
|
||||||
|
b: string | null | undefined
|
||||||
|
c?: string
|
||||||
|
d: {
|
||||||
|
a: string
|
||||||
|
b: string | undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const input: InputType = {
|
||||||
|
a: "a",
|
||||||
|
b: null,
|
||||||
|
c: undefined,
|
||||||
|
d: {
|
||||||
|
a: "a",
|
||||||
|
b: undefined,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const output: PruneNullishValues<InputType> = {
|
||||||
|
a: "a",
|
||||||
|
d: {
|
||||||
|
a: "a",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(pruneNullishValues(input)).toEqual(output)
|
||||||
|
})
|
||||||
46
packages/helpers/prune-nullish-values.ts
Normal file
46
packages/helpers/prune-nullish-values.ts
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import { isObject } from "./is-object"
|
||||||
|
|
||||||
|
export function pruneNullishValues<T>(input: T): PruneNullishValues<T> {
|
||||||
|
if (!isObject(input)) {
|
||||||
|
return input as PruneNullishValues<T>
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(input)) {
|
||||||
|
return input
|
||||||
|
.filter(Boolean)
|
||||||
|
.map(
|
||||||
|
(item) => pruneNullishValues(item) as unknown,
|
||||||
|
) as PruneNullishValues<T>
|
||||||
|
}
|
||||||
|
|
||||||
|
const result: Record<string, unknown> = {}
|
||||||
|
for (const [key, value] of Object.entries(input)) {
|
||||||
|
if (value != undefined) {
|
||||||
|
result[key] = pruneNullishValues(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result as PruneNullishValues<T>
|
||||||
|
}
|
||||||
|
|
||||||
|
export type PruneNullishValues<Input> = Input extends object
|
||||||
|
? OptionalKeys<
|
||||||
|
{ [Key in keyof Input]: NonNullable<PruneNullishValues<Input[Key]>> },
|
||||||
|
KeysWithNullishValues<Input>
|
||||||
|
>
|
||||||
|
: Input
|
||||||
|
|
||||||
|
type OptionalKeys<Input, Keys extends keyof Input> = Omit<Input, Keys> & {
|
||||||
|
[Key in Keys]?: Input[Key]
|
||||||
|
}
|
||||||
|
|
||||||
|
type KeysWithNullishValues<Input> = NonNullable<
|
||||||
|
Values<{
|
||||||
|
[Key in keyof Input]: null extends Input[Key]
|
||||||
|
? Key
|
||||||
|
: undefined extends Input[Key]
|
||||||
|
? Key
|
||||||
|
: never
|
||||||
|
}>
|
||||||
|
>
|
||||||
|
|
||||||
|
type Values<Input> = Input[keyof Input]
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { setTimeout } from "node:timers/promises"
|
|
||||||
import { toError } from "./to-error.js"
|
import { toError } from "./to-error.js"
|
||||||
|
import { setTimeout } from "node:timers/promises"
|
||||||
|
|
||||||
export async function rejectAfter(
|
export async function rejectAfter(
|
||||||
timeMs: number,
|
timeMs: number,
|
||||||
21
packages/helpers/retry-with-timeout.ts
Normal file
21
packages/helpers/retry-with-timeout.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { setTimeout } from "node:timers/promises"
|
||||||
|
|
||||||
|
const maxTime = 500
|
||||||
|
const waitPeriod = 50
|
||||||
|
|
||||||
|
export async function retryWithTimeout<T>(
|
||||||
|
callback: () => Promise<T> | T,
|
||||||
|
): Promise<T> {
|
||||||
|
const startTime = Date.now()
|
||||||
|
// eslint-disable-next-line no-constant-condition, @typescript-eslint/no-unnecessary-condition
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
return await callback()
|
||||||
|
} catch (error) {
|
||||||
|
if (Date.now() - startTime > maxTime) {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
await setTimeout(waitPeriod)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
packages/helpers/to-error.ts
Normal file
3
packages/helpers/to-error.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export function toError(value: unknown) {
|
||||||
|
return value instanceof Error ? value : new Error(String(value))
|
||||||
|
}
|
||||||
3
packages/helpers/tsconfig.json
Normal file
3
packages/helpers/tsconfig.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../tsconfig.base.json"
|
||||||
|
}
|
||||||
4
packages/helpers/types.test.types.ts
Normal file
4
packages/helpers/types.test.types.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import { type LooseOmit, type LoosePick, typeEquals } from "./types.ts"
|
||||||
|
|
||||||
|
typeEquals<LoosePick<{ a: 1; b: 2 }, "a">, { a: 1 }>(true)
|
||||||
|
typeEquals<LooseOmit<{ a: 1; b: 2 }, "a">, { b: 2 }>(true)
|
||||||
21
packages/helpers/types.ts
Normal file
21
packages/helpers/types.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { raise } from "./raise.ts"
|
||||||
|
|
||||||
|
export type MaybePromise<T> = T | PromiseLike<T>
|
||||||
|
|
||||||
|
export type ValueOf<Type> = Type extends ReadonlyArray<infer Value>
|
||||||
|
? Value
|
||||||
|
: Type[keyof Type]
|
||||||
|
|
||||||
|
export type LoosePick<Shape, Keys extends PropertyKey> = Simplify<{
|
||||||
|
[Key in Extract<Keys, keyof Shape>]: Shape[Key]
|
||||||
|
}>
|
||||||
|
|
||||||
|
export type LooseOmit<Shape, Keys extends PropertyKey> = Simplify<{
|
||||||
|
[Key in Exclude<keyof Shape, Keys>]: Shape[Key]
|
||||||
|
}>
|
||||||
|
|
||||||
|
export type Simplify<T> = { [Key in keyof T]: T[Key] } & NonNullable<unknown>
|
||||||
|
|
||||||
|
export const typeEquals = <A, B>(
|
||||||
|
_result: A extends B ? (B extends A ? true : false) : false,
|
||||||
|
) => raise("typeEquals() should not be called at runtime")
|
||||||
23
packages/helpers/wait-for.ts
Normal file
23
packages/helpers/wait-for.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { setTimeout } from "node:timers/promises"
|
||||||
|
import type { MaybePromise } from "./types.ts"
|
||||||
|
|
||||||
|
const maxTime = 1000
|
||||||
|
|
||||||
|
export async function waitFor<Result>(
|
||||||
|
predicate: () => MaybePromise<Result>,
|
||||||
|
): Promise<Awaited<Result>> {
|
||||||
|
const startTime = Date.now()
|
||||||
|
let lastError: unknown
|
||||||
|
|
||||||
|
while (Date.now() - startTime < maxTime) {
|
||||||
|
try {
|
||||||
|
return await predicate()
|
||||||
|
} catch (error) {
|
||||||
|
lastError = error
|
||||||
|
await setTimeout(50)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-throw-literal
|
||||||
|
throw lastError ?? new Error("Timeout")
|
||||||
|
}
|
||||||
24
packages/helpers/with-logged-method-calls.ts
Normal file
24
packages/helpers/with-logged-method-calls.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { inspect } from "node:util"
|
||||||
|
|
||||||
|
export function withLoggedMethodCalls<T extends object>(value: T) {
|
||||||
|
return new Proxy(value as Record<string | symbol, unknown>, {
|
||||||
|
get(target, property) {
|
||||||
|
const value = target[property]
|
||||||
|
if (typeof value !== "function") {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
return (...values: unknown[]) => {
|
||||||
|
console.info(
|
||||||
|
`${String(property)}(${values
|
||||||
|
.map((value) =>
|
||||||
|
typeof value === "object" && value !== null
|
||||||
|
? value.constructor.name
|
||||||
|
: inspect(value, { colors: true }),
|
||||||
|
)
|
||||||
|
.join(", ")})`,
|
||||||
|
)
|
||||||
|
return value.apply(target, values) as unknown
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}) as T
|
||||||
|
}
|
||||||
85
packages/reacord/CHANGELOG.md
Normal file
85
packages/reacord/CHANGELOG.md
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
# reacord
|
||||||
|
|
||||||
|
## 0.6.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- 11153df: breaking: more descriptive component event types
|
||||||
|
- fb0a997: add new descriptive adapter methods
|
||||||
|
|
||||||
|
The reacord instance names have been updated, and the old names are now deprecated.
|
||||||
|
|
||||||
|
- `send` -> `createChannelMessage`
|
||||||
|
- `reply` -> `createInteractionReply`
|
||||||
|
|
||||||
|
These new methods also accept discord JS options. Usage example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// can accept either a channel object or a channel ID
|
||||||
|
reacord.createChannelMessage(channel)
|
||||||
|
reacord.createChannelMessage(channel, {
|
||||||
|
tts: true,
|
||||||
|
})
|
||||||
|
reacord.createChannelMessage(channel, {
|
||||||
|
reply: {
|
||||||
|
messageReference: "123456789012345678",
|
||||||
|
failIfNotExists: false,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
reacord.createInteractionReply(interaction)
|
||||||
|
reacord.createInteractionReply(interaction, {
|
||||||
|
ephemeral: true,
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
These new methods replace the old ones, which are now deprecated.
|
||||||
|
|
||||||
|
## 0.5.5
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- ced48a3: distribute d.ts files again instead of the source
|
||||||
|
|
||||||
|
distributing the source causes typecheck errors when the modules it imports from (in this case, `@reacord/helpers`) don't exist in the end users' projects, so we'll just distribute d.ts files instead like normal. failed experiment :(
|
||||||
|
|
||||||
|
## 0.5.4
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 41c87e3: fix type definitions
|
||||||
|
|
||||||
|
`"types"` wasn't updated, oops!
|
||||||
|
|
||||||
|
technically the typedefs were already correctly defined via `"exports"`, but this may not be picked up depending on the tsconfig, so I'll ensure both are used for compatibility purposes. but this might be worth a note in the docs; pretty much every modern TS Node project should be using a tsconfig that doesn't require setting `"types"`
|
||||||
|
|
||||||
|
## 0.5.3
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 104b175: ensure message is edited from arbitrary component updates
|
||||||
|
- 156cf90: fix interaction handling
|
||||||
|
- 0bab505: fix DJS deprecation warning on isStringSelectMenu
|
||||||
|
- d76f316: ensure action rows handle child interactions
|
||||||
|
|
||||||
|
## 0.5.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 9813a01: import react-reconciler/constants.js for esm
|
||||||
|
|
||||||
|
ESM projects which tried to import reacord would fail due to the lack of .js on this import
|
||||||
|
|
||||||
|
## 0.5.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 72f4a4a: upgrade dependencies and remove some unneeded
|
||||||
|
- 7536bde: add types in exports to work with TS nodenext
|
||||||
|
- e335165: fix links
|
||||||
|
|
||||||
|
## 0.5.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- aa65da5: allow JSX in more places
|
||||||
1
packages/reacord/env.d.ts
vendored
Normal file
1
packages/reacord/env.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/// <reference types="@total-typescript/ts-reset" />
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
import type {
|
|
||||||
CamelCasedPropertiesDeep,
|
|
||||||
SnakeCasedPropertiesDeep,
|
|
||||||
} from "type-fest"
|
|
||||||
import { expect, test } from "vitest"
|
|
||||||
import { camelCaseDeep, snakeCaseDeep } from "./convert-object-property-case"
|
|
||||||
|
|
||||||
test("camelCaseDeep", () => {
|
|
||||||
const input = {
|
|
||||||
some_prop: {
|
|
||||||
some_deep_prop: "some_deep_value",
|
|
||||||
},
|
|
||||||
someOtherProp: "someOtherValue",
|
|
||||||
}
|
|
||||||
|
|
||||||
const expected: CamelCasedPropertiesDeep<typeof input> = {
|
|
||||||
someProp: {
|
|
||||||
someDeepProp: "some_deep_value",
|
|
||||||
},
|
|
||||||
someOtherProp: "someOtherValue",
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(camelCaseDeep(input)).toEqual(expected)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("snakeCaseDeep", () => {
|
|
||||||
const input = {
|
|
||||||
someProp: {
|
|
||||||
someDeepProp: "someDeepValue",
|
|
||||||
},
|
|
||||||
some_other_prop: "someOtherValue",
|
|
||||||
}
|
|
||||||
|
|
||||||
const expected: SnakeCasedPropertiesDeep<typeof input> = {
|
|
||||||
some_prop: {
|
|
||||||
some_deep_prop: "someDeepValue",
|
|
||||||
},
|
|
||||||
some_other_prop: "someOtherValue",
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(snakeCaseDeep(input)).toEqual(expected)
|
|
||||||
})
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
import { camelCase, isObject, snakeCase } from "lodash-es"
|
|
||||||
import type {
|
|
||||||
CamelCasedPropertiesDeep,
|
|
||||||
SnakeCasedPropertiesDeep,
|
|
||||||
} from "type-fest"
|
|
||||||
|
|
||||||
function convertKeyCaseDeep<Input, Output>(
|
|
||||||
input: Input,
|
|
||||||
convertKey: (key: string) => string,
|
|
||||||
): Output {
|
|
||||||
if (!isObject(input)) {
|
|
||||||
return input as unknown as Output
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Array.isArray(input)) {
|
|
||||||
return input.map((item) =>
|
|
||||||
convertKeyCaseDeep(item, convertKey),
|
|
||||||
) as unknown as Output
|
|
||||||
}
|
|
||||||
|
|
||||||
const output: any = {}
|
|
||||||
for (const [key, value] of Object.entries(input)) {
|
|
||||||
output[convertKey(key)] = convertKeyCaseDeep(value, convertKey)
|
|
||||||
}
|
|
||||||
return output
|
|
||||||
}
|
|
||||||
|
|
||||||
export function camelCaseDeep<T>(input: T): CamelCasedPropertiesDeep<T> {
|
|
||||||
return convertKeyCaseDeep(input, camelCase)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function snakeCaseDeep<T>(input: T): SnakeCasedPropertiesDeep<T> {
|
|
||||||
return convertKeyCaseDeep(input, snakeCase)
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
/**
|
|
||||||
* for narrowing instance types with array.filter
|
|
||||||
*/
|
|
||||||
export const isInstanceOf =
|
|
||||||
<T>(Constructor: new (...args: any[]) => T) =>
|
|
||||||
(value: unknown): value is T =>
|
|
||||||
value instanceof Constructor
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
export function isObject<T>(
|
|
||||||
value: T,
|
|
||||||
): value is Exclude<T, Primitive | AnyFunction> {
|
|
||||||
return typeof value === "object" && value !== null
|
|
||||||
}
|
|
||||||
type Primitive = string | number | boolean | undefined | null
|
|
||||||
type AnyFunction = (...args: any[]) => any
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
import { inspect } from "node:util"
|
|
||||||
|
|
||||||
// eslint-disable-next-line import/no-unused-modules
|
|
||||||
export function logPretty(value: unknown) {
|
|
||||||
console.info(
|
|
||||||
inspect(value, {
|
|
||||||
// depth: Number.POSITIVE_INFINITY,
|
|
||||||
depth: 10,
|
|
||||||
colors: true,
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
// eslint-disable-next-line import/no-unused-modules
|
|
||||||
export function omit<Subject extends object, Key extends PropertyKey>(
|
|
||||||
subject: Subject,
|
|
||||||
keys: Key[],
|
|
||||||
// hack: using a conditional type preserves union types
|
|
||||||
): Subject extends any ? Omit<Subject, Key> : never {
|
|
||||||
const result: any = {}
|
|
||||||
for (const key in subject) {
|
|
||||||
if (!keys.includes(key as unknown as Key)) {
|
|
||||||
result[key] = subject[key]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
import type { LoosePick, UnknownRecord } from "./types"
|
|
||||||
|
|
||||||
// eslint-disable-next-line import/no-unused-modules
|
|
||||||
export function pick<T, K extends keyof T | PropertyKey>(
|
|
||||||
object: T,
|
|
||||||
keys: K[],
|
|
||||||
): LoosePick<T, K> {
|
|
||||||
const result: any = {}
|
|
||||||
for (const key of keys) {
|
|
||||||
const value = (object as UnknownRecord)[key]
|
|
||||||
if (value !== undefined) {
|
|
||||||
result[key] = value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
import { isObject } from "./is-object"
|
|
||||||
|
|
||||||
export function pruneNullishValues<T>(input: T): PruneNullishValues<T> {
|
|
||||||
if (Array.isArray(input)) {
|
|
||||||
return input.filter(Boolean).map((item) => pruneNullishValues(item)) as any
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isObject(input)) {
|
|
||||||
return input as any
|
|
||||||
}
|
|
||||||
|
|
||||||
const result: any = {}
|
|
||||||
for (const [key, value] of Object.entries(input)) {
|
|
||||||
if (value != undefined) {
|
|
||||||
result[key] = pruneNullishValues(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
type PruneNullishValues<Input> = Input extends ReadonlyArray<infer Value>
|
|
||||||
? ReadonlyArray<NonNullable<Value>>
|
|
||||||
: Input extends object
|
|
||||||
? {
|
|
||||||
[Key in keyof Input]: NonNullable<Input[Key]>
|
|
||||||
}
|
|
||||||
: Input
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
import { setTimeout } from "node:timers/promises"
|
|
||||||
|
|
||||||
const maxTime = 500
|
|
||||||
const waitPeriod = 50
|
|
||||||
|
|
||||||
export async function retryWithTimeout<T>(
|
|
||||||
callback: () => Promise<T> | T,
|
|
||||||
): Promise<T> {
|
|
||||||
const startTime = Date.now()
|
|
||||||
// eslint-disable-next-line no-constant-condition
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
return await callback()
|
|
||||||
} catch (error) {
|
|
||||||
if (Date.now() - startTime > maxTime) {
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
await setTimeout(waitPeriod)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
export function toError(value: unknown) {
|
|
||||||
return value instanceof Error ? value : new Error(String(value))
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
/* eslint-disable import/no-unused-modules */
|
|
||||||
export type MaybePromise<T> = T | Promise<T>
|
|
||||||
|
|
||||||
export type ValueOf<Type> = Type extends ReadonlyArray<infer Value>
|
|
||||||
? Value
|
|
||||||
: Type[keyof Type]
|
|
||||||
|
|
||||||
export type UnknownRecord = Record<PropertyKey, unknown>
|
|
||||||
|
|
||||||
export type LoosePick<Shape, Keys extends PropertyKey> = {
|
|
||||||
[Key in Keys]: Shape extends Record<Key, infer Value> ? Value : never
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
import { inspect } from "node:util"
|
|
||||||
|
|
||||||
// eslint-disable-next-line import/no-unused-modules
|
|
||||||
export function withLoggedMethodCalls<T extends object>(value: T) {
|
|
||||||
return new Proxy(value as Record<string | symbol, unknown>, {
|
|
||||||
get(target, property) {
|
|
||||||
const value = target[property]
|
|
||||||
if (typeof value !== "function") {
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
return (...values: any[]) => {
|
|
||||||
console.info(
|
|
||||||
`${String(property)}(${values
|
|
||||||
.map((value) =>
|
|
||||||
typeof value === "object" && value !== null
|
|
||||||
? value.constructor.name
|
|
||||||
: inspect(value, { colors: true }),
|
|
||||||
)
|
|
||||||
.join(", ")})`,
|
|
||||||
)
|
|
||||||
return value.apply(target, values)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}) as T
|
|
||||||
}
|
|
||||||
@@ -1,52 +1,60 @@
|
|||||||
import type { ReactNode } from "react"
|
import type { ReactNode } from "react"
|
||||||
import type { ReacordInstance } from "./instance"
|
import type { ReacordInstance } from "./instance"
|
||||||
|
|
||||||
|
/** @category Component Event */
|
||||||
|
export interface ComponentEvent {
|
||||||
/**
|
/**
|
||||||
* @category Component Event
|
* The message associated with this event. For example: with a button click,
|
||||||
*/
|
|
||||||
export type ComponentEvent = {
|
|
||||||
/**
|
|
||||||
* The message associated with this event.
|
|
||||||
* For example: with a button click,
|
|
||||||
* this is the message that the button is on.
|
* this is the message that the button is on.
|
||||||
|
*
|
||||||
* @see https://discord.com/developers/docs/resources/channel#message-object
|
* @see https://discord.com/developers/docs/resources/channel#message-object
|
||||||
*/
|
*/
|
||||||
message: MessageInfo
|
message: ComponentEventMessage
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The channel that this event occurred in.
|
* The channel that this event occurred in.
|
||||||
|
*
|
||||||
* @see https://discord.com/developers/docs/resources/channel#channel-object
|
* @see https://discord.com/developers/docs/resources/channel#channel-object
|
||||||
*/
|
*/
|
||||||
channel: ChannelInfo
|
channel: ComponentEventChannel
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The user that triggered this event.
|
* The user that triggered this event.
|
||||||
|
*
|
||||||
* @see https://discord.com/developers/docs/resources/user#user-object
|
* @see https://discord.com/developers/docs/resources/user#user-object
|
||||||
*/
|
*/
|
||||||
user: UserInfo
|
user: ComponentEventUser
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The guild that this event occurred in.
|
* The guild that this event occurred in.
|
||||||
|
*
|
||||||
* @see https://discord.com/developers/docs/resources/guild#guild-object
|
* @see https://discord.com/developers/docs/resources/guild#guild-object
|
||||||
*/
|
*/
|
||||||
guild?: GuildInfo
|
guild?: ComponentEventGuild
|
||||||
|
|
||||||
|
/** Create a new reply to this event. */
|
||||||
|
reply(
|
||||||
|
content?: ReactNode,
|
||||||
|
options?: ComponentEventReplyOptions,
|
||||||
|
): ReacordInstance
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new reply to this event.
|
* Create an ephemeral reply to this event, shown only to the user who
|
||||||
*/
|
* triggered it.
|
||||||
reply(content?: ReactNode): ReacordInstance
|
*
|
||||||
|
* @deprecated Use event.reply(content, { ephemeral: true })
|
||||||
/**
|
|
||||||
* Create an ephemeral reply to this event,
|
|
||||||
* shown only to the user who triggered it.
|
|
||||||
*/
|
*/
|
||||||
ephemeralReply(content?: ReactNode): ReacordInstance
|
ephemeralReply(content?: ReactNode): ReacordInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @category Component Event */
|
||||||
* @category Component Event
|
export interface ComponentEventReplyOptions {
|
||||||
*/
|
ephemeral?: boolean
|
||||||
export type ChannelInfo = {
|
tts?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @category Component Event */
|
||||||
|
export interface ComponentEventChannel {
|
||||||
id: string
|
id: string
|
||||||
name?: string
|
name?: string
|
||||||
topic?: string
|
topic?: string
|
||||||
@@ -57,14 +65,12 @@ export type ChannelInfo = {
|
|||||||
rateLimitPerUser?: number
|
rateLimitPerUser?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @category Component Event */
|
||||||
* @category Component Event
|
export interface ComponentEventMessage {
|
||||||
*/
|
|
||||||
export type MessageInfo = {
|
|
||||||
id: string
|
id: string
|
||||||
channelId: string
|
channelId: string
|
||||||
authorId: UserInfo
|
authorId: string
|
||||||
member?: GuildMemberInfo
|
member?: ComponentEventGuildMember
|
||||||
content: string
|
content: string
|
||||||
timestamp: string
|
timestamp: string
|
||||||
editedTimestamp?: string
|
editedTimestamp?: string
|
||||||
@@ -74,19 +80,15 @@ export type MessageInfo = {
|
|||||||
mentions: string[]
|
mentions: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @category Component Event */
|
||||||
* @category Component Event
|
export interface ComponentEventGuild {
|
||||||
*/
|
|
||||||
export type GuildInfo = {
|
|
||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
member: GuildMemberInfo
|
member: ComponentEventGuildMember
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @category Component Event */
|
||||||
* @category Component Event
|
export interface ComponentEventGuildMember {
|
||||||
*/
|
|
||||||
export type GuildMemberInfo = {
|
|
||||||
id: string
|
id: string
|
||||||
nick?: string
|
nick?: string
|
||||||
displayName: string
|
displayName: string
|
||||||
@@ -100,14 +102,12 @@ export type GuildMemberInfo = {
|
|||||||
communicationDisabledUntil?: string
|
communicationDisabledUntil?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @category Component Event */
|
||||||
* @category Component Event
|
export interface ComponentEventUser {
|
||||||
*/
|
|
||||||
export type UserInfo = {
|
|
||||||
id: string
|
id: string
|
||||||
username: string
|
username: string
|
||||||
discriminator: string
|
discriminator: string
|
||||||
tag: string
|
tag: string
|
||||||
avatarUrl: string
|
avatarUrl: string | null
|
||||||
accentColor?: number
|
accentColor?: number
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,23 @@
|
|||||||
import type { ReactNode } from "react"
|
import type { ReactNode } from "react"
|
||||||
import React from "react"
|
|
||||||
import { ReacordElement } from "../../internal/element.js"
|
import { ReacordElement } from "../../internal/element.js"
|
||||||
import type { MessageOptions } from "../../internal/message"
|
import type { MessageOptions } from "../../internal/message"
|
||||||
import { Node } from "../../internal/node.js"
|
import { Node } from "../../internal/node.js"
|
||||||
|
import type { ComponentInteraction } from "../../internal/interaction.js"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Props for an action row
|
* Props for an action row
|
||||||
|
*
|
||||||
* @category Action Row
|
* @category Action Row
|
||||||
*/
|
*/
|
||||||
export type ActionRowProps = {
|
export interface ActionRowProps {
|
||||||
children?: ReactNode
|
children?: ReactNode
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An action row is a top-level container for message components.
|
* An action row is a top-level container for message components.
|
||||||
*
|
*
|
||||||
* You don't need to use this; Reacord automatically creates action rows for you.
|
* You don't need to use this; Reacord automatically creates action rows for
|
||||||
* But this can be useful if you want a specific layout.
|
* you. But this can be useful if you want a specific layout.
|
||||||
*
|
*
|
||||||
* ```tsx
|
* ```tsx
|
||||||
* // put buttons on two separate rows
|
* // put buttons on two separate rows
|
||||||
@@ -37,11 +38,19 @@ export function ActionRow(props: ActionRowProps) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
class ActionRowNode extends Node<{}> {
|
class ActionRowNode extends Node<ActionRowProps> {
|
||||||
override modifyMessageOptions(options: MessageOptions): void {
|
override modifyMessageOptions(options: MessageOptions): void {
|
||||||
options.actionRows.push([])
|
options.actionRows.push([])
|
||||||
for (const child of this.children) {
|
for (const child of this.children) {
|
||||||
child.modifyMessageOptions(options)
|
child.modifyMessageOptions(options)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
handleComponentInteraction(interaction: ComponentInteraction) {
|
||||||
|
for (const child of this.children) {
|
||||||
|
if (child.handleComponentInteraction(interaction)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,24 @@
|
|||||||
|
import type { ReactNode } from "react"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common props between button-like components
|
* Common props between button-like components
|
||||||
|
*
|
||||||
* @category Button
|
* @category Button
|
||||||
*/
|
*/
|
||||||
export type ButtonSharedProps = {
|
export interface ButtonSharedProps {
|
||||||
/** The text on the button. Rich formatting (markdown) is not supported here. */
|
/** The text on the button. Rich formatting (markdown) is not supported here. */
|
||||||
label?: string
|
label?: ReactNode
|
||||||
|
|
||||||
/** When true, the button will be slightly faded, and cannot be clicked. */
|
/** When true, the button will be slightly faded, and cannot be clicked. */
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders an emoji to the left of the text.
|
* Renders an emoji to the left of the text. Has to be a literal emoji
|
||||||
* Has to be a literal emoji character (e.g. 🍍),
|
* character (e.g. 🍍), or an emoji code, like
|
||||||
* or an emoji code, like `<:plus_one:778531744860602388>`.
|
* `<:plus_one:778531744860602388>`.
|
||||||
*
|
*
|
||||||
* To get an emoji code, type your emoji in Discord chat
|
* To get an emoji code, type your emoji in Discord chat with a backslash `\`
|
||||||
* with a backslash `\` in front.
|
* in front. The bot has to be in the emoji's guild to use it.
|
||||||
* The bot has to be in the emoji's guild to use it.
|
|
||||||
*/
|
*/
|
||||||
emoji?: string
|
emoji?: string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { nanoid } from "nanoid"
|
import { randomUUID } from "node:crypto"
|
||||||
import React from "react"
|
|
||||||
import { ReacordElement } from "../../internal/element.js"
|
import { ReacordElement } from "../../internal/element.js"
|
||||||
import type { ComponentInteraction } from "../../internal/interaction"
|
import type { ComponentInteraction } from "../../internal/interaction"
|
||||||
import type { MessageOptions } from "../../internal/message"
|
import type { MessageOptions } from "../../internal/message"
|
||||||
@@ -8,38 +7,41 @@ import { Node } from "../../internal/node.js"
|
|||||||
import type { ComponentEvent } from "../component-event"
|
import type { ComponentEvent } from "../component-event"
|
||||||
import type { ButtonSharedProps } from "./button-shared-props"
|
import type { ButtonSharedProps } from "./button-shared-props"
|
||||||
|
|
||||||
/**
|
/** @category Button */
|
||||||
* @category Button
|
|
||||||
*/
|
|
||||||
export type ButtonProps = ButtonSharedProps & {
|
export type ButtonProps = ButtonSharedProps & {
|
||||||
/**
|
/**
|
||||||
* The style determines the color of the button and signals intent.
|
* The style determines the color of the button and signals intent.
|
||||||
|
*
|
||||||
* @see https://discord.com/developers/docs/interactions/message-components#button-object-button-styles
|
* @see https://discord.com/developers/docs/interactions/message-components#button-object-button-styles
|
||||||
*/
|
*/
|
||||||
style?: "primary" | "secondary" | "success" | "danger"
|
style?: "primary" | "secondary" | "success" | "danger"
|
||||||
|
|
||||||
/**
|
/** Happens when a user clicks the button. */
|
||||||
* Happens when a user clicks the button.
|
|
||||||
*/
|
|
||||||
onClick: (event: ButtonClickEvent) => void
|
onClick: (event: ButtonClickEvent) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @category Button */
|
||||||
* @category Button
|
|
||||||
*/
|
|
||||||
export type ButtonClickEvent = ComponentEvent
|
export type ButtonClickEvent = ComponentEvent
|
||||||
|
|
||||||
/**
|
/** @category Button */
|
||||||
* @category Button
|
|
||||||
*/
|
|
||||||
export function Button(props: ButtonProps) {
|
export function Button(props: ButtonProps) {
|
||||||
return (
|
return (
|
||||||
<ReacordElement props={props} createNode={() => new ButtonNode(props)} />
|
<ReacordElement props={props} createNode={() => new ButtonNode(props)}>
|
||||||
|
<ReacordElement props={{}} createNode={() => new ButtonLabelNode({})}>
|
||||||
|
{props.label}
|
||||||
|
</ReacordElement>
|
||||||
|
</ReacordElement>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
class ButtonNode extends Node<ButtonProps> {
|
class ButtonNode extends Node<ButtonProps> {
|
||||||
private customId = nanoid()
|
private customId = randomUUID()
|
||||||
|
|
||||||
|
// this has text children, but buttons themselves shouldn't yield text
|
||||||
|
// eslint-disable-next-line @typescript-eslint/class-literal-property-style
|
||||||
|
override get text() {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
override modifyMessageOptions(options: MessageOptions): void {
|
override modifyMessageOptions(options: MessageOptions): void {
|
||||||
getNextActionRow(options).push({
|
getNextActionRow(options).push({
|
||||||
@@ -48,7 +50,7 @@ class ButtonNode extends Node<ButtonProps> {
|
|||||||
style: this.props.style ?? "secondary",
|
style: this.props.style ?? "secondary",
|
||||||
disabled: this.props.disabled,
|
disabled: this.props.disabled,
|
||||||
emoji: this.props.emoji,
|
emoji: this.props.emoji,
|
||||||
label: this.props.label,
|
label: this.children.findType(ButtonLabelNode)?.text,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,3 +65,5 @@ class ButtonNode extends Node<ButtonProps> {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ButtonLabelNode extends Node<Record<string, never>> {}
|
||||||
|
|||||||
@@ -1,36 +1,36 @@
|
|||||||
import React from "react"
|
import type { ReactNode } from "react"
|
||||||
import { ReacordElement } from "../../internal/element.js"
|
import { ReacordElement } from "../../internal/element.js"
|
||||||
|
import { Node } from "../../internal/node.js"
|
||||||
import { EmbedChildNode } from "./embed-child.js"
|
import { EmbedChildNode } from "./embed-child.js"
|
||||||
import type { EmbedOptions } from "./embed-options"
|
import type { EmbedOptions } from "./embed-options"
|
||||||
|
|
||||||
/**
|
/** @category Embed */
|
||||||
* @category Embed
|
export interface EmbedAuthorProps {
|
||||||
*/
|
name?: ReactNode
|
||||||
export type EmbedAuthorProps = {
|
children?: ReactNode
|
||||||
name?: string
|
|
||||||
children?: string
|
|
||||||
url?: string
|
url?: string
|
||||||
iconUrl?: string
|
iconUrl?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @category Embed */
|
||||||
* @category Embed
|
|
||||||
*/
|
|
||||||
export function EmbedAuthor(props: EmbedAuthorProps) {
|
export function EmbedAuthor(props: EmbedAuthorProps) {
|
||||||
return (
|
return (
|
||||||
<ReacordElement
|
<ReacordElement props={props} createNode={() => new EmbedAuthorNode(props)}>
|
||||||
props={props}
|
<ReacordElement props={{}} createNode={() => new AuthorTextNode({})}>
|
||||||
createNode={() => new EmbedAuthorNode(props)}
|
{props.name ?? props.children}
|
||||||
/>
|
</ReacordElement>
|
||||||
|
</ReacordElement>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
class EmbedAuthorNode extends EmbedChildNode<EmbedAuthorProps> {
|
class EmbedAuthorNode extends EmbedChildNode<EmbedAuthorProps> {
|
||||||
override modifyEmbedOptions(options: EmbedOptions): void {
|
override modifyEmbedOptions(options: EmbedOptions): void {
|
||||||
options.author = {
|
options.author = {
|
||||||
name: this.props.name ?? this.props.children ?? "",
|
name: this.children.findType(AuthorTextNode)?.text ?? "",
|
||||||
url: this.props.url,
|
url: this.props.url,
|
||||||
icon_url: this.props.iconUrl,
|
icon_url: this.props.iconUrl,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class AuthorTextNode extends Node<Record<string, never>> {}
|
||||||
|
|||||||
@@ -1,27 +1,28 @@
|
|||||||
import React from "react"
|
import type { ReactNode } from "react"
|
||||||
import { ReacordElement } from "../../internal/element.js"
|
import { ReacordElement } from "../../internal/element.js"
|
||||||
|
import { Node } from "../../internal/node.js"
|
||||||
import { EmbedChildNode } from "./embed-child.js"
|
import { EmbedChildNode } from "./embed-child.js"
|
||||||
import type { EmbedOptions } from "./embed-options"
|
import type { EmbedOptions } from "./embed-options"
|
||||||
|
|
||||||
/**
|
/** @category Embed */
|
||||||
* @category Embed
|
export interface EmbedFieldProps {
|
||||||
*/
|
name: ReactNode
|
||||||
export type EmbedFieldProps = {
|
value?: ReactNode
|
||||||
name: string
|
|
||||||
value?: string
|
|
||||||
inline?: boolean
|
inline?: boolean
|
||||||
children?: string
|
children?: ReactNode
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @category Embed */
|
||||||
* @category Embed
|
|
||||||
*/
|
|
||||||
export function EmbedField(props: EmbedFieldProps) {
|
export function EmbedField(props: EmbedFieldProps) {
|
||||||
return (
|
return (
|
||||||
<ReacordElement
|
<ReacordElement props={props} createNode={() => new EmbedFieldNode(props)}>
|
||||||
props={props}
|
<ReacordElement props={{}} createNode={() => new FieldNameNode({})}>
|
||||||
createNode={() => new EmbedFieldNode(props)}
|
{props.name}
|
||||||
/>
|
</ReacordElement>
|
||||||
|
<ReacordElement props={{}} createNode={() => new FieldValueNode({})}>
|
||||||
|
{props.value ?? props.children}
|
||||||
|
</ReacordElement>
|
||||||
|
</ReacordElement>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,9 +30,12 @@ class EmbedFieldNode extends EmbedChildNode<EmbedFieldProps> {
|
|||||||
override modifyEmbedOptions(options: EmbedOptions): void {
|
override modifyEmbedOptions(options: EmbedOptions): void {
|
||||||
options.fields ??= []
|
options.fields ??= []
|
||||||
options.fields.push({
|
options.fields.push({
|
||||||
name: this.props.name,
|
name: this.children.findType(FieldNameNode)?.text ?? "",
|
||||||
value: this.props.value ?? this.props.children ?? "",
|
value: this.children.findType(FieldValueNode)?.text ?? "",
|
||||||
inline: this.props.inline,
|
inline: this.props.inline,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class FieldNameNode extends Node<Record<string, never>> {}
|
||||||
|
class FieldValueNode extends Node<Record<string, never>> {}
|
||||||
|
|||||||
@@ -1,34 +1,34 @@
|
|||||||
import React from "react"
|
import type { ReactNode } from "react"
|
||||||
import { ReacordElement } from "../../internal/element.js"
|
import { ReacordElement } from "../../internal/element.js"
|
||||||
|
import { Node } from "../../internal/node.js"
|
||||||
import { EmbedChildNode } from "./embed-child.js"
|
import { EmbedChildNode } from "./embed-child.js"
|
||||||
import type { EmbedOptions } from "./embed-options"
|
import type { EmbedOptions } from "./embed-options"
|
||||||
|
|
||||||
/**
|
/** @category Embed */
|
||||||
* @category Embed
|
export interface EmbedFooterProps {
|
||||||
*/
|
text?: ReactNode
|
||||||
export type EmbedFooterProps = {
|
children?: ReactNode
|
||||||
text?: string
|
|
||||||
children?: string
|
|
||||||
iconUrl?: string
|
iconUrl?: string
|
||||||
timestamp?: string | number | Date
|
timestamp?: string | number | Date
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @category Embed */
|
||||||
* @category Embed
|
export function EmbedFooter({ text, children, ...props }: EmbedFooterProps) {
|
||||||
*/
|
|
||||||
export function EmbedFooter(props: EmbedFooterProps) {
|
|
||||||
return (
|
return (
|
||||||
<ReacordElement
|
<ReacordElement props={props} createNode={() => new EmbedFooterNode(props)}>
|
||||||
props={props}
|
<ReacordElement props={{}} createNode={() => new FooterTextNode({})}>
|
||||||
createNode={() => new EmbedFooterNode(props)}
|
{text ?? children}
|
||||||
/>
|
</ReacordElement>
|
||||||
|
</ReacordElement>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
class EmbedFooterNode extends EmbedChildNode<EmbedFooterProps> {
|
class EmbedFooterNode extends EmbedChildNode<
|
||||||
|
Omit<EmbedFooterProps, "text" | "children">
|
||||||
|
> {
|
||||||
override modifyEmbedOptions(options: EmbedOptions): void {
|
override modifyEmbedOptions(options: EmbedOptions): void {
|
||||||
options.footer = {
|
options.footer = {
|
||||||
text: this.props.text ?? this.props.children ?? "",
|
text: this.children.findType(FooterTextNode)?.text ?? "",
|
||||||
icon_url: this.props.iconUrl,
|
icon_url: this.props.iconUrl,
|
||||||
}
|
}
|
||||||
options.timestamp = this.props.timestamp
|
options.timestamp = this.props.timestamp
|
||||||
@@ -36,3 +36,5 @@ class EmbedFooterNode extends EmbedChildNode<EmbedFooterProps> {
|
|||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class FooterTextNode extends Node<Record<string, never>> {}
|
||||||
|
|||||||
@@ -1,18 +1,13 @@
|
|||||||
import React from "react"
|
|
||||||
import { ReacordElement } from "../../internal/element.js"
|
import { ReacordElement } from "../../internal/element.js"
|
||||||
import { EmbedChildNode } from "./embed-child.js"
|
import { EmbedChildNode } from "./embed-child.js"
|
||||||
import type { EmbedOptions } from "./embed-options"
|
import type { EmbedOptions } from "./embed-options"
|
||||||
|
|
||||||
/**
|
/** @category Embed */
|
||||||
* @category Embed
|
export interface EmbedImageProps {
|
||||||
*/
|
|
||||||
export type EmbedImageProps = {
|
|
||||||
url: string
|
url: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @category Embed */
|
||||||
* @category Embed
|
|
||||||
*/
|
|
||||||
export function EmbedImage(props: EmbedImageProps) {
|
export function EmbedImage(props: EmbedImageProps) {
|
||||||
return (
|
return (
|
||||||
<ReacordElement
|
<ReacordElement
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { Except, SnakeCasedPropertiesDeep } from "type-fest"
|
|
||||||
import type { EmbedProps } from "./embed"
|
import type { EmbedProps } from "./embed"
|
||||||
|
import type { Except, SnakeCasedPropertiesDeep } from "type-fest"
|
||||||
|
|
||||||
export type EmbedOptions = SnakeCasedPropertiesDeep<
|
export type EmbedOptions = SnakeCasedPropertiesDeep<
|
||||||
Except<EmbedProps, "timestamp" | "children"> & {
|
Except<EmbedProps, "timestamp" | "children"> & {
|
||||||
|
|||||||
@@ -1,18 +1,13 @@
|
|||||||
import React from "react"
|
|
||||||
import { ReacordElement } from "../../internal/element.js"
|
import { ReacordElement } from "../../internal/element.js"
|
||||||
import { EmbedChildNode } from "./embed-child.js"
|
import { EmbedChildNode } from "./embed-child.js"
|
||||||
import type { EmbedOptions } from "./embed-options"
|
import type { EmbedOptions } from "./embed-options"
|
||||||
|
|
||||||
/**
|
/** @category Embed */
|
||||||
* @category Embed
|
export interface EmbedThumbnailProps {
|
||||||
*/
|
|
||||||
export type EmbedThumbnailProps = {
|
|
||||||
url: string
|
url: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @category Embed */
|
||||||
* @category Embed
|
|
||||||
*/
|
|
||||||
export function EmbedThumbnail(props: EmbedThumbnailProps) {
|
export function EmbedThumbnail(props: EmbedThumbnailProps) {
|
||||||
return (
|
return (
|
||||||
<ReacordElement
|
<ReacordElement
|
||||||
|
|||||||
@@ -1,31 +1,31 @@
|
|||||||
import React from "react"
|
import type { ReactNode } from "react"
|
||||||
import { ReacordElement } from "../../internal/element.js"
|
import { ReacordElement } from "../../internal/element.js"
|
||||||
|
import { Node } from "../../internal/node.js"
|
||||||
import { EmbedChildNode } from "./embed-child.js"
|
import { EmbedChildNode } from "./embed-child.js"
|
||||||
import type { EmbedOptions } from "./embed-options"
|
import type { EmbedOptions } from "./embed-options"
|
||||||
|
|
||||||
/**
|
/** @category Embed */
|
||||||
* @category Embed
|
export interface EmbedTitleProps {
|
||||||
*/
|
children: ReactNode
|
||||||
export type EmbedTitleProps = {
|
|
||||||
children: string
|
|
||||||
url?: string
|
url?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @category Embed */
|
||||||
* @category Embed
|
export function EmbedTitle({ children, ...props }: EmbedTitleProps) {
|
||||||
*/
|
|
||||||
export function EmbedTitle(props: EmbedTitleProps) {
|
|
||||||
return (
|
return (
|
||||||
<ReacordElement
|
<ReacordElement props={props} createNode={() => new EmbedTitleNode(props)}>
|
||||||
props={props}
|
<ReacordElement props={{}} createNode={() => new TitleTextNode({})}>
|
||||||
createNode={() => new EmbedTitleNode(props)}
|
{children}
|
||||||
/>
|
</ReacordElement>
|
||||||
|
</ReacordElement>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
class EmbedTitleNode extends EmbedChildNode<EmbedTitleProps> {
|
class EmbedTitleNode extends EmbedChildNode<Omit<EmbedTitleProps, "children">> {
|
||||||
override modifyEmbedOptions(options: EmbedOptions): void {
|
override modifyEmbedOptions(options: EmbedOptions): void {
|
||||||
options.title = this.props.children
|
options.title = this.children.findType(TitleTextNode)?.text ?? ""
|
||||||
options.url = this.props.url
|
options.url = this.props.url
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TitleTextNode extends Node<Record<string, never>> {}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React from "react"
|
import { snakeCaseDeep } from "@reacord/helpers/convert-object-property-case"
|
||||||
import { snakeCaseDeep } from "../../../helpers/convert-object-property-case"
|
import { omit } from "@reacord/helpers/omit"
|
||||||
import { omit } from "../../../helpers/omit"
|
import type React from "react"
|
||||||
import { ReacordElement } from "../../internal/element.js"
|
import { ReacordElement } from "../../internal/element.js"
|
||||||
import type { MessageOptions } from "../../internal/message"
|
import type { MessageOptions } from "../../internal/message"
|
||||||
import { Node } from "../../internal/node.js"
|
import { Node } from "../../internal/node.js"
|
||||||
@@ -12,7 +12,7 @@ import type { EmbedOptions } from "./embed-options"
|
|||||||
* @category Embed
|
* @category Embed
|
||||||
* @see https://discord.com/developers/docs/resources/channel#embed-object
|
* @see https://discord.com/developers/docs/resources/channel#embed-object
|
||||||
*/
|
*/
|
||||||
export type EmbedProps = {
|
export interface EmbedProps {
|
||||||
title?: string
|
title?: string
|
||||||
description?: string
|
description?: string
|
||||||
url?: string
|
url?: string
|
||||||
@@ -53,7 +53,7 @@ class EmbedNode extends Node<EmbedProps> {
|
|||||||
child.modifyEmbedOptions(embed)
|
child.modifyEmbedOptions(embed)
|
||||||
}
|
}
|
||||||
if (child instanceof TextNode) {
|
if (child instanceof TextNode) {
|
||||||
embed.description = (embed.description || "") + child.props
|
embed.description = (embed.description ?? "") + child.props
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
import React from "react"
|
|
||||||
import { ReacordElement } from "../../internal/element.js"
|
import { ReacordElement } from "../../internal/element.js"
|
||||||
import type { MessageOptions } from "../../internal/message"
|
import type { MessageOptions } from "../../internal/message"
|
||||||
import { getNextActionRow } from "../../internal/message"
|
import { getNextActionRow } from "../../internal/message"
|
||||||
import { Node } from "../../internal/node.js"
|
import { Node } from "../../internal/node.js"
|
||||||
import type { ButtonSharedProps } from "./button-shared-props"
|
import type { ButtonSharedProps } from "./button-shared-props"
|
||||||
|
|
||||||
/**
|
/** @category Link */
|
||||||
* @category Link
|
|
||||||
*/
|
|
||||||
export type LinkProps = ButtonSharedProps & {
|
export type LinkProps = ButtonSharedProps & {
|
||||||
/** The URL the link should lead to */
|
/** The URL the link should lead to */
|
||||||
url: string
|
url: string
|
||||||
@@ -15,21 +12,27 @@ export type LinkProps = ButtonSharedProps & {
|
|||||||
children?: string
|
children?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @category Link */
|
||||||
* @category Link
|
export function Link({ label, children, ...props }: LinkProps) {
|
||||||
*/
|
return (
|
||||||
export function Link(props: LinkProps) {
|
<ReacordElement props={props} createNode={() => new LinkNode(props)}>
|
||||||
return <ReacordElement props={props} createNode={() => new LinkNode(props)} />
|
<ReacordElement props={{}} createNode={() => new LinkTextNode({})}>
|
||||||
|
{label ?? children}
|
||||||
|
</ReacordElement>
|
||||||
|
</ReacordElement>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
class LinkNode extends Node<LinkProps> {
|
class LinkNode extends Node<Omit<LinkProps, "label" | "children">> {
|
||||||
override modifyMessageOptions(options: MessageOptions): void {
|
override modifyMessageOptions(options: MessageOptions): void {
|
||||||
getNextActionRow(options).push({
|
getNextActionRow(options).push({
|
||||||
type: "link",
|
type: "link",
|
||||||
disabled: this.props.disabled,
|
disabled: this.props.disabled,
|
||||||
emoji: this.props.emoji,
|
emoji: this.props.emoji,
|
||||||
label: this.props.label || this.props.children,
|
label: this.children.findType(LinkTextNode)?.text,
|
||||||
url: this.props.url,
|
url: this.props.url,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class LinkTextNode extends Node<Record<string, never>> {}
|
||||||
|
|||||||
@@ -2,13 +2,18 @@ import type { MessageSelectOptionOptions } from "../../internal/message"
|
|||||||
import { Node } from "../../internal/node"
|
import { Node } from "../../internal/node"
|
||||||
import type { OptionProps } from "./option"
|
import type { OptionProps } from "./option"
|
||||||
|
|
||||||
export class OptionNode extends Node<OptionProps> {
|
export class OptionNode extends Node<
|
||||||
|
Omit<OptionProps, "children" | "label" | "description">
|
||||||
|
> {
|
||||||
get options(): MessageSelectOptionOptions {
|
get options(): MessageSelectOptionOptions {
|
||||||
return {
|
return {
|
||||||
label: this.props.children || this.props.label || this.props.value,
|
label: this.children.findType(OptionLabelNode)?.text ?? this.props.value,
|
||||||
value: this.props.value,
|
value: this.props.value,
|
||||||
description: this.props.description,
|
description: this.children.findType(OptionDescriptionNode)?.text,
|
||||||
emoji: this.props.emoji,
|
emoji: this.props.emoji,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class OptionLabelNode extends Node<Record<string, never>> {}
|
||||||
|
export class OptionDescriptionNode extends Node<Record<string, never>> {}
|
||||||
|
|||||||
@@ -1,38 +1,56 @@
|
|||||||
import React from "react"
|
import type { ReactNode } from "react"
|
||||||
import { ReacordElement } from "../../internal/element"
|
import { ReacordElement } from "../../internal/element"
|
||||||
import { OptionNode } from "./option-node"
|
import {
|
||||||
|
OptionDescriptionNode,
|
||||||
|
OptionLabelNode,
|
||||||
|
OptionNode,
|
||||||
|
} from "./option-node"
|
||||||
|
|
||||||
/**
|
/** @category Select */
|
||||||
* @category Select
|
export interface OptionProps {
|
||||||
*/
|
|
||||||
export type OptionProps = {
|
|
||||||
/** The internal value of this option */
|
/** The internal value of this option */
|
||||||
value: string
|
value: string
|
||||||
/** The text shown to the user. This takes priority over `children` */
|
/** The text shown to the user. This takes priority over `children` */
|
||||||
label?: string
|
label?: ReactNode
|
||||||
/** The text shown to the user */
|
/** The text shown to the user */
|
||||||
children?: string
|
children?: ReactNode
|
||||||
/** Description for the option, shown to the user */
|
/** Description for the option, shown to the user */
|
||||||
description?: string
|
description?: ReactNode
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders an emoji to the left of the text.
|
* Renders an emoji to the left of the text.
|
||||||
*
|
*
|
||||||
* Has to be a literal emoji character (e.g. 🍍),
|
* Has to be a literal emoji character (e.g. 🍍), or an emoji code, like
|
||||||
* or an emoji code, like `<:plus_one:778531744860602388>`.
|
* `<:plus_one:778531744860602388>`.
|
||||||
*
|
*
|
||||||
* To get an emoji code, type your emoji in Discord chat
|
* To get an emoji code, type your emoji in Discord chat with a backslash `\`
|
||||||
* with a backslash `\` in front.
|
* in front. The bot has to be in the emoji's guild to use it.
|
||||||
* The bot has to be in the emoji's guild to use it.
|
|
||||||
*/
|
*/
|
||||||
emoji?: string
|
emoji?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @category Select */
|
||||||
* @category Select
|
export function Option({
|
||||||
*/
|
label,
|
||||||
export function Option(props: OptionProps) {
|
children,
|
||||||
|
description,
|
||||||
|
...props
|
||||||
|
}: OptionProps) {
|
||||||
return (
|
return (
|
||||||
<ReacordElement props={props} createNode={() => new OptionNode(props)} />
|
<ReacordElement props={props} createNode={() => new OptionNode(props)}>
|
||||||
|
{(label !== undefined || children !== undefined) && (
|
||||||
|
<ReacordElement props={{}} createNode={() => new OptionLabelNode({})}>
|
||||||
|
{label ?? children}
|
||||||
|
</ReacordElement>
|
||||||
|
)}
|
||||||
|
{description !== undefined && (
|
||||||
|
<ReacordElement
|
||||||
|
props={{}}
|
||||||
|
createNode={() => new OptionDescriptionNode({})}
|
||||||
|
>
|
||||||
|
{description}
|
||||||
|
</ReacordElement>
|
||||||
|
)}
|
||||||
|
</ReacordElement>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { nanoid } from "nanoid"
|
import { isInstanceOf } from "@reacord/helpers/is-instance-of"
|
||||||
|
import { randomUUID } from "node:crypto"
|
||||||
import type { ReactNode } from "react"
|
import type { ReactNode } from "react"
|
||||||
import React from "react"
|
|
||||||
import { isInstanceOf } from "../../../helpers/is-instance-of"
|
|
||||||
import { ReacordElement } from "../../internal/element.js"
|
import { ReacordElement } from "../../internal/element.js"
|
||||||
import type { ComponentInteraction } from "../../internal/interaction"
|
import type { ComponentInteraction } from "../../internal/interaction"
|
||||||
import type {
|
import type {
|
||||||
@@ -12,11 +11,17 @@ import type {
|
|||||||
import { Node } from "../../internal/node.js"
|
import { Node } from "../../internal/node.js"
|
||||||
import type { ComponentEvent } from "../component-event"
|
import type { ComponentEvent } from "../component-event"
|
||||||
import { OptionNode } from "./option-node"
|
import { OptionNode } from "./option-node"
|
||||||
|
import { omit } from "@reacord/helpers/omit.js"
|
||||||
|
|
||||||
/**
|
export type SelectMenuType =
|
||||||
* @category Select
|
| "string"
|
||||||
*/
|
| "user"
|
||||||
export type SelectProps = {
|
| "role"
|
||||||
|
| "mentionable"
|
||||||
|
| "channel"
|
||||||
|
|
||||||
|
/** @category Select */
|
||||||
|
export interface SelectProps {
|
||||||
children?: ReactNode
|
children?: ReactNode
|
||||||
/** Sets the currently selected value */
|
/** Sets the currently selected value */
|
||||||
value?: string
|
value?: string
|
||||||
@@ -27,12 +32,26 @@ export type SelectProps = {
|
|||||||
/** The text shown when no value is selected */
|
/** The text shown when no value is selected */
|
||||||
placeholder?: string
|
placeholder?: string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The kind of select menu to render.
|
||||||
|
*
|
||||||
|
* Defaults to `string`.
|
||||||
|
*/
|
||||||
|
menuType?: SelectMenuType
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Limit the channel types shown in a channel select menu.
|
||||||
|
*
|
||||||
|
* This is only used when `menuType` is `channel`.
|
||||||
|
*/
|
||||||
|
channelTypes?: number[]
|
||||||
|
|
||||||
/** Set to true to allow multiple selected values */
|
/** Set to true to allow multiple selected values */
|
||||||
multiple?: boolean
|
multiple?: boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* With `multiple`, the minimum number of values that can be selected.
|
* With `multiple`, the minimum number of values that can be selected. When
|
||||||
* When `multiple` is false or not defined, this is always 1.
|
* `multiple` is false or not defined, this is always 1.
|
||||||
*
|
*
|
||||||
* This only limits the number of values that can be received by the user.
|
* This only limits the number of values that can be received by the user.
|
||||||
* This does not limit the number of values that can be displayed by you.
|
* This does not limit the number of values that can be displayed by you.
|
||||||
@@ -40,44 +59,44 @@ export type SelectProps = {
|
|||||||
minValues?: number
|
minValues?: number
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* With `multiple`, the maximum number of values that can be selected.
|
* With `multiple`, the maximum number of values that can be selected. When
|
||||||
* When `multiple` is false or not defined, this is always 1.
|
* `multiple` is false or not defined, this is always 1.
|
||||||
*
|
*
|
||||||
* This only limits the number of values that can be received by the user.
|
* This only limits the number of values that can be received by the user.
|
||||||
* This does not limit the number of values that can be displayed by you.
|
* This does not limit the number of values that can be displayed by you.
|
||||||
*/
|
*/
|
||||||
maxValues?: number
|
maxValues?: number
|
||||||
|
|
||||||
/** When true, the select will be slightly faded, and cannot be interacted with. */
|
/**
|
||||||
|
* When true, the select will be slightly faded, and cannot be interacted
|
||||||
|
* with.
|
||||||
|
*/
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the user inputs a selection.
|
* Called when the user inputs a selection. Receives the entire select change
|
||||||
* Receives the entire select change event,
|
* event, which can be used to create new replies, etc.
|
||||||
* which can be used to create new replies, etc.
|
|
||||||
*/
|
*/
|
||||||
onChange?: (event: SelectChangeEvent) => void
|
onChange?: (event: SelectChangeEvent) => void
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience shorthand for `onChange`, which receives the first selected value.
|
* Convenience shorthand for `onChange`, which receives the first selected
|
||||||
|
* value.
|
||||||
*/
|
*/
|
||||||
onChangeValue?: (value: string, event: SelectChangeEvent) => void
|
onChangeValue?: (value: string, event: SelectChangeEvent) => void
|
||||||
|
|
||||||
/**
|
/** Convenience shorthand for `onChange`, which receives all selected values. */
|
||||||
* Convenience shorthand for `onChange`, which receives all selected values.
|
|
||||||
*/
|
|
||||||
onChangeMultiple?: (values: string[], event: SelectChangeEvent) => void
|
onChangeMultiple?: (values: string[], event: SelectChangeEvent) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @category Select */
|
||||||
* @category Select
|
|
||||||
*/
|
|
||||||
export type SelectChangeEvent = ComponentEvent & {
|
export type SelectChangeEvent = ComponentEvent & {
|
||||||
values: string[]
|
values: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See [the select menu guide](/guides/select-menu) for a usage example.
|
* See [the select menu guide](/guides/select-menu) for a usage example.
|
||||||
|
*
|
||||||
* @category Select
|
* @category Select
|
||||||
*/
|
*/
|
||||||
export function Select(props: SelectProps) {
|
export function Select(props: SelectProps) {
|
||||||
@@ -89,7 +108,7 @@ export function Select(props: SelectProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class SelectNode extends Node<SelectProps> {
|
class SelectNode extends Node<SelectProps> {
|
||||||
readonly customId = nanoid()
|
readonly customId = randomUUID()
|
||||||
|
|
||||||
override modifyMessageOptions(message: MessageOptions): void {
|
override modifyMessageOptions(message: MessageOptions): void {
|
||||||
const actionRow: ActionRow = []
|
const actionRow: ActionRow = []
|
||||||
@@ -105,12 +124,13 @@ class SelectNode extends Node<SelectProps> {
|
|||||||
values,
|
values,
|
||||||
minValues = 0,
|
minValues = 0,
|
||||||
maxValues = 25,
|
maxValues = 25,
|
||||||
children,
|
|
||||||
onChange,
|
|
||||||
onChangeValue,
|
|
||||||
onChangeMultiple,
|
|
||||||
...props
|
...props
|
||||||
} = this.props
|
} = omit(this.props, [
|
||||||
|
"children",
|
||||||
|
"onChange",
|
||||||
|
"onChangeValue",
|
||||||
|
"onChangeMultiple",
|
||||||
|
])
|
||||||
|
|
||||||
const item: ActionRowItem = {
|
const item: ActionRowItem = {
|
||||||
...props,
|
...props,
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
|
import type { ReacordInstance } from "./instance.js"
|
||||||
|
import { raise } from "@reacord/helpers/raise.js"
|
||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
import { raise } from "../../helpers/raise"
|
import type { MessageStore } from "../internal/message-store.js"
|
||||||
import type { ReacordInstance } from "./instance"
|
|
||||||
|
|
||||||
const Context = React.createContext<ReacordInstance | undefined>(undefined)
|
const Context = React.createContext<ReacordInstance | undefined>(undefined)
|
||||||
|
const MessageContext = React.createContext<MessageStore | undefined>(undefined)
|
||||||
|
|
||||||
export const InstanceProvider = Context.Provider
|
export const InstanceProvider = Context.Provider
|
||||||
|
export const MessageProvider = MessageContext.Provider
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the associated instance for the current component.
|
* Get the associated instance for the current component.
|
||||||
*
|
*
|
||||||
* @category Core
|
* @category Core
|
||||||
* @see https://reacord.fly.dev/guides/use-instance
|
* @see https://reacord.mapleleaf.dev/guides/use-instance
|
||||||
*/
|
*/
|
||||||
export function useInstance(): ReacordInstance {
|
export function useInstance(): ReacordInstance {
|
||||||
return (
|
return (
|
||||||
@@ -18,3 +21,27 @@ export function useInstance(): ReacordInstance {
|
|||||||
raise("Could not find instance, was this component rendered via Reacord?")
|
raise("Could not find instance, was this component rendered via Reacord?")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the message that the current component is rendered into.
|
||||||
|
*
|
||||||
|
* @category Core
|
||||||
|
*/
|
||||||
|
export function useMessage() {
|
||||||
|
const store =
|
||||||
|
React.useContext(MessageContext) ??
|
||||||
|
raise("Could not find message store, was this component rendered via Reacord?")
|
||||||
|
|
||||||
|
const getSnapshot = React.useCallback(() => store.getSnapshot(), [store])
|
||||||
|
|
||||||
|
if (React.useSyncExternalStore) {
|
||||||
|
return React.useSyncExternalStore(store.subscribe, getSnapshot, getSnapshot)
|
||||||
|
}
|
||||||
|
|
||||||
|
const [value, setValue] = React.useState(getSnapshot)
|
||||||
|
React.useEffect(() => store.subscribe(() => setValue(getSnapshot())), [
|
||||||
|
store,
|
||||||
|
getSnapshot,
|
||||||
|
])
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,11 +2,12 @@ import type { ReactNode } from "react"
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an interactive message, which can later be replaced or deleted.
|
* Represents an interactive message, which can later be replaced or deleted.
|
||||||
|
*
|
||||||
* @category Core
|
* @category Core
|
||||||
*/
|
*/
|
||||||
export type ReacordInstance = {
|
export interface ReacordInstance {
|
||||||
/** Render some JSX to this instance (edits the message) */
|
/** Render some JSX to this instance (edits the message) */
|
||||||
render: (content: ReactNode) => void
|
render: (content: ReactNode) => ReacordInstance
|
||||||
|
|
||||||
/** Remove this message */
|
/** Remove this message */
|
||||||
destroy: () => void
|
destroy: () => void
|
||||||
|
|||||||
@@ -1,21 +1,25 @@
|
|||||||
/* eslint-disable class-methods-use-this */
|
import { safeJsonStringify } from "@reacord/helpers/json"
|
||||||
|
import { pick } from "@reacord/helpers/pick"
|
||||||
|
import { pruneNullishValues } from "@reacord/helpers/prune-nullish-values"
|
||||||
|
import { raise } from "@reacord/helpers/raise"
|
||||||
import * as Discord from "discord.js"
|
import * as Discord from "discord.js"
|
||||||
import type { ReactNode } from "react"
|
import type { ReactNode } from "react"
|
||||||
import type { Except } from "type-fest"
|
import type { Except } from "type-fest"
|
||||||
import { pick } from "../../helpers/pick"
|
|
||||||
import { pruneNullishValues } from "../../helpers/prune-nullish-values"
|
|
||||||
import { raise } from "../../helpers/raise"
|
|
||||||
import { toUpper } from "../../helpers/to-upper"
|
|
||||||
import type { ComponentInteraction } from "../internal/interaction"
|
import type { ComponentInteraction } from "../internal/interaction"
|
||||||
import type { Message, MessageOptions } from "../internal/message"
|
import type {
|
||||||
|
Message,
|
||||||
|
MessageButtonOptions,
|
||||||
|
MessageOptions,
|
||||||
|
} from "../internal/message"
|
||||||
import { ChannelMessageRenderer } from "../internal/renderers/channel-message-renderer"
|
import { ChannelMessageRenderer } from "../internal/renderers/channel-message-renderer"
|
||||||
import { InteractionReplyRenderer } from "../internal/renderers/interaction-reply-renderer"
|
import { InteractionReplyRenderer } from "../internal/renderers/interaction-reply-renderer"
|
||||||
import type {
|
import type {
|
||||||
ChannelInfo,
|
ComponentEventChannel,
|
||||||
GuildInfo,
|
ComponentEventGuild,
|
||||||
GuildMemberInfo,
|
ComponentEventGuildMember,
|
||||||
MessageInfo,
|
ComponentEventMessage,
|
||||||
UserInfo,
|
ComponentEventReplyOptions,
|
||||||
|
ComponentEventUser,
|
||||||
} from "./component-event"
|
} from "./component-event"
|
||||||
import type { ReacordInstance } from "./instance"
|
import type { ReacordInstance } from "./instance"
|
||||||
import type { ReacordConfig } from "./reacord"
|
import type { ReacordConfig } from "./reacord"
|
||||||
@@ -23,14 +27,18 @@ import { Reacord } from "./reacord"
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The Reacord adapter for Discord.js.
|
* The Reacord adapter for Discord.js.
|
||||||
|
*
|
||||||
* @category Core
|
* @category Core
|
||||||
*/
|
*/
|
||||||
export class ReacordDiscordJs extends Reacord {
|
export class ReacordDiscordJs extends Reacord {
|
||||||
constructor(private client: Discord.Client, config: ReacordConfig = {}) {
|
constructor(
|
||||||
|
private client: Discord.Client,
|
||||||
|
config: ReacordConfig = {},
|
||||||
|
) {
|
||||||
super(config)
|
super(config)
|
||||||
|
|
||||||
client.on("interactionCreate", (interaction) => {
|
client.on("interactionCreate", (interaction) => {
|
||||||
if (interaction.isMessageComponent()) {
|
if (interaction.isButton() || interaction.isAnySelectMenu()) {
|
||||||
this.handleComponentInteraction(
|
this.handleComponentInteraction(
|
||||||
this.createReacordComponentInteraction(interaction),
|
this.createReacordComponentInteraction(interaction),
|
||||||
)
|
)
|
||||||
@@ -40,59 +48,118 @@ export class ReacordDiscordJs extends Reacord {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a message to a channel.
|
* Sends a message to a channel.
|
||||||
* @see https://reacord.fly.dev/guides/sending-messages
|
*
|
||||||
|
* @param target Discord channel object.
|
||||||
|
* @param [options] Options for the channel message
|
||||||
|
* @see https://reacord.mapleleaf.dev/guides/sending-messages
|
||||||
|
* @see {@link Discord.MessageCreateOptions}
|
||||||
*/
|
*/
|
||||||
override send(
|
public createChannelMessage(
|
||||||
channelId: string,
|
target: Discord.ChannelResolvable,
|
||||||
|
options: Discord.MessageCreateOptions = {},
|
||||||
|
): ReacordInstance {
|
||||||
|
return this.createInstance(
|
||||||
|
this.createChannelMessageRenderer(target, options),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replies to a command interaction by sending a message.
|
||||||
|
*
|
||||||
|
* @param interaction Discord command interaction object.
|
||||||
|
* @param [options] Custom options for the interaction reply method.
|
||||||
|
* @see https://reacord.mapleleaf.dev/guides/sending-messages
|
||||||
|
* @see {@link Discord.InteractionReplyOptions}
|
||||||
|
*/
|
||||||
|
public createInteractionReply(
|
||||||
|
interaction: Discord.CommandInteraction,
|
||||||
|
options: Discord.InteractionReplyOptions = {},
|
||||||
|
): ReacordInstance {
|
||||||
|
return this.createInstance(
|
||||||
|
this.createInteractionReplyRenderer(interaction, options),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a message to a channel.
|
||||||
|
*
|
||||||
|
* @deprecated Use reacord.createChannelMessage() instead.
|
||||||
|
* @see https://reacord.mapleleaf.dev/guides/sending-messages
|
||||||
|
*/
|
||||||
|
public send(
|
||||||
|
channel: Discord.ChannelResolvable,
|
||||||
initialContent?: React.ReactNode,
|
initialContent?: React.ReactNode,
|
||||||
): ReacordInstance {
|
): ReacordInstance {
|
||||||
return this.createInstance(
|
return this.createInstance(
|
||||||
this.createChannelRenderer(channelId),
|
this.createChannelMessageRenderer(channel, {}),
|
||||||
initialContent,
|
initialContent,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a message as a reply to a command interaction.
|
* Sends a message as a reply to a command interaction.
|
||||||
* @see https://reacord.fly.dev/guides/sending-messages
|
*
|
||||||
|
* @deprecated Use reacord.createInteractionReply() instead.
|
||||||
|
* @see https://reacord.mapleleaf.dev/guides/sending-messages
|
||||||
*/
|
*/
|
||||||
override reply(
|
public reply(
|
||||||
interaction: Discord.CommandInteraction,
|
interaction: Discord.CommandInteraction,
|
||||||
initialContent?: React.ReactNode,
|
initialContent?: React.ReactNode,
|
||||||
): ReacordInstance {
|
): ReacordInstance {
|
||||||
return this.createInstance(
|
return this.createInstance(
|
||||||
this.createInteractionReplyRenderer(interaction),
|
this.createInteractionReplyRenderer(interaction, {}),
|
||||||
initialContent,
|
initialContent,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends an ephemeral message as a reply to a command interaction.
|
* Sends an ephemeral message as a reply to a command interaction.
|
||||||
* @see https://reacord.fly.dev/guides/sending-messages
|
*
|
||||||
|
* @deprecated Use reacord.createInteractionReply(interaction, { ephemeral:
|
||||||
|
* true })
|
||||||
|
* @see https://reacord.mapleleaf.dev/guides/sending-messages
|
||||||
*/
|
*/
|
||||||
override ephemeralReply(
|
public ephemeralReply(
|
||||||
interaction: Discord.CommandInteraction,
|
interaction: Discord.CommandInteraction,
|
||||||
initialContent?: React.ReactNode,
|
initialContent?: React.ReactNode,
|
||||||
): ReacordInstance {
|
): ReacordInstance {
|
||||||
return this.createInstance(
|
return this.createInstance(
|
||||||
this.createEphemeralInteractionReplyRenderer(interaction),
|
this.createInteractionReplyRenderer(interaction, {
|
||||||
|
ephemeral: true,
|
||||||
|
}),
|
||||||
initialContent,
|
initialContent,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private createChannelRenderer(channelId: string) {
|
private createChannelMessageRenderer(
|
||||||
|
channelResolvable: Discord.ChannelResolvable,
|
||||||
|
messageCreateOptions?: Discord.MessageCreateOptions,
|
||||||
|
) {
|
||||||
return new ChannelMessageRenderer({
|
return new ChannelMessageRenderer({
|
||||||
send: async (options) => {
|
send: async (messageOptions) => {
|
||||||
const channel =
|
let channel = this.client.channels.resolve(channelResolvable)
|
||||||
this.client.channels.cache.get(channelId) ??
|
if (!channel && typeof channelResolvable === "string") {
|
||||||
(await this.client.channels.fetch(channelId)) ??
|
channel = await this.client.channels.fetch(channelResolvable)
|
||||||
raise(`Channel ${channelId} not found`)
|
|
||||||
|
|
||||||
if (!channel.isText()) {
|
|
||||||
raise(`Channel ${channelId} is not a text channel`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const message = await channel.send(getDiscordMessageOptions(options))
|
if (!channel) {
|
||||||
|
const id =
|
||||||
|
typeof channelResolvable === "string"
|
||||||
|
? channelResolvable
|
||||||
|
: channelResolvable.id
|
||||||
|
raise(`Channel ${id} not found`)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!channel.isTextBased()) {
|
||||||
|
raise(`Channel ${channel.id} must be a text channel`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const textChannel = channel as Discord.TextBasedChannel &
|
||||||
|
Discord.PartialTextBasedChannelFields
|
||||||
|
const message = await textChannel.send({
|
||||||
|
...getDiscordMessageOptions(messageOptions),
|
||||||
|
...messageCreateOptions,
|
||||||
|
})
|
||||||
return createReacordMessage(message)
|
return createReacordMessage(message)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -102,48 +169,25 @@ export class ReacordDiscordJs extends Reacord {
|
|||||||
interaction:
|
interaction:
|
||||||
| Discord.CommandInteraction
|
| Discord.CommandInteraction
|
||||||
| Discord.MessageComponentInteraction,
|
| Discord.MessageComponentInteraction,
|
||||||
|
interactionReplyOptions: Discord.InteractionReplyOptions,
|
||||||
) {
|
) {
|
||||||
return new InteractionReplyRenderer({
|
return new InteractionReplyRenderer({
|
||||||
type: "command",
|
interactionId: interaction.id,
|
||||||
id: interaction.id,
|
reply: async (messageOptions) => {
|
||||||
reply: async (options) => {
|
|
||||||
const message = await interaction.reply({
|
const message = await interaction.reply({
|
||||||
...getDiscordMessageOptions(options),
|
...getDiscordMessageOptions(messageOptions),
|
||||||
|
...interactionReplyOptions,
|
||||||
fetchReply: true,
|
fetchReply: true,
|
||||||
})
|
})
|
||||||
return createReacordMessage(message as Discord.Message)
|
return createReacordMessage(message)
|
||||||
},
|
},
|
||||||
followUp: async (options) => {
|
followUp: async (messageOptions) => {
|
||||||
const message = await interaction.followUp({
|
const message = await interaction.followUp({
|
||||||
...getDiscordMessageOptions(options),
|
...getDiscordMessageOptions(messageOptions),
|
||||||
|
...interactionReplyOptions,
|
||||||
fetchReply: true,
|
fetchReply: true,
|
||||||
})
|
})
|
||||||
return createReacordMessage(message as Discord.Message)
|
return createReacordMessage(message)
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
private createEphemeralInteractionReplyRenderer(
|
|
||||||
interaction:
|
|
||||||
| Discord.CommandInteraction
|
|
||||||
| Discord.MessageComponentInteraction,
|
|
||||||
) {
|
|
||||||
return new InteractionReplyRenderer({
|
|
||||||
type: "command",
|
|
||||||
id: interaction.id,
|
|
||||||
reply: async (options) => {
|
|
||||||
await interaction.reply({
|
|
||||||
...getDiscordMessageOptions(options),
|
|
||||||
ephemeral: true,
|
|
||||||
})
|
|
||||||
return createEphemeralReacordMessage()
|
|
||||||
},
|
|
||||||
followUp: async (options) => {
|
|
||||||
await interaction.followUp({
|
|
||||||
...getDiscordMessageOptions(options),
|
|
||||||
ephemeral: true,
|
|
||||||
})
|
|
||||||
return createEphemeralReacordMessage()
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -152,7 +196,7 @@ export class ReacordDiscordJs extends Reacord {
|
|||||||
interaction: Discord.MessageComponentInteraction,
|
interaction: Discord.MessageComponentInteraction,
|
||||||
): ComponentInteraction {
|
): ComponentInteraction {
|
||||||
// todo please dear god clean this up
|
// todo please dear god clean this up
|
||||||
const channel: ChannelInfo = interaction.channel
|
const channel: ComponentEventChannel = interaction.channel
|
||||||
? {
|
? {
|
||||||
...pruneNullishValues(
|
...pruneNullishValues(
|
||||||
pick(interaction.channel, [
|
pick(interaction.channel, [
|
||||||
@@ -168,62 +212,43 @@ export class ReacordDiscordJs extends Reacord {
|
|||||||
}
|
}
|
||||||
: raise("Non-channel interactions are not supported")
|
: raise("Non-channel interactions are not supported")
|
||||||
|
|
||||||
const message: MessageInfo =
|
const message: ComponentEventMessage =
|
||||||
interaction.message instanceof Discord.Message
|
interaction.message instanceof Discord.Message
|
||||||
? {
|
? createComponentEventMessage(interaction.message)
|
||||||
...pick(interaction.message, [
|
|
||||||
"id",
|
|
||||||
"channelId",
|
|
||||||
"authorId",
|
|
||||||
"content",
|
|
||||||
"tts",
|
|
||||||
"mentionEveryone",
|
|
||||||
]),
|
|
||||||
timestamp: new Date(
|
|
||||||
interaction.message.createdTimestamp,
|
|
||||||
).toISOString(),
|
|
||||||
editedTimestamp: interaction.message.editedTimestamp
|
|
||||||
? new Date(interaction.message.editedTimestamp).toISOString()
|
|
||||||
: undefined,
|
|
||||||
mentions: interaction.message.mentions.users.map((u) => u.id),
|
|
||||||
}
|
|
||||||
: raise("Message not found")
|
: raise("Message not found")
|
||||||
|
|
||||||
const member: GuildMemberInfo | undefined =
|
const member: ComponentEventGuildMember | undefined =
|
||||||
interaction.member instanceof Discord.GuildMember
|
interaction.member instanceof Discord.GuildMember
|
||||||
? {
|
? {
|
||||||
...pruneNullishValues(
|
...pruneNullishValues(
|
||||||
pick(interaction.member, [
|
pick(interaction.member, ["nick", "avatarUrl", "pending"]),
|
||||||
"id",
|
|
||||||
"nick",
|
|
||||||
"displayName",
|
|
||||||
"avatarUrl",
|
|
||||||
"displayAvatarUrl",
|
|
||||||
"color",
|
|
||||||
"pending",
|
|
||||||
]),
|
|
||||||
),
|
),
|
||||||
|
id: interaction.member.id,
|
||||||
displayName: interaction.member.displayName,
|
displayName: interaction.member.displayName,
|
||||||
roles: [...interaction.member.roles.cache.map((role) => role.id)],
|
roles: interaction.member.roles.cache.map((role) => role.id),
|
||||||
joinedAt: interaction.member.joinedAt?.toISOString(),
|
joinedAt: interaction.member.joinedAt?.toISOString(),
|
||||||
premiumSince: interaction.member.premiumSince?.toISOString(),
|
premiumSince: interaction.member.premiumSince?.toISOString(),
|
||||||
communicationDisabledUntil:
|
communicationDisabledUntil:
|
||||||
interaction.member.communicationDisabledUntil?.toISOString(),
|
interaction.member.communicationDisabledUntil?.toISOString(),
|
||||||
|
color: interaction.member.displayColor,
|
||||||
|
displayAvatarUrl: interaction.member.displayAvatarURL(),
|
||||||
}
|
}
|
||||||
: undefined
|
: undefined
|
||||||
|
|
||||||
const guild: GuildInfo | undefined = interaction.guild
|
const guild: ComponentEventGuild | undefined = interaction.guild
|
||||||
? {
|
? {
|
||||||
...pruneNullishValues(pick(interaction.guild, ["id", "name"])),
|
id: interaction.guild.id,
|
||||||
|
name: interaction.guild.name,
|
||||||
member: member ?? raise("unexpected: member is undefined"),
|
member: member ?? raise("unexpected: member is undefined"),
|
||||||
}
|
}
|
||||||
: undefined
|
: undefined
|
||||||
|
|
||||||
const user: UserInfo = {
|
const user: ComponentEventUser = {
|
||||||
...pruneNullishValues(
|
id: interaction.user.id,
|
||||||
pick(interaction.user, ["id", "username", "discriminator", "tag"]),
|
username: interaction.user.username,
|
||||||
),
|
discriminator: interaction.user.discriminator,
|
||||||
avatarUrl: interaction.user.avatarURL()!,
|
tag: interaction.user.tag,
|
||||||
|
avatarUrl: interaction.user.avatarURL(),
|
||||||
accentColor: interaction.user.accentColor ?? undefined,
|
accentColor: interaction.user.accentColor ?? undefined,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,7 +256,11 @@ export class ReacordDiscordJs extends Reacord {
|
|||||||
id: interaction.id,
|
id: interaction.id,
|
||||||
customId: interaction.customId,
|
customId: interaction.customId,
|
||||||
update: async (options: MessageOptions) => {
|
update: async (options: MessageOptions) => {
|
||||||
|
if (interaction.deferred || interaction.replied) {
|
||||||
|
await interaction.message.edit(getDiscordMessageOptions(options))
|
||||||
|
} else {
|
||||||
await interaction.update(getDiscordMessageOptions(options))
|
await interaction.update(getDiscordMessageOptions(options))
|
||||||
|
}
|
||||||
},
|
},
|
||||||
deferUpdate: async () => {
|
deferUpdate: async () => {
|
||||||
if (interaction.replied || interaction.deferred) return
|
if (interaction.replied || interaction.deferred) return
|
||||||
@@ -242,14 +271,14 @@ export class ReacordDiscordJs extends Reacord {
|
|||||||
...getDiscordMessageOptions(options),
|
...getDiscordMessageOptions(options),
|
||||||
fetchReply: true,
|
fetchReply: true,
|
||||||
})
|
})
|
||||||
return createReacordMessage(message as Discord.Message)
|
return createReacordMessage(message)
|
||||||
},
|
},
|
||||||
followUp: async (options) => {
|
followUp: async (options) => {
|
||||||
const message = await interaction.followUp({
|
const message = await interaction.followUp({
|
||||||
...getDiscordMessageOptions(options),
|
...getDiscordMessageOptions(options),
|
||||||
fetchReply: true,
|
fetchReply: true,
|
||||||
})
|
})
|
||||||
return createReacordMessage(message as Discord.Message)
|
return createReacordMessage(message)
|
||||||
},
|
},
|
||||||
event: {
|
event: {
|
||||||
channel,
|
channel,
|
||||||
@@ -257,15 +286,18 @@ export class ReacordDiscordJs extends Reacord {
|
|||||||
user,
|
user,
|
||||||
guild,
|
guild,
|
||||||
|
|
||||||
reply: (content?: ReactNode) =>
|
reply: (content?: ReactNode, options?: ComponentEventReplyOptions) =>
|
||||||
this.createInstance(
|
this.createInstance(
|
||||||
this.createInteractionReplyRenderer(interaction),
|
this.createInteractionReplyRenderer(interaction, options ?? {}),
|
||||||
content,
|
content,
|
||||||
),
|
),
|
||||||
|
|
||||||
|
/** @deprecated Use event.reply(content, { ephemeral: true }) */
|
||||||
ephemeralReply: (content: ReactNode) =>
|
ephemeralReply: (content: ReactNode) =>
|
||||||
this.createInstance(
|
this.createInstance(
|
||||||
this.createEphemeralInteractionReplyRenderer(interaction),
|
this.createInteractionReplyRenderer(interaction, {
|
||||||
|
ephemeral: true,
|
||||||
|
}),
|
||||||
content,
|
content,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@@ -278,7 +310,7 @@ export class ReacordDiscordJs extends Reacord {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (interaction.isSelectMenu()) {
|
if (interaction.isAnySelectMenu()) {
|
||||||
return {
|
return {
|
||||||
...baseProps,
|
...baseProps,
|
||||||
type: "select",
|
type: "select",
|
||||||
@@ -295,85 +327,148 @@ export class ReacordDiscordJs extends Reacord {
|
|||||||
|
|
||||||
function createReacordMessage(message: Discord.Message): Message {
|
function createReacordMessage(message: Discord.Message): Message {
|
||||||
return {
|
return {
|
||||||
|
data: createComponentEventMessage(message),
|
||||||
edit: async (options) => {
|
edit: async (options) => {
|
||||||
await message.edit(getDiscordMessageOptions(options))
|
await message.edit(getDiscordMessageOptions(options))
|
||||||
},
|
},
|
||||||
disableComponents: async () => {
|
|
||||||
for (const actionRow of message.components) {
|
|
||||||
for (const component of actionRow.components) {
|
|
||||||
component.setDisabled(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await message.edit({
|
|
||||||
components: message.components,
|
|
||||||
})
|
|
||||||
},
|
|
||||||
delete: async () => {
|
delete: async () => {
|
||||||
await message.delete()
|
await message.delete()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createEphemeralReacordMessage(): Message {
|
function createComponentEventMessage(
|
||||||
|
message: Discord.Message,
|
||||||
|
): ComponentEventMessage {
|
||||||
return {
|
return {
|
||||||
edit: () => {
|
...pick(message, [
|
||||||
console.warn("Ephemeral messages can't be edited")
|
"id",
|
||||||
return Promise.resolve()
|
"channelId",
|
||||||
},
|
"authorId",
|
||||||
disableComponents: () => {
|
"content",
|
||||||
console.warn("Ephemeral messages can't be edited")
|
"tts",
|
||||||
return Promise.resolve()
|
"mentionEveryone",
|
||||||
},
|
]),
|
||||||
delete: () => {
|
timestamp: new Date(message.createdTimestamp).toISOString(),
|
||||||
console.warn("Ephemeral messages can't be deleted")
|
editedTimestamp: message.editedTimestamp
|
||||||
return Promise.resolve()
|
? new Date(message.editedTimestamp).toISOString()
|
||||||
},
|
: undefined,
|
||||||
|
mentions: message.mentions.users.map((u) => u.id),
|
||||||
|
authorId: message.author.id,
|
||||||
|
mentionEveryone: message.mentions.everyone,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function convertButtonStyleToEnum(style: MessageButtonOptions["style"]) {
|
||||||
|
const styleMap = {
|
||||||
|
primary: Discord.ButtonStyle.Primary,
|
||||||
|
secondary: Discord.ButtonStyle.Secondary,
|
||||||
|
success: Discord.ButtonStyle.Success,
|
||||||
|
danger: Discord.ButtonStyle.Danger,
|
||||||
|
} as const
|
||||||
|
|
||||||
|
return styleMap[style ?? "secondary"]
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: this could be a part of the core library,
|
// TODO: this could be a part of the core library,
|
||||||
// and also handle some edge cases, e.g. empty messages
|
// and also handle some edge cases, e.g. empty messages
|
||||||
function getDiscordMessageOptions(
|
function getDiscordMessageOptions(reacordOptions: MessageOptions) {
|
||||||
reacordOptions: MessageOptions,
|
const options = {
|
||||||
): Discord.MessageOptions {
|
content: reacordOptions.content || undefined,
|
||||||
const options: Discord.MessageOptions = {
|
|
||||||
// eslint-disable-next-line unicorn/no-null
|
|
||||||
content: reacordOptions.content || null,
|
|
||||||
embeds: reacordOptions.embeds,
|
embeds: reacordOptions.embeds,
|
||||||
components: reacordOptions.actionRows.map((row) => ({
|
components: reacordOptions.actionRows.map((row) => ({
|
||||||
type: "ACTION_ROW",
|
type: Discord.ComponentType.ActionRow,
|
||||||
components: row.map(
|
components: row.map(
|
||||||
(component): Discord.MessageActionRowComponentOptions => {
|
(component): Discord.MessageActionRowComponentData => {
|
||||||
if (component.type === "button") {
|
if (component.type === "button") {
|
||||||
return {
|
return {
|
||||||
type: "BUTTON",
|
type: Discord.ComponentType.Button,
|
||||||
customId: component.customId,
|
customId: component.customId,
|
||||||
label: component.label ?? "",
|
label: component.label ?? "",
|
||||||
style: toUpper(component.style ?? "secondary"),
|
style: convertButtonStyleToEnum(component.style),
|
||||||
disabled: component.disabled,
|
disabled: component.disabled,
|
||||||
emoji: component.emoji,
|
emoji: component.emoji,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (component.type === "select") {
|
if (component.type === "link") {
|
||||||
return {
|
return {
|
||||||
...component,
|
type: Discord.ComponentType.Button,
|
||||||
type: "SELECT_MENU",
|
url: component.url,
|
||||||
options: component.options.map((option) => ({
|
label: component.label ?? "",
|
||||||
|
style: Discord.ButtonStyle.Link,
|
||||||
|
disabled: component.disabled,
|
||||||
|
emoji: component.emoji,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// future proofing
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||||
|
if (component.type === "select") {
|
||||||
|
const {
|
||||||
|
menuType,
|
||||||
|
values,
|
||||||
|
options: selectOptions,
|
||||||
|
channelTypes,
|
||||||
|
multiple,
|
||||||
|
...rest
|
||||||
|
} = component
|
||||||
|
|
||||||
|
if (menuType === "string" || menuType == undefined) {
|
||||||
|
return {
|
||||||
|
...rest,
|
||||||
|
type: Discord.ComponentType.StringSelect,
|
||||||
|
options: selectOptions.map((option) => ({
|
||||||
...option,
|
...option,
|
||||||
default: component.values?.includes(option.value),
|
default: values?.includes(option.value),
|
||||||
})),
|
})),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
raise(`Unsupported component type: ${component.type}`)
|
if (menuType === "user") {
|
||||||
|
return {
|
||||||
|
...rest,
|
||||||
|
type: Discord.ComponentType.UserSelect,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (menuType === "role") {
|
||||||
|
return {
|
||||||
|
...rest,
|
||||||
|
type: Discord.ComponentType.RoleSelect,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (menuType === "mentionable") {
|
||||||
|
return {
|
||||||
|
...rest,
|
||||||
|
type: Discord.ComponentType.MentionableSelect,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (menuType === "channel") {
|
||||||
|
return {
|
||||||
|
...rest,
|
||||||
|
type: Discord.ComponentType.ChannelSelect,
|
||||||
|
channelTypes,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
raise(
|
||||||
|
`Unsupported select menu type: ${menuType ?? "string"}`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
component satisfies never
|
||||||
|
throw new Error(
|
||||||
|
`Invalid component type ${safeJsonStringify(component)}}`,
|
||||||
|
)
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
})),
|
})),
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options.content && !options.embeds?.length) {
|
if (!options.content && !options.embeds.length) {
|
||||||
options.content = "_ _"
|
options.content = "_ _"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,35 +1,28 @@
|
|||||||
import type { ReactNode } from "react"
|
import type { ReactNode } from "react"
|
||||||
import React from "react"
|
import type { ComponentInteraction } from "../internal/interaction.js"
|
||||||
import type { ComponentInteraction } from "../internal/interaction"
|
|
||||||
import { reconciler } from "../internal/reconciler.js"
|
import { reconciler } from "../internal/reconciler.js"
|
||||||
import type { Renderer } from "../internal/renderers/renderer"
|
import type { Renderer } from "../internal/renderers/renderer.js"
|
||||||
import type { ReacordInstance } from "./instance"
|
import { InstanceProvider, MessageProvider } from "./instance-context.js"
|
||||||
import { InstanceProvider } from "./instance-context"
|
import type { ReacordInstance } from "./instance.js"
|
||||||
|
|
||||||
|
/** @category Core */
|
||||||
|
export interface ReacordConfig {
|
||||||
/**
|
/**
|
||||||
* @category Core
|
* The max number of active instances. When this limit is exceeded, the oldest
|
||||||
*/
|
* instances will be disabled.
|
||||||
export type ReacordConfig = {
|
|
||||||
/**
|
|
||||||
* The max number of active instances.
|
|
||||||
* When this limit is exceeded, the oldest instances will be disabled.
|
|
||||||
*/
|
*/
|
||||||
maxInstances?: number
|
maxInstances?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main Reacord class that other Reacord adapters should extend.
|
* The main Reacord class that other Reacord adapters should extend. Only use
|
||||||
* Only use this directly if you're making [a custom adapter](/guides/custom-adapters).
|
* this directly if you're making [a custom adapter](/guides/custom-adapters).
|
||||||
*/
|
*/
|
||||||
export abstract class Reacord {
|
export abstract class Reacord {
|
||||||
private renderers: Renderer[] = []
|
private renderers: Renderer[] = []
|
||||||
|
|
||||||
constructor(private readonly config: ReacordConfig = {}) {}
|
constructor(private readonly config: ReacordConfig = {}) {}
|
||||||
|
|
||||||
abstract send(...args: unknown[]): ReacordInstance
|
|
||||||
abstract reply(...args: unknown[]): ReacordInstance
|
|
||||||
abstract ephemeralReply(...args: unknown[]): ReacordInstance
|
|
||||||
|
|
||||||
protected handleComponentInteraction(interaction: ComponentInteraction) {
|
protected handleComponentInteraction(interaction: ComponentInteraction) {
|
||||||
for (const renderer of this.renderers) {
|
for (const renderer of this.renderers) {
|
||||||
if (renderer.handleComponentInteraction(interaction)) return
|
if (renderer.handleComponentInteraction(interaction)) return
|
||||||
@@ -41,20 +34,34 @@ export abstract class Reacord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected createInstance(renderer: Renderer, initialContent?: ReactNode) {
|
protected createInstance(renderer: Renderer, initialContent?: ReactNode) {
|
||||||
if (this.renderers.length > this.maxInstances) {
|
if (this.renderers.length > this.maxInstances && this.renderers[0]) {
|
||||||
this.deactivate(this.renderers[0]!)
|
this.deactivate(this.renderers[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
this.renderers.push(renderer)
|
this.renderers.push(renderer)
|
||||||
|
|
||||||
const container = reconciler.createContainer(renderer, 0, false, {})
|
const container: unknown = reconciler.createContainer(
|
||||||
|
renderer,
|
||||||
|
0,
|
||||||
|
null,
|
||||||
|
false,
|
||||||
|
null,
|
||||||
|
"reacord",
|
||||||
|
() => {},
|
||||||
|
null,
|
||||||
|
)
|
||||||
|
|
||||||
const instance: ReacordInstance = {
|
const instance: ReacordInstance = {
|
||||||
render: (content: ReactNode) => {
|
render: (content: ReactNode) => {
|
||||||
reconciler.updateContainer(
|
reconciler.updateContainer(
|
||||||
<InstanceProvider value={instance}>{content}</InstanceProvider>,
|
<InstanceProvider value={instance}>
|
||||||
|
<MessageProvider value={renderer.messageStore}>
|
||||||
|
{content}
|
||||||
|
</MessageProvider>
|
||||||
|
</InstanceProvider>,
|
||||||
container,
|
container,
|
||||||
)
|
)
|
||||||
|
return instance
|
||||||
},
|
},
|
||||||
deactivate: () => {
|
deactivate: () => {
|
||||||
this.deactivate(renderer)
|
this.deactivate(renderer)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { Message, MessageOptions } from "./message"
|
import type { Message, MessageOptions } from "./message"
|
||||||
|
|
||||||
export type Channel = {
|
export interface Channel {
|
||||||
send(message: MessageOptions): Promise<Message>
|
send(message: MessageOptions): Promise<Message>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,18 @@ export class Container<T> {
|
|||||||
this.items = []
|
this.items = []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
find(predicate: (item: T) => boolean): T | undefined {
|
||||||
|
return this.items.find(predicate)
|
||||||
|
}
|
||||||
|
|
||||||
|
findType<U extends T>(
|
||||||
|
type: new (...args: Array<NonNullable<unknown>>) => U,
|
||||||
|
): U | undefined {
|
||||||
|
for (const item of this.items) {
|
||||||
|
if (item instanceof type) return item
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Symbol.iterator]() {
|
[Symbol.iterator]() {
|
||||||
return this.items[Symbol.iterator]()
|
return this.items[Symbol.iterator]()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
import type { Node } from "./node"
|
||||||
import type { ReactNode } from "react"
|
import type { ReactNode } from "react"
|
||||||
import React from "react"
|
import React from "react"
|
||||||
import type { Node } from "./node"
|
|
||||||
|
|
||||||
export function ReacordElement<Props>(props: {
|
export function ReacordElement<Props>(props: {
|
||||||
props: Props
|
props: Props
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export type SelectInteraction = BaseComponentInteraction<
|
|||||||
SelectChangeEvent
|
SelectChangeEvent
|
||||||
>
|
>
|
||||||
|
|
||||||
export type BaseInteraction<Type extends string> = {
|
export interface BaseInteraction<Type extends string> {
|
||||||
type: Type
|
type: Type
|
||||||
id: string
|
id: string
|
||||||
reply(messageOptions: MessageOptions): Promise<Message>
|
reply(messageOptions: MessageOptions): Promise<Message>
|
||||||
|
|||||||
22
packages/reacord/library/internal/message-store.ts
Normal file
22
packages/reacord/library/internal/message-store.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import type { ComponentEventMessage } from "../core/component-event"
|
||||||
|
|
||||||
|
export class MessageStore {
|
||||||
|
private value: ComponentEventMessage | undefined
|
||||||
|
private listeners = new Set<() => void>()
|
||||||
|
|
||||||
|
getSnapshot = () => this.value
|
||||||
|
|
||||||
|
subscribe = (listener: () => void) => {
|
||||||
|
this.listeners.add(listener)
|
||||||
|
return () => {
|
||||||
|
this.listeners.delete(listener)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
set(value: ComponentEventMessage | undefined) {
|
||||||
|
this.value = value
|
||||||
|
for (const listener of this.listeners) {
|
||||||
|
listener()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
import type { Except } from "type-fest"
|
import type { ComponentEventMessage } from "../core/component-event"
|
||||||
import { last } from "../../helpers/last"
|
|
||||||
import type { EmbedOptions } from "../core/components/embed-options"
|
import type { EmbedOptions } from "../core/components/embed-options"
|
||||||
import type { SelectProps } from "../core/components/select"
|
import type { SelectProps } from "../core/components/select"
|
||||||
|
import { last } from "@reacord/helpers/last"
|
||||||
|
import type { Except } from "type-fest"
|
||||||
|
|
||||||
export type MessageOptions = {
|
export interface MessageOptions {
|
||||||
content: string
|
content: string
|
||||||
embeds: EmbedOptions[]
|
embeds: EmbedOptions[]
|
||||||
actionRows: ActionRow[]
|
actionRows: ActionRow[]
|
||||||
@@ -16,7 +17,7 @@ export type ActionRowItem =
|
|||||||
| MessageLinkOptions
|
| MessageLinkOptions
|
||||||
| MessageSelectOptions
|
| MessageSelectOptions
|
||||||
|
|
||||||
export type MessageButtonOptions = {
|
export interface MessageButtonOptions {
|
||||||
type: "button"
|
type: "button"
|
||||||
customId: string
|
customId: string
|
||||||
label?: string
|
label?: string
|
||||||
@@ -25,7 +26,7 @@ export type MessageButtonOptions = {
|
|||||||
emoji?: string
|
emoji?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type MessageLinkOptions = {
|
export interface MessageLinkOptions {
|
||||||
type: "link"
|
type: "link"
|
||||||
url: string
|
url: string
|
||||||
label?: string
|
label?: string
|
||||||
@@ -39,17 +40,17 @@ export type MessageSelectOptions = Except<SelectProps, "children" | "value"> & {
|
|||||||
options: MessageSelectOptionOptions[]
|
options: MessageSelectOptionOptions[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export type MessageSelectOptionOptions = {
|
export interface MessageSelectOptionOptions {
|
||||||
label: string
|
label: string
|
||||||
value: string
|
value: string
|
||||||
description?: string
|
description?: string
|
||||||
emoji?: string
|
emoji?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Message = {
|
export interface Message {
|
||||||
|
data?: ComponentEventMessage
|
||||||
edit(options: MessageOptions): Promise<void>
|
edit(options: MessageOptions): Promise<void>
|
||||||
delete(): Promise<void>
|
delete(): Promise<void>
|
||||||
disableComponents(): Promise<void>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getNextActionRow(options: MessageOptions): ActionRow {
|
export function getNextActionRow(options: MessageOptions): ActionRow {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
/* eslint-disable class-methods-use-this */
|
|
||||||
import { Container } from "./container.js"
|
import { Container } from "./container.js"
|
||||||
import type { ComponentInteraction } from "./interaction"
|
import type { ComponentInteraction } from "./interaction"
|
||||||
import type { MessageOptions } from "./message"
|
import type { MessageOptions } from "./message"
|
||||||
@@ -8,9 +7,15 @@ export abstract class Node<Props> {
|
|||||||
|
|
||||||
constructor(public props: Props) {}
|
constructor(public props: Props) {}
|
||||||
|
|
||||||
modifyMessageOptions(options: MessageOptions) {}
|
modifyMessageOptions(_options: MessageOptions) {
|
||||||
|
// noop
|
||||||
|
}
|
||||||
|
|
||||||
handleComponentInteraction(interaction: ComponentInteraction): boolean {
|
handleComponentInteraction(_interaction: ComponentInteraction): boolean {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get text(): string {
|
||||||
|
return [...this.children].map((child) => child.text).join("")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
import { raise } from "@reacord/helpers/raise.js"
|
||||||
import type { HostConfig } from "react-reconciler"
|
import type { HostConfig } from "react-reconciler"
|
||||||
import ReactReconciler from "react-reconciler"
|
import ReactReconciler from "react-reconciler"
|
||||||
import { raise } from "../../helpers/raise.js"
|
import { DefaultEventPriority } from "react-reconciler/constants.js"
|
||||||
import { Node } from "./node.js"
|
import { Node } from "./node.js"
|
||||||
import type { Renderer } from "./renderers/renderer"
|
import type { Renderer } from "./renderers/renderer"
|
||||||
import { TextNode } from "./text-node.js"
|
import { TextNode } from "./text-node.js"
|
||||||
@@ -14,14 +15,12 @@ const config: HostConfig<
|
|||||||
never, // SuspenseInstance,
|
never, // SuspenseInstance,
|
||||||
never, // HydratableInstance,
|
never, // HydratableInstance,
|
||||||
never, // PublicInstance,
|
never, // PublicInstance,
|
||||||
never, // HostContext,
|
null, // HostContext,
|
||||||
true, // UpdatePayload,
|
true, // UpdatePayload,
|
||||||
never, // ChildSet,
|
never, // ChildSet,
|
||||||
number, // TimeoutHandle,
|
number, // TimeoutHandle,
|
||||||
number // NoTimeout,
|
number // NoTimeout,
|
||||||
> = {
|
> = {
|
||||||
// config
|
|
||||||
now: Date.now,
|
|
||||||
supportsMutation: true,
|
supportsMutation: true,
|
||||||
supportsPersistence: false,
|
supportsPersistence: false,
|
||||||
supportsHydration: false,
|
supportsHydration: false,
|
||||||
@@ -30,7 +29,6 @@ const config: HostConfig<
|
|||||||
cancelTimeout: global.clearTimeout,
|
cancelTimeout: global.clearTimeout,
|
||||||
noTimeout: -1,
|
noTimeout: -1,
|
||||||
|
|
||||||
// eslint-disable-next-line unicorn/no-null
|
|
||||||
getRootHostContext: () => null,
|
getRootHostContext: () => null,
|
||||||
getChildHostContext: (parentContext) => parentContext,
|
getChildHostContext: (parentContext) => parentContext,
|
||||||
|
|
||||||
@@ -43,7 +41,7 @@ const config: HostConfig<
|
|||||||
raise(`Missing createNode function`)
|
raise(`Missing createNode function`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const node = props.createNode(props.props)
|
const node: unknown = props.createNode(props.props)
|
||||||
if (!(node instanceof Node)) {
|
if (!(node instanceof Node)) {
|
||||||
raise(`createNode function did not return a Node`)
|
raise(`createNode function did not return a Node`)
|
||||||
}
|
}
|
||||||
@@ -52,6 +50,11 @@ const config: HostConfig<
|
|||||||
},
|
},
|
||||||
createTextInstance: (text) => new TextNode(text),
|
createTextInstance: (text) => new TextNode(text),
|
||||||
shouldSetTextContent: () => false,
|
shouldSetTextContent: () => false,
|
||||||
|
detachDeletedInstance: (_instance) => {},
|
||||||
|
beforeActiveInstanceBlur: () => {},
|
||||||
|
afterActiveInstanceBlur: () => {},
|
||||||
|
getInstanceFromNode: (_node: unknown) => null,
|
||||||
|
getInstanceFromScope: (_scopeInstance: unknown) => null,
|
||||||
|
|
||||||
clearContainer: (renderer) => {
|
clearContainer: (renderer) => {
|
||||||
renderer.nodes.clear()
|
renderer.nodes.clear()
|
||||||
@@ -87,16 +90,18 @@ const config: HostConfig<
|
|||||||
node.props = newText
|
node.props = newText
|
||||||
},
|
},
|
||||||
|
|
||||||
// eslint-disable-next-line unicorn/no-null
|
|
||||||
prepareForCommit: () => null,
|
prepareForCommit: () => null,
|
||||||
resetAfterCommit: (renderer) => {
|
resetAfterCommit: (renderer) => {
|
||||||
renderer.render()
|
renderer.render()
|
||||||
},
|
},
|
||||||
|
prepareScopeUpdate: (_scopeInstance: unknown, _instance: unknown) => {},
|
||||||
|
|
||||||
preparePortalMount: () => raise("Portals are not supported"),
|
preparePortalMount: () => raise("Portals are not supported"),
|
||||||
getPublicInstance: () => raise("Refs are currently not supported"),
|
getPublicInstance: () => raise("Refs are currently not supported"),
|
||||||
|
|
||||||
finalizeInitialChildren: () => false,
|
finalizeInitialChildren: () => false,
|
||||||
|
|
||||||
|
getCurrentEventPriority: () => DefaultEventPriority,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const reconciler = ReactReconciler(config)
|
export const reconciler = ReactReconciler(config)
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import type { Interaction } from "../interaction"
|
|
||||||
import type { Message, MessageOptions } from "../message"
|
import type { Message, MessageOptions } from "../message"
|
||||||
import { Renderer } from "./renderer"
|
import { Renderer } from "./renderer"
|
||||||
|
|
||||||
@@ -6,17 +5,23 @@ import { Renderer } from "./renderer"
|
|||||||
// so we know whether to call reply() or followUp()
|
// so we know whether to call reply() or followUp()
|
||||||
const repliedInteractionIds = new Set<string>()
|
const repliedInteractionIds = new Set<string>()
|
||||||
|
|
||||||
|
export type InteractionReplyRendererImplementation = {
|
||||||
|
interactionId: string
|
||||||
|
reply: (options: MessageOptions) => Promise<Message>
|
||||||
|
followUp: (options: MessageOptions) => Promise<Message>
|
||||||
|
}
|
||||||
|
|
||||||
export class InteractionReplyRenderer extends Renderer {
|
export class InteractionReplyRenderer extends Renderer {
|
||||||
constructor(private interaction: Interaction) {
|
constructor(private implementation: InteractionReplyRendererImplementation) {
|
||||||
super()
|
super()
|
||||||
}
|
}
|
||||||
|
|
||||||
protected createMessage(options: MessageOptions): Promise<Message> {
|
protected createMessage(options: MessageOptions): Promise<Message> {
|
||||||
if (repliedInteractionIds.has(this.interaction.id)) {
|
if (repliedInteractionIds.has(this.implementation.interactionId)) {
|
||||||
return this.interaction.followUp(options)
|
return this.implementation.followUp(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
repliedInteractionIds.add(this.interaction.id)
|
repliedInteractionIds.add(this.implementation.interactionId)
|
||||||
return this.interaction.reply(options)
|
return this.implementation.reply(options)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { Subject } from "rxjs"
|
|
||||||
import { concatMap } from "rxjs/operators"
|
|
||||||
import { Container } from "../container.js"
|
import { Container } from "../container.js"
|
||||||
import type { ComponentInteraction } from "../interaction"
|
import type { ComponentInteraction } from "../interaction"
|
||||||
|
import { MessageStore } from "../message-store.js"
|
||||||
import type { Message, MessageOptions } from "../message"
|
import type { Message, MessageOptions } from "../message"
|
||||||
import type { Node } from "../node.js"
|
import type { Node } from "../node.js"
|
||||||
|
import { Subject } from "rxjs"
|
||||||
|
import { concatMap } from "rxjs/operators"
|
||||||
|
|
||||||
type UpdatePayload =
|
type UpdatePayload =
|
||||||
| { action: "update" | "deactivate"; options: MessageOptions }
|
| { action: "update" | "deactivate"; options: MessageOptions }
|
||||||
@@ -12,6 +13,7 @@ type UpdatePayload =
|
|||||||
|
|
||||||
export abstract class Renderer {
|
export abstract class Renderer {
|
||||||
readonly nodes = new Container<Node<unknown>>()
|
readonly nodes = new Container<Node<unknown>>()
|
||||||
|
readonly messageStore = new MessageStore()
|
||||||
private componentInteraction?: ComponentInteraction
|
private componentInteraction?: ComponentInteraction
|
||||||
private message?: Message
|
private message?: Message
|
||||||
private active = true
|
private active = true
|
||||||
@@ -47,14 +49,12 @@ export abstract class Renderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleComponentInteraction(interaction: ComponentInteraction) {
|
handleComponentInteraction(interaction: ComponentInteraction) {
|
||||||
|
for (const node of this.nodes) {
|
||||||
|
if (node.handleComponentInteraction(interaction)) {
|
||||||
this.componentInteraction = interaction
|
this.componentInteraction = interaction
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.updates.next({ action: "deferUpdate", interaction })
|
this.updates.next({ action: "deferUpdate", interaction })
|
||||||
}, 500)
|
}, 500)
|
||||||
|
|
||||||
for (const node of this.nodes) {
|
|
||||||
if (node.handleComponentInteraction(interaction)) {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,13 +77,24 @@ export abstract class Renderer {
|
|||||||
private async updateMessage(payload: UpdatePayload) {
|
private async updateMessage(payload: UpdatePayload) {
|
||||||
if (payload.action === "destroy") {
|
if (payload.action === "destroy") {
|
||||||
this.updateSubscription.unsubscribe()
|
this.updateSubscription.unsubscribe()
|
||||||
|
this.messageStore.set(undefined)
|
||||||
await this.message?.delete()
|
await this.message?.delete()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (payload.action === "deactivate") {
|
if (payload.action === "deactivate") {
|
||||||
this.updateSubscription.unsubscribe()
|
this.updateSubscription.unsubscribe()
|
||||||
await this.message?.disableComponents()
|
|
||||||
|
await this.message?.edit({
|
||||||
|
...payload.options,
|
||||||
|
actionRows: payload.options.actionRows.map((row) =>
|
||||||
|
row.map((component) => ({
|
||||||
|
...component,
|
||||||
|
disabled: true,
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
})
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,5 +116,6 @@ export abstract class Renderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.message = await this.createMessage(payload.options)
|
this.message = await this.createMessage(payload.options)
|
||||||
|
this.messageStore.set(this.message.data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,4 +5,8 @@ export class TextNode extends Node<string> {
|
|||||||
override modifyMessageOptions(options: MessageOptions) {
|
override modifyMessageOptions(options: MessageOptions) {
|
||||||
options.content = options.content + this.props
|
options.content = options.content + this.props
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override get text() {
|
||||||
|
return this.props
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,6 @@ export * from "./core/components/link"
|
|||||||
export * from "./core/components/option"
|
export * from "./core/components/option"
|
||||||
export * from "./core/components/select"
|
export * from "./core/components/select"
|
||||||
export * from "./core/instance"
|
export * from "./core/instance"
|
||||||
export { useInstance } from "./core/instance-context"
|
export { useInstance, useMessage } from "./core/instance-context"
|
||||||
export * from "./core/reacord"
|
export * from "./core/reacord"
|
||||||
export * from "./core/reacord-discord-js"
|
export * from "./core/reacord-discord-js"
|
||||||
|
|||||||
@@ -2,9 +2,8 @@
|
|||||||
"name": "reacord",
|
"name": "reacord",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "Create interactive Discord messages using React.",
|
"description": "Create interactive Discord messages using React.",
|
||||||
"version": "0.3.4",
|
"version": "0.6.0",
|
||||||
"types": "./dist/main.d.ts",
|
"homepage": "https://reacord.mapleleaf.dev",
|
||||||
"homepage": "https://reacord.fly.dev",
|
|
||||||
"repository": "https://github.com/itsMapleLeaf/reacord.git",
|
"repository": "https://github.com/itsMapleLeaf/reacord.git",
|
||||||
"changelog": "https://github.com/itsMapleLeaf/reacord/releases",
|
"changelog": "https://github.com/itsMapleLeaf/reacord/releases",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@@ -24,10 +23,12 @@
|
|||||||
"README.md",
|
"README.md",
|
||||||
"LICENSE"
|
"LICENSE"
|
||||||
],
|
],
|
||||||
|
"types": "./dist/main.d.ts",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"import": "./dist/main.js",
|
"import": "./dist/main.js",
|
||||||
"require": "./dist/main.cjs"
|
"require": "./dist/main.cjs",
|
||||||
|
"types": "./dist/main.d.ts"
|
||||||
},
|
},
|
||||||
"./package.json": {
|
"./package.json": {
|
||||||
"import": "./package.json",
|
"import": "./package.json",
|
||||||
@@ -35,24 +36,21 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsup-node library/main.ts --target node16 --format cjs,esm --dts --sourcemap",
|
"build": "rm -rf dist && mkdir -p dist && cp ../../README.md ../../LICENSE . && bun build library/main.ts --target=node --outdir=dist --format=esm --sourcemap=external --external react --external react/jsx-runtime --external react/jsx-dev-runtime && bun build library/main.ts --target=node --outdir=dist --format=cjs --sourcemap=external --entry-naming=main.cjs --external react --external react/jsx-runtime --external react/jsx-dev-runtime && tsc -p tsconfig.build.json",
|
||||||
"build-watch": "pnpm build -- --watch",
|
"build-watch": "bun build library/main.ts --target=node --outdir=dist --format=esm --sourcemap=external --watch --external react --external react/jsx-runtime --external react/jsx-dev-runtime",
|
||||||
"test": "vitest --coverage --no-watch",
|
"test": "vitest --coverage --no-watch",
|
||||||
"test-dev": "vitest",
|
"test-dev": "vitest",
|
||||||
"typecheck": "tsc --noEmit",
|
"test-manual": "nodemon --exec tsx --ext ts,tsx ./scripts/discordjs-manual-test.tsx",
|
||||||
"playground": "nodemon --exec esmo --ext ts,tsx --inspect=5858 --enable-source-maps ./playground/main.tsx",
|
"typecheck": "tsc -b"
|
||||||
"release": "bash scripts/release.sh"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/node": "*",
|
"@types/react": "^18.2.27",
|
||||||
"@types/react": "*",
|
"@types/react-reconciler": "^0.28.5",
|
||||||
"@types/react-reconciler": "^0.26.4",
|
"react-reconciler": "^0.29.0",
|
||||||
"nanoid": "^3.1.31",
|
"rxjs": "^7.8.1"
|
||||||
"react-reconciler": "^0.26.2",
|
|
||||||
"rxjs": "^7.5.2"
|
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"discord.js": "^13.3",
|
"discord.js": "^14.25.1",
|
||||||
"react": ">=17"
|
"react": ">=17"
|
||||||
},
|
},
|
||||||
"peerDependenciesMeta": {
|
"peerDependenciesMeta": {
|
||||||
@@ -61,27 +59,18 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/lodash-es": "^4.17.5",
|
"@reacord/helpers": "workspace:*",
|
||||||
"c8": "^7.11.0",
|
"@types/lodash-es": "^4.17.9",
|
||||||
"discord.js": "^13.5.1",
|
"c8": "^8.0.1",
|
||||||
"dotenv": "^11.0.0",
|
"discord.js": "^14.25.1",
|
||||||
"esbuild": "latest",
|
"dotenv": "^16.3.1",
|
||||||
"esbuild-jest": "^0.5.0",
|
|
||||||
"esmo": "^0.13.0",
|
|
||||||
"lodash-es": "^4.17.21",
|
"lodash-es": "^4.17.21",
|
||||||
"nodemon": "^2.0.15",
|
"nodemon": "^3.0.1",
|
||||||
"prettier": "^2.5.1",
|
"prettier": "^3.0.3",
|
||||||
"pretty-ms": "^7.0.1",
|
"pretty-ms": "^8.0.0",
|
||||||
"react": "^17.0.2",
|
"react": "^18.2.0",
|
||||||
"release-it": "^14.12.1",
|
"tsx": "^3.13.0",
|
||||||
"tsup": "^5.11.11",
|
"type-fest": "^4.4.0"
|
||||||
"type-fest": "^2.9.0",
|
|
||||||
"typescript": "^4.5.4",
|
|
||||||
"vite": "^2.7.10",
|
|
||||||
"vitest": "^0.0.141"
|
|
||||||
},
|
|
||||||
"resolutions": {
|
|
||||||
"esbuild": "latest"
|
|
||||||
},
|
},
|
||||||
"release-it": {
|
"release-it": {
|
||||||
"git": {
|
"git": {
|
||||||
@@ -91,5 +80,8 @@
|
|||||||
"release": true,
|
"release": true,
|
||||||
"web": true
|
"web": true
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"publishConfig": {
|
||||||
|
"access": "public"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
import type { Client, CommandInteraction } from "discord.js"
|
|
||||||
|
|
||||||
type Command = {
|
|
||||||
name: string
|
|
||||||
description: string
|
|
||||||
run: (interaction: CommandInteraction) => unknown
|
|
||||||
}
|
|
||||||
|
|
||||||
export function createCommandHandler(client: Client, commands: Command[]) {
|
|
||||||
client.on("ready", async () => {
|
|
||||||
for (const command of commands) {
|
|
||||||
for (const guild of client.guilds.cache.values()) {
|
|
||||||
await client.application?.commands.create(
|
|
||||||
{
|
|
||||||
name: command.name,
|
|
||||||
description: command.description,
|
|
||||||
},
|
|
||||||
guild.id,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
client.on("interactionCreate", async (interaction) => {
|
|
||||||
if (!interaction.isCommand()) return
|
|
||||||
|
|
||||||
const command = commands.find(
|
|
||||||
(command) => command.name === interaction.commandName,
|
|
||||||
)
|
|
||||||
if (command) {
|
|
||||||
try {
|
|
||||||
await command.run(interaction)
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
import * as React from "react"
|
|
||||||
import { Button, Embed, EmbedField, EmbedTitle } from "../library/main"
|
|
||||||
|
|
||||||
export function Counter(props: { onDeactivate: () => void }) {
|
|
||||||
const [count, setCount] = React.useState(0)
|
|
||||||
const [embedVisible, setEmbedVisible] = React.useState(false)
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
this button was clicked {count} times
|
|
||||||
{embedVisible && (
|
|
||||||
<Embed>
|
|
||||||
<EmbedTitle>the counter</EmbedTitle>
|
|
||||||
{count > 0 && (
|
|
||||||
<EmbedField name="is it even?">
|
|
||||||
{count % 2 === 0 ? "yes" : "no"}
|
|
||||||
</EmbedField>
|
|
||||||
)}
|
|
||||||
</Embed>
|
|
||||||
)}
|
|
||||||
{embedVisible && (
|
|
||||||
<Button label="hide embed" onClick={() => setEmbedVisible(false)} />
|
|
||||||
)}
|
|
||||||
<Button
|
|
||||||
style="primary"
|
|
||||||
emoji="<:plus_one:778531744860602388>"
|
|
||||||
label="clicc"
|
|
||||||
onClick={() => setCount(count + 1)}
|
|
||||||
/>
|
|
||||||
{!embedVisible && (
|
|
||||||
<Button label="show embed" onClick={() => setEmbedVisible(true)} />
|
|
||||||
)}
|
|
||||||
<Button style="danger" label="deactivate" onClick={props.onDeactivate} />
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
import React, { useState } from "react"
|
|
||||||
import { Button, Option, Select } from "../library/main"
|
|
||||||
|
|
||||||
export function FruitSelect({
|
|
||||||
onConfirm,
|
|
||||||
}: {
|
|
||||||
onConfirm: (choice: string) => void
|
|
||||||
}) {
|
|
||||||
const [value, setValue] = useState<string>()
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Select
|
|
||||||
placeholder="choose a fruit"
|
|
||||||
value={value}
|
|
||||||
onChangeValue={setValue}
|
|
||||||
>
|
|
||||||
<Option value="🍎" />
|
|
||||||
<Option value="🍌" />
|
|
||||||
<Option value="🍒" />
|
|
||||||
</Select>
|
|
||||||
<Button
|
|
||||||
label="confirm"
|
|
||||||
disabled={value == undefined}
|
|
||||||
onClick={() => {
|
|
||||||
if (value) onConfirm(value)
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
import { Client } from "discord.js"
|
|
||||||
import "dotenv/config"
|
|
||||||
import React from "react"
|
|
||||||
import { Button, ReacordDiscordJs, useInstance } from "../library/main"
|
|
||||||
import { createCommandHandler } from "./command-handler"
|
|
||||||
import { Counter } from "./counter"
|
|
||||||
import { FruitSelect } from "./fruit-select"
|
|
||||||
|
|
||||||
const client = new Client({
|
|
||||||
intents: ["GUILDS"],
|
|
||||||
})
|
|
||||||
|
|
||||||
const reacord = new ReacordDiscordJs(client)
|
|
||||||
|
|
||||||
client.on("ready", () => {
|
|
||||||
console.info("ready 💖")
|
|
||||||
|
|
||||||
// const now = new Date()
|
|
||||||
|
|
||||||
// function UptimeCounter() {
|
|
||||||
// const [uptime, setUptime] = React.useState(0)
|
|
||||||
|
|
||||||
// React.useEffect(() => {
|
|
||||||
// const interval = setInterval(() => {
|
|
||||||
// setUptime(Date.now() - now.getTime())
|
|
||||||
// }, 5000)
|
|
||||||
// return () => clearInterval(interval)
|
|
||||||
// }, [])
|
|
||||||
|
|
||||||
// return (
|
|
||||||
// <Embed>this bot has been running for {prettyMilliseconds(uptime)}</Embed>
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
|
|
||||||
// reacord.send("671787605624487941", <UptimeCounter />)
|
|
||||||
})
|
|
||||||
|
|
||||||
createCommandHandler(client, [
|
|
||||||
{
|
|
||||||
name: "button",
|
|
||||||
description: "it's a button",
|
|
||||||
run: (interaction) => {
|
|
||||||
reacord.reply(
|
|
||||||
interaction,
|
|
||||||
<Button label="clic" onClick={() => console.info("was clic")} />,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "counter",
|
|
||||||
description: "shows a counter button",
|
|
||||||
run: (interaction) => {
|
|
||||||
const reply = reacord.reply(interaction)
|
|
||||||
reply.render(<Counter onDeactivate={() => reply.destroy()} />)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "select",
|
|
||||||
description: "shows a select",
|
|
||||||
run: (interaction) => {
|
|
||||||
const instance = reacord.reply(
|
|
||||||
interaction,
|
|
||||||
<FruitSelect
|
|
||||||
onConfirm={(value) => {
|
|
||||||
instance.render(`you chose ${value}`)
|
|
||||||
instance.deactivate()
|
|
||||||
}}
|
|
||||||
/>,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "ephemeral-button",
|
|
||||||
description: "button which shows ephemeral messages",
|
|
||||||
run: (interaction) => {
|
|
||||||
reacord.reply(
|
|
||||||
interaction,
|
|
||||||
<>
|
|
||||||
<Button
|
|
||||||
label="public clic"
|
|
||||||
onClick={(event) =>
|
|
||||||
reacord.reply(
|
|
||||||
interaction,
|
|
||||||
`${event.guild?.member.displayName} clic`,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Button
|
|
||||||
label="clic"
|
|
||||||
onClick={(event) => event.ephemeralReply("you clic")}
|
|
||||||
/>
|
|
||||||
</>,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "delete-this",
|
|
||||||
description: "delete this",
|
|
||||||
run: (interaction) => {
|
|
||||||
function DeleteThis() {
|
|
||||||
const instance = useInstance()
|
|
||||||
return <Button label="delete this" onClick={() => instance.destroy()} />
|
|
||||||
}
|
|
||||||
reacord.reply(interaction, <DeleteThis />)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
await client.login(process.env.TEST_BOT_TOKEN)
|
|
||||||
193
packages/reacord/scripts/discordjs-manual-test.tsx
Normal file
193
packages/reacord/scripts/discordjs-manual-test.tsx
Normal file
@@ -0,0 +1,193 @@
|
|||||||
|
import { raise } from "@reacord/helpers/raise.js"
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Embed,
|
||||||
|
EmbedField,
|
||||||
|
Link,
|
||||||
|
Option,
|
||||||
|
ReacordDiscordJs,
|
||||||
|
Select,
|
||||||
|
useInstance,
|
||||||
|
} from "../library/main.js"
|
||||||
|
import type { TextChannel } from "discord.js"
|
||||||
|
import { ChannelType, Client, IntentsBitField } from "discord.js"
|
||||||
|
import "dotenv/config"
|
||||||
|
import { kebabCase } from "lodash-es"
|
||||||
|
import { useState } from "react"
|
||||||
|
|
||||||
|
const client = new Client({ intents: IntentsBitField.Flags.Guilds })
|
||||||
|
const reacord = new ReacordDiscordJs(client)
|
||||||
|
|
||||||
|
await client.login(process.env.TEST_BOT_TOKEN)
|
||||||
|
|
||||||
|
const guild = await client.guilds.fetch(
|
||||||
|
process.env.TEST_GUILD_ID ?? raise("TEST_GUILD_ID not defined"),
|
||||||
|
)
|
||||||
|
|
||||||
|
const category = await guild.channels.fetch(
|
||||||
|
process.env.TEST_CATEGORY_ID ?? raise("TEST_CATEGORY_ID not defined"),
|
||||||
|
)
|
||||||
|
if (category?.type !== ChannelType.GuildCategory) {
|
||||||
|
throw new Error(
|
||||||
|
`channel ${process.env.TEST_CATEGORY_ID} is not a guild category. received ${category?.type}`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const [, channel] of category.children.cache) {
|
||||||
|
await channel.delete()
|
||||||
|
}
|
||||||
|
|
||||||
|
let prefix = 0
|
||||||
|
const createTest = async (
|
||||||
|
name: string,
|
||||||
|
block: (channel: TextChannel) => unknown,
|
||||||
|
) => {
|
||||||
|
prefix += 1
|
||||||
|
const channel = await category.children.create({
|
||||||
|
type: ChannelType.GuildText,
|
||||||
|
name: `${String(prefix).padStart(3, "0")}-${kebabCase(name)}`,
|
||||||
|
})
|
||||||
|
await block(channel)
|
||||||
|
}
|
||||||
|
|
||||||
|
await createTest("basic", (channel) => {
|
||||||
|
reacord.createChannelMessage(channel).render("Hello, world!")
|
||||||
|
})
|
||||||
|
|
||||||
|
await createTest("readme counter", (channel) => {
|
||||||
|
interface EmbedCounterProps {
|
||||||
|
count: number
|
||||||
|
visible: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
function EmbedCounter({ count, visible }: EmbedCounterProps) {
|
||||||
|
if (!visible) return <></>
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Embed title="the counter">
|
||||||
|
<EmbedField name="is it even?">{count % 2 ? "no" : "yes"}</EmbedField>
|
||||||
|
</Embed>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Counter() {
|
||||||
|
const [showEmbed, setShowEmbed] = useState(false)
|
||||||
|
const [count, setCount] = useState(0)
|
||||||
|
const instance = useInstance()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
this button was clicked {count} times
|
||||||
|
<EmbedCounter count={count} visible={showEmbed} />
|
||||||
|
<Button
|
||||||
|
style="primary"
|
||||||
|
label="clicc"
|
||||||
|
onClick={() => setCount(count + 1)}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
style="secondary"
|
||||||
|
label={showEmbed ? "hide embed" : "show embed"}
|
||||||
|
onClick={() => setShowEmbed(!showEmbed)}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
style="danger"
|
||||||
|
label="deactivate"
|
||||||
|
onClick={() => instance.destroy()}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
reacord.createChannelMessage(channel).render(<Counter />)
|
||||||
|
})
|
||||||
|
|
||||||
|
await createTest("counter", (channel) => {
|
||||||
|
function Counter() {
|
||||||
|
const [count, setCount] = useState(0)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
count: {count}
|
||||||
|
<Button
|
||||||
|
style="primary"
|
||||||
|
emoji="➕"
|
||||||
|
onClick={() => setCount(count + 1)}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
style="primary"
|
||||||
|
emoji="➖"
|
||||||
|
onClick={() => setCount(count - 1)}
|
||||||
|
/>
|
||||||
|
<Button label="reset" onClick={() => setCount(0)} />
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
reacord.createChannelMessage(channel).render(<Counter />)
|
||||||
|
})
|
||||||
|
|
||||||
|
await createTest("select", (channel) => {
|
||||||
|
function FruitSelect({ onConfirm }: { onConfirm: (choice: string) => void }) {
|
||||||
|
const [value, setValue] = useState<string>()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Select
|
||||||
|
placeholder="choose a fruit"
|
||||||
|
value={value}
|
||||||
|
onChangeValue={setValue}
|
||||||
|
>
|
||||||
|
<Option value="🍎" emoji="🍎" label="apple" description="it red" />
|
||||||
|
<Option value="🍌" emoji="🍌" label="banana" description="bnanbna" />
|
||||||
|
<Option value="🍒" emoji="🍒" label="cherry" description="heh" />
|
||||||
|
</Select>
|
||||||
|
<Button
|
||||||
|
label="confirm"
|
||||||
|
disabled={value == undefined}
|
||||||
|
onClick={() => {
|
||||||
|
if (value) onConfirm(value)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const instance = reacord.createChannelMessage(channel).render(
|
||||||
|
<FruitSelect
|
||||||
|
onConfirm={(value) => {
|
||||||
|
instance.render(`you chose ${value}`)
|
||||||
|
instance.deactivate()
|
||||||
|
}}
|
||||||
|
/>,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
await createTest("ephemeral button", (channel) => {
|
||||||
|
reacord.createChannelMessage(channel).render(
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
label="public clic"
|
||||||
|
onClick={(event) =>
|
||||||
|
event.reply(`${event.guild?.member.displayName} clic`)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
label="clic"
|
||||||
|
onClick={(event) => event.reply("you clic", { ephemeral: true })}
|
||||||
|
/>
|
||||||
|
</>,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
await createTest("delete this", (channel) => {
|
||||||
|
function DeleteThis() {
|
||||||
|
const instance = useInstance()
|
||||||
|
return <Button label="delete this" onClick={() => instance.destroy()} />
|
||||||
|
}
|
||||||
|
reacord.createChannelMessage(channel).render(<DeleteThis />)
|
||||||
|
})
|
||||||
|
|
||||||
|
await createTest("link", (channel) => {
|
||||||
|
reacord
|
||||||
|
.createChannelMessage(channel)
|
||||||
|
.render(<Link label="hi" url="https://mapleleaf.dev" />)
|
||||||
|
})
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
pnpm build
|
|
||||||
cp ../../README.md .
|
|
||||||
cp ../../LICENSE .
|
|
||||||
pnpx release-it
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import React from "react"
|
|
||||||
import { test } from "vitest"
|
import { test } from "vitest"
|
||||||
import { ActionRow, Button, Select } from "../library/main"
|
import { ActionRow, Button, Select } from "../library/main"
|
||||||
import { ReacordTester } from "./test-adapter"
|
import { ReacordTester } from "./test-adapter"
|
||||||
|
|||||||
15
packages/reacord/test/commonjs-require.test.ts
Normal file
15
packages/reacord/test/commonjs-require.test.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import { spawnSync } from "node:child_process"
|
||||||
|
import { fileURLToPath } from "node:url"
|
||||||
|
import { dirname } from "node:path"
|
||||||
|
import { createRequire } from "node:module"
|
||||||
|
import { beforeAll, expect, test } from "vitest"
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
const cwd = dirname(dirname(fileURLToPath(import.meta.url)))
|
||||||
|
spawnSync("bun", ["run", "build"], { cwd })
|
||||||
|
})
|
||||||
|
|
||||||
|
test("can require commonjs", () => {
|
||||||
|
const require = createRequire(import.meta.url)
|
||||||
|
expect(() => require("../dist/main.cjs") as unknown).not.toThrow()
|
||||||
|
})
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import React from "react"
|
|
||||||
import { test } from "vitest"
|
import { test } from "vitest"
|
||||||
import {
|
import {
|
||||||
Embed,
|
Embed,
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
import { test } from "vitest"
|
import { test } from "vitest"
|
||||||
|
|
||||||
test.todo("ephemeral reply")
|
test.todo("ephemeral reply")
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import React from "react"
|
|
||||||
import { test } from "vitest"
|
import { test } from "vitest"
|
||||||
import { Link } from "../library/main"
|
import { Link } from "../library/main"
|
||||||
import { ReacordTester } from "./test-adapter"
|
import { ReacordTester } from "./test-adapter"
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
import * as React from "react"
|
|
||||||
import { test } from "vitest"
|
|
||||||
import { Button, Embed, EmbedField, EmbedTitle } from "../library/main"
|
import { Button, Embed, EmbedField, EmbedTitle } from "../library/main"
|
||||||
import { ReacordTester } from "./test-adapter"
|
import { ReacordTester } from "./test-adapter"
|
||||||
|
import * as React from "react"
|
||||||
|
import { test } from "vitest"
|
||||||
|
|
||||||
test("rendering behavior", async () => {
|
test("rendering behavior", async () => {
|
||||||
const tester = new ReacordTester()
|
const tester = new ReacordTester()
|
||||||
|
|
||||||
const reply = tester.reply()
|
const reply = tester
|
||||||
reply.render(<KitchenSinkCounter onDeactivate={() => reply.deactivate()} />)
|
.createInteractionReply()
|
||||||
|
.render(<KitchenSinkCounter onDeactivate={() => reply.deactivate()} />)
|
||||||
|
|
||||||
await tester.assertMessages([
|
await tester.assertMessages([
|
||||||
{
|
{
|
||||||
@@ -35,7 +36,7 @@ test("rendering behavior", async () => {
|
|||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
tester.findButtonByLabel("show embed").click()
|
await tester.findButtonByLabel("show embed").click()
|
||||||
await tester.assertMessages([
|
await tester.assertMessages([
|
||||||
{
|
{
|
||||||
content: "count: 0",
|
content: "count: 0",
|
||||||
@@ -62,7 +63,7 @@ test("rendering behavior", async () => {
|
|||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
tester.findButtonByLabel("clicc").click()
|
await tester.findButtonByLabel("clicc").click()
|
||||||
await tester.assertMessages([
|
await tester.assertMessages([
|
||||||
{
|
{
|
||||||
content: "count: 1",
|
content: "count: 1",
|
||||||
@@ -94,7 +95,7 @@ test("rendering behavior", async () => {
|
|||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
tester.findButtonByLabel("clicc").click()
|
await tester.findButtonByLabel("clicc").click()
|
||||||
await tester.assertMessages([
|
await tester.assertMessages([
|
||||||
{
|
{
|
||||||
content: "count: 2",
|
content: "count: 2",
|
||||||
@@ -126,7 +127,7 @@ test("rendering behavior", async () => {
|
|||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
tester.findButtonByLabel("hide embed").click()
|
await tester.findButtonByLabel("hide embed").click()
|
||||||
await tester.assertMessages([
|
await tester.assertMessages([
|
||||||
{
|
{
|
||||||
content: "count: 2",
|
content: "count: 2",
|
||||||
@@ -153,7 +154,7 @@ test("rendering behavior", async () => {
|
|||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
tester.findButtonByLabel("clicc").click()
|
await tester.findButtonByLabel("clicc").click()
|
||||||
await tester.assertMessages([
|
await tester.assertMessages([
|
||||||
{
|
{
|
||||||
content: "count: 3",
|
content: "count: 3",
|
||||||
@@ -180,7 +181,7 @@ test("rendering behavior", async () => {
|
|||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
tester.findButtonByLabel("deactivate").click()
|
await tester.findButtonByLabel("deactivate").click()
|
||||||
await tester.assertMessages([
|
await tester.assertMessages([
|
||||||
{
|
{
|
||||||
content: "count: 3",
|
content: "count: 3",
|
||||||
@@ -210,7 +211,7 @@ test("rendering behavior", async () => {
|
|||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
tester.findButtonByLabel("clicc").click()
|
await tester.findButtonByLabel("clicc").click()
|
||||||
await tester.assertMessages([
|
await tester.assertMessages([
|
||||||
{
|
{
|
||||||
content: "count: 3",
|
content: "count: 3",
|
||||||
@@ -244,8 +245,7 @@ test("rendering behavior", async () => {
|
|||||||
test("delete", async () => {
|
test("delete", async () => {
|
||||||
const tester = new ReacordTester()
|
const tester = new ReacordTester()
|
||||||
|
|
||||||
const reply = tester.reply()
|
const reply = tester.createInteractionReply().render(
|
||||||
reply.render(
|
|
||||||
<>
|
<>
|
||||||
some text
|
some text
|
||||||
<Embed>some embed</Embed>
|
<Embed>some embed</Embed>
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import React, { useState } from "react"
|
import { useState } from "react"
|
||||||
import { expect, fn, test } from "vitest"
|
import { expect, test, vi } from "vitest"
|
||||||
import { Button, Option, Select } from "../library/main"
|
import { Button, Option, Select } from "../library/main"
|
||||||
import { ReacordTester } from "./test-adapter"
|
import { ReacordTester } from "./test-adapter"
|
||||||
|
|
||||||
test("single select", async () => {
|
test("single select", async () => {
|
||||||
const tester = new ReacordTester()
|
const tester = new ReacordTester()
|
||||||
const onSelect = fn()
|
const onSelect = vi.fn()
|
||||||
|
|
||||||
function TestSelect() {
|
function TestSelect() {
|
||||||
const [value, setValue] = useState<string>()
|
const [value, setValue] = useState<string>()
|
||||||
@@ -53,29 +53,27 @@ test("single select", async () => {
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
const reply = tester.reply()
|
tester.createInteractionReply().render(<TestSelect />)
|
||||||
|
|
||||||
reply.render(<TestSelect />)
|
|
||||||
await assertSelect([])
|
await assertSelect([])
|
||||||
expect(onSelect).toHaveBeenCalledTimes(0)
|
expect(onSelect).toHaveBeenCalledTimes(0)
|
||||||
|
|
||||||
tester.findSelectByPlaceholder("choose one").select("2")
|
await tester.findSelectByPlaceholder("choose one").select("2")
|
||||||
await assertSelect(["2"])
|
await assertSelect(["2"])
|
||||||
expect(onSelect).toHaveBeenCalledWith(
|
expect(onSelect).toHaveBeenCalledWith(
|
||||||
expect.objectContaining({ values: ["2"] }),
|
expect.objectContaining({ values: ["2"] }),
|
||||||
)
|
)
|
||||||
|
|
||||||
tester.findButtonByLabel("disable").click()
|
await tester.findButtonByLabel("disable").click()
|
||||||
await assertSelect(["2"], true)
|
await assertSelect(["2"], true)
|
||||||
|
|
||||||
tester.findSelectByPlaceholder("choose one").select("1")
|
await tester.findSelectByPlaceholder("choose one").select("1")
|
||||||
await assertSelect(["2"], true)
|
await assertSelect(["2"], true)
|
||||||
expect(onSelect).toHaveBeenCalledTimes(1)
|
expect(onSelect).toHaveBeenCalledTimes(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
test("multiple select", async () => {
|
test("multiple select", async () => {
|
||||||
const tester = new ReacordTester()
|
const tester = new ReacordTester()
|
||||||
const onSelect = fn()
|
const onSelect = vi.fn()
|
||||||
|
|
||||||
function TestSelect() {
|
function TestSelect() {
|
||||||
const [values, setValues] = useState<string[]>([])
|
const [values, setValues] = useState<string[]>([])
|
||||||
@@ -119,33 +117,35 @@ test("multiple select", async () => {
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
const reply = tester.reply()
|
tester.createInteractionReply().render(<TestSelect />)
|
||||||
|
|
||||||
reply.render(<TestSelect />)
|
|
||||||
await assertSelect([])
|
await assertSelect([])
|
||||||
expect(onSelect).toHaveBeenCalledTimes(0)
|
expect(onSelect).toHaveBeenCalledTimes(0)
|
||||||
|
|
||||||
tester.findSelectByPlaceholder("select").select("1", "3")
|
await tester.findSelectByPlaceholder("select").select("1", "3")
|
||||||
await assertSelect(expect.arrayContaining(["1", "3"]) as unknown as string[])
|
await assertSelect(expect.arrayContaining(["1", "3"]) as unknown as string[])
|
||||||
expect(onSelect).toHaveBeenCalledWith(
|
expect(onSelect).toHaveBeenCalledWith(
|
||||||
expect.objectContaining({ values: expect.arrayContaining(["1", "3"]) }),
|
expect.objectContaining({
|
||||||
|
values: expect.arrayContaining(["1", "3"]) as unknown,
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
tester.findSelectByPlaceholder("select").select("2")
|
await tester.findSelectByPlaceholder("select").select("2")
|
||||||
await assertSelect(expect.arrayContaining(["2"]) as unknown as string[])
|
await assertSelect(expect.arrayContaining(["2"]) as unknown as string[])
|
||||||
expect(onSelect).toHaveBeenCalledWith(
|
expect(onSelect).toHaveBeenCalledWith(
|
||||||
expect.objectContaining({ values: expect.arrayContaining(["2"]) }),
|
expect.objectContaining({
|
||||||
|
values: expect.arrayContaining(["2"]) as unknown,
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
tester.findSelectByPlaceholder("select").select()
|
await tester.findSelectByPlaceholder("select").select()
|
||||||
await assertSelect([])
|
await assertSelect([])
|
||||||
expect(onSelect).toHaveBeenCalledWith(expect.objectContaining({ values: [] }))
|
expect(onSelect).toHaveBeenCalledWith(expect.objectContaining({ values: [] }))
|
||||||
})
|
})
|
||||||
|
|
||||||
test("optional onSelect + unknown value", async () => {
|
test("optional onSelect + unknown value", async () => {
|
||||||
const tester = new ReacordTester()
|
const tester = new ReacordTester()
|
||||||
tester.reply().render(<Select placeholder="select" />)
|
tester.createInteractionReply().render(<Select placeholder="select" />)
|
||||||
tester.findSelectByPlaceholder("select").select("something")
|
await tester.findSelectByPlaceholder("select").select("something")
|
||||||
await tester.assertMessages([
|
await tester.assertMessages([
|
||||||
{
|
{
|
||||||
content: "",
|
content: "",
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user