Compare commits
245 Commits
use-instan
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9594542869 | ||
|
|
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 | ||
|
|
05bda71ad6 | ||
|
|
0217fb8533 | ||
|
|
b59dcc0ae7 | ||
|
|
3efaef162b | ||
|
|
4c2aafe185 | ||
|
|
d3d1f473ae | ||
|
|
116e606db1 | ||
|
|
490bf2cefa | ||
|
|
e06bfa490f | ||
|
|
2765b4fda4 | ||
|
|
5660297588 | ||
|
|
2cdd324495 | ||
|
|
7a09e8fdca | ||
|
|
8111931183 | ||
|
|
fd64132e58 | ||
|
|
1ba0da6c86 | ||
|
|
fdd6a3a3cc | ||
|
|
8ce3834cf4 | ||
|
|
1bfbe9608c | ||
|
|
0695bbc6bd | ||
|
|
569e5c7473 | ||
|
|
62300d23ca | ||
|
|
cda69a0c85 | ||
|
|
785384286b | ||
|
|
50961e888e | ||
|
|
8c3304144e | ||
|
|
b6b05232f7 | ||
|
|
33a170a4fb | ||
|
|
9a6f85a726 | ||
|
|
a79649048f | ||
|
|
e7196e686c | ||
|
|
26eb8bedb0 | ||
|
|
2851d4b787 | ||
|
|
46d3c64133 | ||
|
|
6b77971ed5 | ||
|
|
effd16ed97 | ||
|
|
989ab330b3 | ||
|
|
0aafc66ce1 | ||
|
|
ff8347b52a | ||
|
|
c436500b3a | ||
|
|
e93506409f | ||
|
|
8482f6e91a | ||
|
|
c5e11b4417 | ||
|
|
2e4ff0f524 | ||
|
|
d0c940c693 | ||
|
|
01f245c2e2 | ||
|
|
b65004dd75 | ||
|
|
d9dd4d5307 | ||
|
|
2b3b8953d0 | ||
|
|
a6b706a3de | ||
|
|
d3f6c8af4d | ||
|
|
b0e937f896 | ||
|
|
8b371cd1cf | ||
|
|
ba155226f1 | ||
|
|
a1424f4607 | ||
|
|
42461c7ec8 | ||
|
|
27f793b1db | ||
|
|
97a5526d9d | ||
|
|
99eebef9a9 | ||
|
|
1b97f9256f | ||
|
|
1a04e6093d | ||
|
|
4803cb8478 | ||
|
|
4201f45cc9 | ||
|
|
52b83522de | ||
|
|
017a417773 |
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": []
|
||||
}
|
||||
5
.changeset/five-wolves-destroy.md
Normal file
5
.changeset/five-wolves-destroy.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"reacord": minor
|
||||
---
|
||||
|
||||
breaking: more descriptive component event types
|
||||
33
.changeset/many-pets-melt.md
Normal file
33
.changeset/many-pets-melt.md
Normal file
@@ -0,0 +1,33 @@
|
||||
---
|
||||
"reacord": minor
|
||||
---
|
||||
|
||||
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.
|
||||
@@ -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/docs/cypress/**"],
|
||||
"parserOptions": {
|
||||
"project": "./packages/docs/cypress/tsconfig.json"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
18
.github/workflows/deploy-docs.yml
vendored
18
.github/workflows/deploy-docs.yml
vendored
@@ -1,18 +0,0 @@
|
||||
name: deploy docs
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths:
|
||||
- "packages/docs/**"
|
||||
- "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"
|
||||
37
.github/workflows/main.yml
vendored
37
.github/workflows/main.yml
vendored
@@ -1,37 +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-scripts:
|
||||
strategy:
|
||||
matrix:
|
||||
scripts:
|
||||
- name: test
|
||||
script: coverage
|
||||
- name: lint
|
||||
script: lint
|
||||
- name: typecheck
|
||||
script: typecheck
|
||||
- name: build
|
||||
script: build
|
||||
fail-fast: false
|
||||
name: ${{ matrix.scripts.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: pnpm run --recursive ${{ matrix.scripts.script }}
|
||||
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
|
||||
coverage
|
||||
.env
|
||||
|
||||
*.code-workspace
|
||||
.pnpm-debug.log
|
||||
build
|
||||
.cache
|
||||
.vercel
|
||||
*.tsbuildinfo
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
node_modules
|
||||
dist
|
||||
coverage
|
||||
pnpm-lock.yaml
|
||||
build
|
||||
.cache
|
||||
/packages/website/public/api
|
||||
.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/docs
|
||||
|
||||
ENV NODE_ENV=production
|
||||
CMD [ "pnpm", "-C", "packages/docs", "start" ]
|
||||
12
README.md
12
README.md
@@ -1,7 +1,9 @@
|
||||
# reacord
|
||||
Create interactive Discord messages using React!
|
||||
<center>
|
||||
<img src="packages/website/src/assets/banner.png" alt="Reacord: Create interactive Discord messages using React">
|
||||
</center>
|
||||
|
||||
## Installation ∙ [](https://www.npmjs.com/package/reacord)
|
||||
|
||||
## Installation
|
||||
```console
|
||||
# npm
|
||||
npm install reacord react discord.js
|
||||
@@ -15,9 +17,11 @@ pnpm add reacord react discord.js
|
||||
```
|
||||
|
||||
## Get Started
|
||||
[Visit the docs to get started.](https://reacord.fly.dev/guides/getting-started)
|
||||
|
||||
[Visit the docs to get started.](https://reacord.mapleleaf.dev/guides/getting-started)
|
||||
|
||||
## Example
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```tsx
|
||||
import * as React from "react"
|
||||
|
||||
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"
|
||||
59
package.json
59
package.json
@@ -1,29 +1,44 @@
|
||||
{
|
||||
"name": "reacord-monorepo",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"lint": "eslint --ext js,ts,tsx .",
|
||||
"lint-fix": "pnpm lint -- --fix",
|
||||
"format": "prettier --write ."
|
||||
},
|
||||
"dependencies": {
|
||||
"@itsmapleleaf/configs": "^1.1.2"
|
||||
"lint": "run-s --continue-on-error lint:*",
|
||||
"lint:eslint": "eslint . --fix --cache --cache-file=node_modules/.cache/.eslintcache --report-unused-disable-directives",
|
||||
"lint:prettier": "prettier . \"**/*.astro\" --write --cache --list-different",
|
||||
"lint:types": "tsc -b & pnpm -r --parallel run typecheck",
|
||||
"astro-sync": "pnpm --filter website exec astro sync",
|
||||
"test": "vitest",
|
||||
"build": "pnpm -r run build",
|
||||
"build:website": "pnpm --filter website... run build",
|
||||
"start": "pnpm -C packages/website run start",
|
||||
"start:website": "pnpm -C packages/website run start",
|
||||
"release": "pnpm -r run build && changeset publish"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "^5.9.0",
|
||||
"@typescript-eslint/parser": "^5.9.0",
|
||||
"eslint": "^8.6.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-import-resolver-typescript": "^2.5.0",
|
||||
"eslint-plugin-import": "^2.25.4",
|
||||
"eslint-plugin-jsx-a11y": "^6.5.1",
|
||||
"eslint-plugin-react": "^7.28.0",
|
||||
"eslint-plugin-react-hooks": "^4.3.0",
|
||||
"eslint-plugin-unicorn": "^39.0.0",
|
||||
"prettier": "^2.5.1",
|
||||
"typescript": "^4.5.4"
|
||||
"@changesets/cli": "^2.26.2",
|
||||
"@itsmapleleaf/configs": "github:itsMapleLeaf/configs",
|
||||
"eslint": "^8.51.0",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"prettier": "^3.0.3",
|
||||
"react": "^18.2.0",
|
||||
"tailwindcss": "^3.3.3",
|
||||
"typescript": "^5.2.2",
|
||||
"vitest": "^0.34.6"
|
||||
},
|
||||
"resolutions": {
|
||||
"esbuild": "latest"
|
||||
},
|
||||
"prettier": "@itsmapleleaf/configs/prettier"
|
||||
"prettier": "@itsmapleleaf/configs/prettier",
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"./node_modules/@itsmapleleaf/configs/eslint.config.cjs",
|
||||
"./node_modules/@itsmapleleaf/configs/eslint.config.react.cjs"
|
||||
],
|
||||
"ignorePatterns": [
|
||||
"node_modules",
|
||||
"dist",
|
||||
"packages/website/public/api"
|
||||
],
|
||||
"rules": {
|
||||
"@typescript-eslint/no-non-null-assertion": "warn",
|
||||
"@typescript-eslint/require-await": "off"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
import { hydrate } from "react-dom";
|
||||
import { RemixBrowser } from "remix";
|
||||
|
||||
hydrate(<RemixBrowser />, document);
|
||||
@@ -1,21 +0,0 @@
|
||||
import { renderToString } from "react-dom/server";
|
||||
import { RemixServer } from "remix";
|
||||
import type { EntryContext } from "remix";
|
||||
|
||||
export default function handleRequest(
|
||||
request: Request,
|
||||
responseStatusCode: number,
|
||||
responseHeaders: Headers,
|
||||
remixContext: EntryContext
|
||||
) {
|
||||
const markup = renderToString(
|
||||
<RemixServer context={remixContext} url={request.url} />
|
||||
);
|
||||
|
||||
responseHeaders.set("Content-Type", "text/html");
|
||||
|
||||
return new Response("<!DOCTYPE html>" + markup, {
|
||||
status: responseStatusCode,
|
||||
headers: responseHeaders
|
||||
});
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
export function raise(error: unknown): never {
|
||||
throw error instanceof Error ? error : new Error(String(error))
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
{/* prettier-ignore */}
|
||||
```tsx
|
||||
import * as React from "react"
|
||||
import { Embed, Button } from "reacord"
|
||||
|
||||
function Counter() {
|
||||
const [count, setCount] = React.useState(0)
|
||||
return (
|
||||
<>
|
||||
<Embed title="Counter">
|
||||
This button has been clicked {count} times.
|
||||
</Embed>
|
||||
<Button onClick={() => setCount(count + 1)}>
|
||||
+1
|
||||
</Button>
|
||||
</>
|
||||
)
|
||||
}
|
||||
```
|
||||
@@ -1,31 +0,0 @@
|
||||
import type { ComponentPropsWithoutRef } from "react"
|
||||
import { Link } from "remix"
|
||||
|
||||
export type AppLinkProps = ComponentPropsWithoutRef<"a"> & {
|
||||
type: "internal" | "external" | "router"
|
||||
to: string
|
||||
}
|
||||
|
||||
export function AppLink({ type, to, children, ...props }: AppLinkProps) {
|
||||
if (type === "internal") {
|
||||
return (
|
||||
<a href={to} {...props}>
|
||||
{children}
|
||||
</a>
|
||||
)
|
||||
}
|
||||
|
||||
if (type === "external") {
|
||||
return (
|
||||
<a href={to} target="_blank" rel="noopener noreferrer" {...props}>
|
||||
{children}
|
||||
</a>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<Link to={to} {...props}>
|
||||
{children}
|
||||
</Link>
|
||||
)
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import { createContext, useContext } from "react"
|
||||
import type { GuideLink } from "~/modules/navigation/load-guide-links.server"
|
||||
|
||||
const Context = createContext<GuideLink[]>([])
|
||||
|
||||
export const GuideLinksProvider = Context.Provider
|
||||
|
||||
export function useGuideLinksContext() {
|
||||
return useContext(Context)
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
import glob from "fast-glob"
|
||||
import grayMatter from "gray-matter"
|
||||
import { readFile } from "node:fs/promises"
|
||||
import { join, parse } from "node:path"
|
||||
import type { AppLinkProps } from "~/modules/navigation/app-link"
|
||||
|
||||
const guidesFolder = "app/routes/guides"
|
||||
|
||||
export type GuideLink = {
|
||||
title: string
|
||||
order: number
|
||||
link: AppLinkProps
|
||||
}
|
||||
|
||||
export async function loadGuideLinks(): Promise<GuideLink[]> {
|
||||
const guideFiles = await glob(`**/*.md`, { cwd: guidesFolder })
|
||||
|
||||
const links: GuideLink[] = await Promise.all(
|
||||
guideFiles.map(async (file) => {
|
||||
const { data } = grayMatter(await readFile(join(guidesFolder, file)))
|
||||
|
||||
let order = data.order
|
||||
if (!Number.isFinite(order)) {
|
||||
order = Number.POSITIVE_INFINITY
|
||||
}
|
||||
|
||||
return {
|
||||
title: data.meta?.title,
|
||||
order,
|
||||
link: {
|
||||
type: "router",
|
||||
to: `/guides/${parse(file).name}`,
|
||||
children: data.meta?.title,
|
||||
},
|
||||
}
|
||||
}),
|
||||
)
|
||||
|
||||
return links.sort((a, b) => a.order - b.order)
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
import {
|
||||
CodeIcon,
|
||||
DocumentTextIcon,
|
||||
ExternalLinkIcon,
|
||||
} from "@heroicons/react/solid"
|
||||
import type { AppLinkProps } from "~/modules/navigation/app-link"
|
||||
import { inlineIconClass } from "../ui/components"
|
||||
|
||||
export const mainLinks: AppLinkProps[] = [
|
||||
{
|
||||
type: "internal",
|
||||
to: "/guides/getting-started",
|
||||
children: (
|
||||
<>
|
||||
<DocumentTextIcon className={inlineIconClass} /> Guides
|
||||
</>
|
||||
),
|
||||
},
|
||||
{
|
||||
type: "internal",
|
||||
to: "/api",
|
||||
children: (
|
||||
<>
|
||||
<CodeIcon className={inlineIconClass} /> API Reference
|
||||
</>
|
||||
),
|
||||
},
|
||||
{
|
||||
type: "external",
|
||||
to: "https://github.com/itsMapleLeaf/reacord",
|
||||
children: (
|
||||
<>
|
||||
<ExternalLinkIcon className={inlineIconClass} /> GitHub
|
||||
</>
|
||||
),
|
||||
},
|
||||
]
|
||||
@@ -1,42 +0,0 @@
|
||||
import { useGuideLinksContext } from "~/modules/navigation/guide-links-context"
|
||||
import { linkClass } from "../ui/components"
|
||||
import { PopoverMenu } from "../ui/popover-menu"
|
||||
import { AppLink } from "./app-link"
|
||||
import { mainLinks } from "./main-links"
|
||||
|
||||
export function MainNavigation() {
|
||||
const guideLinks = useGuideLinksContext()
|
||||
return (
|
||||
<nav className="flex justify-between items-center h-16">
|
||||
<a href="/">
|
||||
<h1 className="text-3xl font-light">reacord</h1>
|
||||
</a>
|
||||
<div className="hidden md:flex gap-4">
|
||||
{mainLinks.map((link) => (
|
||||
<AppLink {...link} key={link.to} className={linkClass} />
|
||||
))}
|
||||
</div>
|
||||
<div className="md:hidden">
|
||||
<PopoverMenu>
|
||||
{mainLinks.map((link) => (
|
||||
<AppLink
|
||||
{...link}
|
||||
role="menuitem"
|
||||
key={link.to}
|
||||
className={PopoverMenu.itemClass}
|
||||
/>
|
||||
))}
|
||||
<hr className="border-0 h-[2px] bg-black/50" />
|
||||
{guideLinks.map(({ link }) => (
|
||||
<AppLink
|
||||
{...link}
|
||||
role="menuitem"
|
||||
key={link.to}
|
||||
className={PopoverMenu.itemClass}
|
||||
/>
|
||||
))}
|
||||
</PopoverMenu>
|
||||
</div>
|
||||
</nav>
|
||||
)
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
import clsx from "clsx"
|
||||
|
||||
export const maxWidthContainer = clsx`mx-auto w-full max-w-screen-lg px-4`
|
||||
|
||||
export const inlineIconClass = clsx`inline w-5 align-sub`
|
||||
|
||||
export const linkClass = clsx`
|
||||
font-medium inline-block relative
|
||||
opacity-60 hover:opacity-100 transition-opacity
|
||||
after:absolute after:block after:w-full after:h-px after:bg-white/50 after:translate-y-[3px] after:opacity-0 after:transition
|
||||
hover:after:translate-y-[-1px] hover:after:opacity-100
|
||||
`
|
||||
|
||||
export const docsProseClass = clsx`
|
||||
prose prose-invert
|
||||
prose-h1:font-light prose-h1:mb-4 prose-h1:text-3xl lg:prose-h1:text-4xl
|
||||
prose-h2:font-light
|
||||
prose-h3:font-light
|
||||
prose-p:my-4
|
||||
prose-a:font-medium prose-a:text-emerald-400 hover:prose-a:no-underline
|
||||
prose-strong:font-medium prose-strong:text-emerald-400
|
||||
prose-pre:font-monospace prose-pre:overflow-x-auto
|
||||
max-w-none
|
||||
`
|
||||
@@ -1,32 +0,0 @@
|
||||
import { MenuAlt4Icon } from "@heroicons/react/outline"
|
||||
import clsx from "clsx"
|
||||
import React from "react"
|
||||
import { linkClass } from "./components"
|
||||
|
||||
export function PopoverMenu({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<div className="relative" x-data="{ open: false }">
|
||||
<button title="Menu" className={linkClass} x-on:click="open = !open">
|
||||
<MenuAlt4Icon className="w-6" />
|
||||
</button>
|
||||
<div
|
||||
role="menu"
|
||||
className={`
|
||||
w-48 max-h-[calc(100vh-4rem)]
|
||||
absolute right-0 top-[calc(100%+8px)]
|
||||
bg-slate-800 shadow rounded-lg
|
||||
overflow-hidden overflow-y-auto
|
||||
transition-all
|
||||
`}
|
||||
x-bind:class="open ? 'visible opacity-100' : 'invisible opacity-0 translate-y-3'"
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
PopoverMenu.itemClass = clsx`
|
||||
px-3 py-2 transition text-left font-medium block
|
||||
opacity-50 hover:opacity-100 hover:bg-black/30
|
||||
`
|
||||
@@ -1,133 +0,0 @@
|
||||
/**
|
||||
* Nord Theme Originally by Arctic Ice Studio
|
||||
* https://nordtheme.com
|
||||
*
|
||||
* Ported for PrismJS by Zane Hitchcoxc (@zwhitchcox) and Gabriel Ramos (@gabrieluizramos)
|
||||
*/
|
||||
|
||||
code[class*="language-"],
|
||||
pre[class*="language-"] {
|
||||
color: #f8f8f2;
|
||||
background: none;
|
||||
/* font-family: "Fira Code", Consolas, Monaco, "Andale Mono", "Ubuntu Mono",
|
||||
monospace; */
|
||||
text-align: left;
|
||||
white-space: pre;
|
||||
word-spacing: normal;
|
||||
word-break: normal;
|
||||
word-wrap: normal;
|
||||
line-height: 1.7;
|
||||
-moz-tab-size: 4;
|
||||
-o-tab-size: 4;
|
||||
tab-size: 4;
|
||||
-webkit-hyphens: none;
|
||||
-moz-hyphens: none;
|
||||
-ms-hyphens: none;
|
||||
hyphens: none;
|
||||
}
|
||||
|
||||
/* Code blocks */
|
||||
pre[class*="language-"] {
|
||||
padding: 1em;
|
||||
margin: 0.5em 0;
|
||||
overflow: auto;
|
||||
border-radius: 0.3em;
|
||||
}
|
||||
|
||||
:not(pre) > code[class*="language-"],
|
||||
pre[class*="language-"] {
|
||||
/* background: #2e3440; */
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
/* Inline code */
|
||||
:not(pre) > code[class*="language-"] {
|
||||
padding: 0.1em;
|
||||
border-radius: 0.3em;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.token.comment,
|
||||
.token.prolog,
|
||||
.token.doctype,
|
||||
.token.cdata {
|
||||
color: #636f88;
|
||||
}
|
||||
|
||||
.token.punctuation {
|
||||
color: #81a1c1;
|
||||
}
|
||||
|
||||
.namespace {
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.token.property,
|
||||
.token.tag,
|
||||
.token.constant,
|
||||
.token.symbol,
|
||||
.token.deleted {
|
||||
color: #81a1c1;
|
||||
}
|
||||
|
||||
.token.number {
|
||||
color: #b48ead;
|
||||
}
|
||||
|
||||
.token.boolean {
|
||||
color: #81a1c1;
|
||||
}
|
||||
|
||||
.token.selector,
|
||||
.token.attr-name,
|
||||
.token.string,
|
||||
.token.char,
|
||||
.token.builtin,
|
||||
.token.inserted {
|
||||
color: #a3be8c;
|
||||
}
|
||||
|
||||
.token.operator,
|
||||
.token.entity,
|
||||
.token.url,
|
||||
.language-css .token.string,
|
||||
.style .token.string,
|
||||
.token.variable {
|
||||
color: #81a1c1;
|
||||
}
|
||||
|
||||
.token.atrule,
|
||||
.token.attr-value,
|
||||
.token.function,
|
||||
.token.class-name {
|
||||
color: #88c0d0;
|
||||
}
|
||||
|
||||
.token.keyword {
|
||||
color: #81a1c1;
|
||||
}
|
||||
|
||||
.token.regex,
|
||||
.token.important {
|
||||
color: #ebcb8b;
|
||||
}
|
||||
|
||||
.token.important,
|
||||
.token.bold {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.token.italic {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.token.entity {
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
.code-line.highlight-line {
|
||||
background-color: rgba(255, 255, 255, 0.08);
|
||||
padding: 0 1rem;
|
||||
margin: 0 -1rem;
|
||||
display: block;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
@layer utilities {
|
||||
.prose aside {
|
||||
@apply opacity-75 italic border-l-4 pl-3 border-white/50;
|
||||
}
|
||||
}
|
||||
4
packages/docs/app/react.d.ts
vendored
4
packages/docs/app/react.d.ts
vendored
@@ -1,4 +0,0 @@
|
||||
import "react"
|
||||
declare module "react" {
|
||||
export function createContext<Value>(): Context<Value | undefined>
|
||||
}
|
||||
2
packages/docs/app/remix.env.d.ts
vendored
2
packages/docs/app/remix.env.d.ts
vendored
@@ -1,2 +0,0 @@
|
||||
/// <reference types="@remix-run/dev" />
|
||||
/// <reference types="@remix-run/node/globals" />
|
||||
@@ -1,68 +0,0 @@
|
||||
import packageJson from "reacord/package.json"
|
||||
import type { LinksFunction, LoaderFunction, MetaFunction } from "remix"
|
||||
import {
|
||||
Links,
|
||||
LiveReload,
|
||||
Meta,
|
||||
Outlet,
|
||||
ScrollRestoration,
|
||||
useLoaderData,
|
||||
} from "remix"
|
||||
import { GuideLinksProvider } from "~/modules/navigation/guide-links-context"
|
||||
import type { GuideLink } from "~/modules/navigation/load-guide-links.server"
|
||||
import { loadGuideLinks } from "~/modules/navigation/load-guide-links.server"
|
||||
import prismThemeCss from "~/modules/ui/prism-theme.css"
|
||||
|
||||
export const meta: MetaFunction = () => ({
|
||||
title: "Reacord",
|
||||
description: packageJson.description,
|
||||
})
|
||||
|
||||
export const links: LinksFunction = () => [
|
||||
{ rel: "preconnect", href: "https://fonts.googleapis.com" },
|
||||
{
|
||||
rel: "preconnect",
|
||||
href: "https://fonts.gstatic.com",
|
||||
crossOrigin: "anonymous",
|
||||
},
|
||||
{
|
||||
rel: "preload",
|
||||
as: "style",
|
||||
href: "https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@500&family=Rubik:ital,wght@0,300;0,400;0,500;1,300;1,400;1,500&display=swap",
|
||||
},
|
||||
{ rel: "stylesheet", href: "/tailwind.css" },
|
||||
{ rel: "stylesheet", href: prismThemeCss },
|
||||
]
|
||||
|
||||
type LoaderData = {
|
||||
guideLinks: GuideLink[]
|
||||
}
|
||||
|
||||
export const loader: LoaderFunction = async () => {
|
||||
const data: LoaderData = {
|
||||
guideLinks: await loadGuideLinks(),
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
const data: LoaderData = useLoaderData()
|
||||
return (
|
||||
<html lang="en" className="bg-slate-900 text-slate-100">
|
||||
<head>
|
||||
<meta charSet="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<Meta />
|
||||
<Links />
|
||||
<script defer src="https://unpkg.com/alpinejs@3.7.1/dist/cdn.min.js" />
|
||||
</head>
|
||||
<body>
|
||||
<GuideLinksProvider value={data.guideLinks}>
|
||||
<Outlet />
|
||||
</GuideLinksProvider>
|
||||
<ScrollRestoration />
|
||||
{process.env.NODE_ENV === "development" && <LiveReload />}
|
||||
</body>
|
||||
</html>
|
||||
)
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
import clsx from "clsx"
|
||||
import { Outlet } from "remix"
|
||||
import { AppLink } from "~/modules/navigation/app-link"
|
||||
import { useGuideLinksContext } from "~/modules/navigation/guide-links-context"
|
||||
import { MainNavigation } from "~/modules/navigation/main-navigation"
|
||||
import {
|
||||
docsProseClass,
|
||||
linkClass,
|
||||
maxWidthContainer,
|
||||
} from "~/modules/ui/components"
|
||||
|
||||
export default function GuidePage() {
|
||||
const guideLinks = useGuideLinksContext()
|
||||
return (
|
||||
<>
|
||||
<header className="bg-slate-700/30 shadow sticky top-0 backdrop-blur-sm transition z-10 flex">
|
||||
<div className={maxWidthContainer}>
|
||||
<MainNavigation />
|
||||
</div>
|
||||
</header>
|
||||
<main className={clsx(maxWidthContainer, "mt-8 flex items-start gap-4")}>
|
||||
<nav className="w-48 sticky top-24 hidden md:block">
|
||||
<h2 className="text-2xl">Guides</h2>
|
||||
<ul className="mt-3 flex flex-col gap-2 items-start">
|
||||
{guideLinks.map(({ link }) => (
|
||||
<li key={link.to}>
|
||||
<AppLink {...link} className={linkClass} />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</nav>
|
||||
<section className={clsx(docsProseClass, "pb-8 flex-1 min-w-0")}>
|
||||
<Outlet />
|
||||
</section>
|
||||
</main>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
---
|
||||
order: 3
|
||||
meta:
|
||||
title: Buttons
|
||||
description: Using button components
|
||||
---
|
||||
|
||||
# Buttons
|
||||
|
||||
Use the `<Button />` component to create a message with a button, and use the `onClick` callback to respond to button clicks.
|
||||
|
||||
```jsx
|
||||
import { Button } from "reacord"
|
||||
|
||||
function Counter() {
|
||||
const [count, setCount] = useState(0)
|
||||
|
||||
return (
|
||||
<>
|
||||
You've clicked the button {count} times.
|
||||
<Button label="+1" onClick={() => setCount(count + 1)} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
The `onClick` callback receives an `event` object. It includes some information, such as the user who clicked the button, and functions for creating new replies in response. These functions return message instances.
|
||||
|
||||
```jsx
|
||||
import { Button } from "reacord"
|
||||
|
||||
function TheButton() {
|
||||
function handleClick(event) {
|
||||
const name = event.guild.member.displayName || event.user.username
|
||||
|
||||
const publicReply = event.reply(`${name} clicked the button. wow`)
|
||||
setTimeout(() => publicReply.destroy(), 3000)
|
||||
|
||||
const privateReply = event.ephemeralReply("good job, you clicked it")
|
||||
privateReply.deactivate() // we don't need to listen to updates on this
|
||||
}
|
||||
|
||||
return <Button label="click me i dare you" onClick={handleClick} />
|
||||
}
|
||||
```
|
||||
|
||||
See the [API reference](/api/index.html#ButtonProps) for more information.
|
||||
@@ -1,64 +0,0 @@
|
||||
---
|
||||
order: 2
|
||||
meta:
|
||||
title: Embeds
|
||||
description: Using embed components
|
||||
---
|
||||
|
||||
# Embeds
|
||||
|
||||
Reacord comes with an `<Embed />` component for sending rich embeds.
|
||||
|
||||
```jsx
|
||||
import { Embed } from "reacord"
|
||||
|
||||
function FancyMessage({ title, description }) {
|
||||
return (
|
||||
<Embed
|
||||
title={title}
|
||||
description={description}
|
||||
color={0x00ff00}
|
||||
timestamp={Date.now()}
|
||||
/>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
```jsx
|
||||
reacord.send(channelId, <FancyMessage title="Hello" description="World" />)
|
||||
```
|
||||
|
||||
Reacord also comes with multiple embed components, for defining embeds on a piece-by-piece basis. This enables composition:
|
||||
|
||||
```jsx
|
||||
import { Embed, EmbedTitle } from "reacord"
|
||||
|
||||
function FancyDetails({ title, description }) {
|
||||
return (
|
||||
<>
|
||||
<EmbedTitle>{title}</EmbedTitle>
|
||||
{/* embed descriptions are just text */}
|
||||
{description}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
function FancyMessage({ children }) {
|
||||
return (
|
||||
<Embed color={0x00ff00} timestamp={Date.now()}>
|
||||
{children}
|
||||
</Embed>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
```jsx
|
||||
reacord.send(
|
||||
channelId,
|
||||
<FancyMessage>
|
||||
<FancyDetails title="Hello" description="World" />
|
||||
</FancyMessage>,
|
||||
)
|
||||
```
|
||||
|
||||
See the [API Reference](/api/index.html#EmbedAuthorProps) for the full list of embed components.
|
||||
@@ -1,44 +0,0 @@
|
||||
---
|
||||
order: 0
|
||||
meta:
|
||||
title: Getting Started
|
||||
description: Learn how to get started with Reacord.
|
||||
---
|
||||
|
||||
# Getting Started
|
||||
|
||||
This guide assumes some familiarity with JavaScript, [React](https://reactjs.org), [Discord.js](https://discord.js.org) and the [Discord API](https://discord.dev). Keep these pages as reference if you need it.
|
||||
|
||||
**Note:** Ensure your project has support for running code with JSX. I recommend using [esno](https://npm.im/esno).
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
# npm
|
||||
npm install reacord react discord.js
|
||||
|
||||
# yarn
|
||||
yarn add reacord react discord.js
|
||||
|
||||
# pnpm
|
||||
pnpm add reacord react discord.js
|
||||
```
|
||||
|
||||
## Setup
|
||||
|
||||
Create a Discord.js client and a Reacord instance:
|
||||
|
||||
```js
|
||||
// main.js
|
||||
import { Client } from "discord.js"
|
||||
import { ReacordDiscordJs } from "reacord"
|
||||
|
||||
const client = new Client()
|
||||
const reacord = new ReacordDiscordJs(client)
|
||||
|
||||
client.on("ready", () => {
|
||||
console.log("Ready!")
|
||||
})
|
||||
|
||||
await client.login(process.env.BOT_TOKEN)
|
||||
```
|
||||
@@ -1,71 +0,0 @@
|
||||
---
|
||||
order: 4
|
||||
meta:
|
||||
title: Select Menus
|
||||
description: Using select menu components
|
||||
---
|
||||
|
||||
# Select Menus
|
||||
|
||||
To create a select menu, use the `Select` component, and pass a list of `Option` components as children. Use the `value` prop to set a currently selected value. You can respond to changes in the value via `onChangeValue`.
|
||||
|
||||
```jsx
|
||||
export function FruitSelect({ onConfirm }) {
|
||||
const [value, setValue] = useState()
|
||||
|
||||
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)
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
```jsx
|
||||
const instance = reacord.send(
|
||||
channelId,
|
||||
<FruitSelect
|
||||
onConfirm={(value) => {
|
||||
instance.render(`you chose ${value}`)
|
||||
instance.deactivate()
|
||||
}}
|
||||
/>,
|
||||
)
|
||||
```
|
||||
|
||||
For a multi-select, use the `multiple` prop, then you can use `values` and `onChangeMultiple` to handle multiple values.
|
||||
|
||||
```tsx
|
||||
export function FruitSelect({ onConfirm }) {
|
||||
const [values, setValues] = useState([])
|
||||
|
||||
return (
|
||||
<Select
|
||||
placeholder="choose a fruit"
|
||||
values={values}
|
||||
onChangeMultiple={setValues}
|
||||
>
|
||||
<Option value="🍎" />
|
||||
<Option value="🍌" />
|
||||
<Option value="🍒" />
|
||||
</Select>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
The Select component accepts a variety of props beyond what's shown here. See the [API reference](/api/index.html#SelectChangeEvent) for more information.
|
||||
@@ -1,167 +0,0 @@
|
||||
---
|
||||
order: 1
|
||||
meta:
|
||||
title: Sending Messages
|
||||
description: Sending messages by creating Reacord instances
|
||||
---
|
||||
|
||||
# Sending Messages with Instances
|
||||
|
||||
You can send messages via Reacord to a channel like so.
|
||||
|
||||
```jsx
|
||||
const channelId = "abc123deadbeef"
|
||||
|
||||
client.on("ready", () => {
|
||||
reacord.send(channelId, "Hello, world!")
|
||||
})
|
||||
```
|
||||
|
||||
The `.send()` function creates a **Reacord instance**. You can pass strings, numbers, or anything that can be rendered by React, such as JSX!
|
||||
|
||||
Components rendered through this instance can include state and effects, and the message on Discord will update automatically.
|
||||
|
||||
```jsx
|
||||
function Uptime() {
|
||||
const [startTime] = useState(Date.now())
|
||||
const [currentTime, setCurrentTime] = useState(Date.now())
|
||||
|
||||
useEffect(() => {
|
||||
const interval = setInterval(() => {
|
||||
currentTime(Date.now())
|
||||
}, 3000)
|
||||
return () => clearInterval(interval)
|
||||
}, [])
|
||||
|
||||
return <>this message has been shown for {currentTime - startTime}ms</>
|
||||
}
|
||||
|
||||
client.on("ready", () => {
|
||||
reacord.send(channelId, <Uptime />)
|
||||
})
|
||||
```
|
||||
|
||||
The instance can be rendered to multiple times, which will update the message each time.
|
||||
|
||||
```jsx
|
||||
const Hello = ({ subject }) => <>Hello, {subject}!</>
|
||||
|
||||
client.on("ready", () => {
|
||||
const instance = reacord.send(channel)
|
||||
instance.render(<Hello subject="World" />)
|
||||
instance.render(<Hello subject="Moon" />)
|
||||
})
|
||||
```
|
||||
|
||||
## Cleaning Up Instances
|
||||
|
||||
If you no longer want to use the instance, you can clean it up in a few ways:
|
||||
|
||||
- `instance.destroy()` - This will remove the message.
|
||||
- `instance.deactivate()` - This will keep the message, but it will disable the components on the message, and no longer listen to user interactions.
|
||||
|
||||
By default, Reacord has a max limit on the number of active instances, and deactivates older instances to conserve memory. This can be configured through the Reacord options:
|
||||
|
||||
```js
|
||||
const reacord = new ReacordDiscordJs(client, {
|
||||
// after sending four messages,
|
||||
// the first one will be deactivated
|
||||
maxInstances: 3,
|
||||
})
|
||||
```
|
||||
|
||||
## Discord Slash Commands
|
||||
|
||||
<aside>
|
||||
This section also applies to other kinds of application commands, such as context menu commands.
|
||||
</aside>
|
||||
|
||||
To reply to a command interaction, use the `.reply()` function. This function returns an instance that works the same way as the one from `.send()`. Here's an example:
|
||||
|
||||
```jsx
|
||||
import { Client } from "discord.js"
|
||||
import * as React from "react"
|
||||
import { Button, ReacordDiscordJs } from "reacord"
|
||||
|
||||
const client = new Client({ intents: [] })
|
||||
const reacord = new ReacordDiscordJs(client)
|
||||
|
||||
client.on("ready", () => {
|
||||
client.application?.commands.create({
|
||||
name: "ping",
|
||||
description: "pong!",
|
||||
})
|
||||
})
|
||||
|
||||
client.on("interactionCreate", (interaction) => {
|
||||
if (interaction.isCommand() && interaction.commandName === "ping") {
|
||||
// Use the reply() function instead of send
|
||||
reacord.reply(interaction, <>pong!</>)
|
||||
}
|
||||
})
|
||||
|
||||
client.login(process.env.DISCORD_TOKEN)
|
||||
```
|
||||
|
||||
<aside>
|
||||
This example uses <a href="https://discord.com/developers/docs/interactions/application-commands#registering-a-command">global commands</a>, so the command might take a while to show up 😅
|
||||
</aside>
|
||||
|
||||
However, the process of creating commands can get really repetitive and error-prone. A command framework could help with this, or you could make a small helper:
|
||||
|
||||
```jsx
|
||||
function handleCommands(client, commands) {
|
||||
client.on("ready", () => {
|
||||
for (const { name, description } of commands) {
|
||||
client.application?.commands.create({ name, description })
|
||||
}
|
||||
})
|
||||
|
||||
client.on("interactionCreate", (interaction) => {
|
||||
if (interaction.isCommand()) {
|
||||
for (const command of commands) {
|
||||
if (interaction.commandName === command.name) {
|
||||
command.run(interaction)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
```jsx
|
||||
handleCommands(client, [
|
||||
{
|
||||
name: "ping",
|
||||
description: "pong!",
|
||||
run: (interaction) => {
|
||||
reacord.reply(interaction, <>pong!</>)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "hi",
|
||||
description: "say hi",
|
||||
run: (interaction) => {
|
||||
reacord.reply(interaction, <>hi</>)
|
||||
},
|
||||
},
|
||||
])
|
||||
```
|
||||
|
||||
## Ephemeral Command Replies
|
||||
|
||||
Ephemeral replies are replies that only appear for one user. To create them, use the `.ephemeralReply()` function.
|
||||
|
||||
```tsx
|
||||
handleCommands(client, [
|
||||
{
|
||||
name: "pong",
|
||||
description: "pong, but in secret",
|
||||
run: (interaction) => {
|
||||
reacord.ephemeralReply(interaction, <>(pong)</>)
|
||||
},
|
||||
},
|
||||
])
|
||||
```
|
||||
|
||||
The `ephemeralReply` function also returns an instance, but ephemeral replies cannot be updated via `instance.render()`. You can `.deactivate()` them, but `.destroy()` will not delete the message; only the user can hide it from view.
|
||||
@@ -1,29 +0,0 @@
|
||||
import packageJson from "reacord/package.json"
|
||||
import LandingExample from "~/modules/landing/landing-example.mdx"
|
||||
import { MainNavigation } from "~/modules/navigation/main-navigation"
|
||||
import { maxWidthContainer } from "~/modules/ui/components"
|
||||
|
||||
export default function Landing() {
|
||||
return (
|
||||
<div className="flex flex-col min-w-0 min-h-screen text-center">
|
||||
<header className={maxWidthContainer}>
|
||||
<MainNavigation />
|
||||
</header>
|
||||
<div className="px-4 pb-8 flex flex-1">
|
||||
<main className="px-4 py-6 rounded-lg shadow bg-slate-800 space-y-5 m-auto w-full max-w-xl">
|
||||
<h1 className="text-6xl font-light">reacord</h1>
|
||||
<section className="mx-auto text-sm sm:text-base">
|
||||
<LandingExample />
|
||||
</section>
|
||||
<p className="text-2xl font-light">{packageJson.description}</p>
|
||||
<a
|
||||
href="/guides/getting-started"
|
||||
className="inline-block px-4 py-3 text-xl transition rounded-lg bg-emerald-700 hover:translate-y-[-2px] hover:bg-emerald-800 hover:shadow"
|
||||
>
|
||||
Get Started
|
||||
</a>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
import type { LoaderFunction } from "remix"
|
||||
import { serveTailwindCss } from "remix-tailwind"
|
||||
|
||||
export const loader: LoaderFunction = () =>
|
||||
serveTailwindCss("app/modules/ui/tailwind.css")
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"baseUrl": "http://localhost:3000/"
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"name": "Using fixtures to represent data",
|
||||
"email": "hello@cypress.io",
|
||||
"body": "Fixtures are a great way to mock data for responses to routes"
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
export {}
|
||||
|
||||
describe("main popover menu", () => {
|
||||
it("should toggle on button click", () => {
|
||||
cy.viewport(480, 720)
|
||||
cy.visit("/")
|
||||
cy.findByRole("button", { name: "Menu" }).click()
|
||||
cy.findByRole("menu").should("be.visible")
|
||||
cy.findByRole("button", { name: "Menu" }).click()
|
||||
cy.findByRole("menu").should("not.exist")
|
||||
})
|
||||
})
|
||||
@@ -1,22 +0,0 @@
|
||||
/// <reference types="cypress" />
|
||||
// ***********************************************************
|
||||
// This example plugins/index.js can be used to load plugins
|
||||
//
|
||||
// You can change the location of this file or turn off loading
|
||||
// the plugins file with the 'pluginsFile' configuration option.
|
||||
//
|
||||
// You can read more here:
|
||||
// https://on.cypress.io/plugins-guide
|
||||
// ***********************************************************
|
||||
|
||||
// This function is called when a project is opened or re-opened (e.g. due to
|
||||
// the project's config changing)
|
||||
|
||||
/**
|
||||
* @type {Cypress.PluginConfig}
|
||||
*/
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
// module.exports = (on, config) => {
|
||||
// `on` is used to hook into various events Cypress emits
|
||||
// `config` is the resolved Cypress config
|
||||
// }
|
||||
@@ -1,26 +0,0 @@
|
||||
// ***********************************************
|
||||
// This example commands.js shows you how to
|
||||
// create various custom commands and overwrite
|
||||
// existing commands.
|
||||
//
|
||||
// For more comprehensive examples of custom
|
||||
// commands please read more here:
|
||||
// https://on.cypress.io/custom-commands
|
||||
// ***********************************************
|
||||
//
|
||||
//
|
||||
// -- This is a parent command --
|
||||
// Cypress.Commands.add('login', (email, password) => { ... })
|
||||
//
|
||||
//
|
||||
// -- This is a child command --
|
||||
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
|
||||
//
|
||||
//
|
||||
// -- This is a dual command --
|
||||
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
|
||||
//
|
||||
//
|
||||
// -- This will overwrite an existing command --
|
||||
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
|
||||
import "@testing-library/cypress/add-commands"
|
||||
@@ -1,20 +0,0 @@
|
||||
// ***********************************************************
|
||||
// This example support/index.js is processed and
|
||||
// loaded automatically before your test files.
|
||||
//
|
||||
// This is a great place to put global configuration and
|
||||
// behavior that modifies Cypress.
|
||||
//
|
||||
// You can change the location of this file or turn off
|
||||
// automatically serving support files with the
|
||||
// 'supportFile' configuration option.
|
||||
//
|
||||
// You can read more here:
|
||||
// https://on.cypress.io/configuration
|
||||
// ***********************************************************
|
||||
|
||||
// Import commands.js using ES2015 syntax:
|
||||
import './commands'
|
||||
|
||||
// Alternatively you can use CommonJS syntax:
|
||||
// require('./commands')
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"types": ["cypress", "@testing-library/cypress"]
|
||||
},
|
||||
"include": ["."],
|
||||
"exclude": []
|
||||
}
|
||||
Binary file not shown.
@@ -1,49 +0,0 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "reacord-docs-new",
|
||||
"scripts": {
|
||||
"prepare": "remix setup node",
|
||||
"dev": "concurrently 'typedoc --watch' 'remix dev'",
|
||||
"test": "pnpm build && pnpm start & wait-on http-get://localhost:3000 && cypress run",
|
||||
"test-dev": "pnpm dev & wait-on http-get://localhost:3000 && cypress open",
|
||||
"build": "typedoc && remix build",
|
||||
"start": "remix-serve build",
|
||||
"typecheck": "tsc --noEmit && tsc --project cypress/tsconfig.json --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@heroicons/react": "^1.0.5",
|
||||
"@remix-run/react": "^1.1.1",
|
||||
"@remix-run/serve": "^1.1.1",
|
||||
"@tailwindcss/typography": "^0.5.0",
|
||||
"autoprefixer": "^10.4.2",
|
||||
"clsx": "^1.1.1",
|
||||
"fast-glob": "^3.2.10",
|
||||
"gray-matter": "^4.0.3",
|
||||
"postcss": "^8.4.5",
|
||||
"reacord": "workspace:*",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2",
|
||||
"remix": "^1.1.1",
|
||||
"remix-tailwind": "^0.2.1",
|
||||
"tailwindcss": "^3.0.12"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@remix-run/dev": "^1.1.1",
|
||||
"@remix-run/node": "^1.1.1",
|
||||
"@testing-library/cypress": "^8.0.2",
|
||||
"@types/node": "*",
|
||||
"@types/react": "^17.0.38",
|
||||
"@types/react-dom": "^17.0.11",
|
||||
"@types/tailwindcss": "^3.0.2",
|
||||
"concurrently": "^7.0.0",
|
||||
"cypress": "^9.2.0",
|
||||
"rehype-prism-plus": "^1.2.2",
|
||||
"typedoc": "^0.22.10",
|
||||
"typescript": "^4.5.4",
|
||||
"wait-on": "^6.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"sideEffects": false
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 17 KiB |
@@ -1,18 +0,0 @@
|
||||
/* eslint-disable unicorn/prefer-module */
|
||||
/**
|
||||
* @type {import('@remix-run/dev/config').AppConfig}
|
||||
*/
|
||||
module.exports = {
|
||||
appDirectory: "app",
|
||||
assetsBuildDirectory: "public/build",
|
||||
publicPath: "/build/",
|
||||
serverBuildDirectory: "build",
|
||||
devServerPort: 8002,
|
||||
ignoredRouteFiles: [".*"],
|
||||
mdx: async () => {
|
||||
const rehypePrism = await import("rehype-prism-plus")
|
||||
return {
|
||||
rehypePlugins: [rehypePrism.default],
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
// @ts-nocheck
|
||||
module.exports = {
|
||||
content: ["./app/**/*.{ts,tsx,md}"],
|
||||
theme: {
|
||||
fontFamily: {
|
||||
sans: ["Rubik", "sans-serif"],
|
||||
monospace: ["'JetBrains Mono'", "monospace"],
|
||||
},
|
||||
boxShadow: {
|
||||
DEFAULT: "0 2px 9px 0 rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.3)",
|
||||
},
|
||||
extend: {},
|
||||
},
|
||||
plugins: [require("@tailwindcss/typography")],
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"paths": {
|
||||
"~/*": ["./app/*"]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
{
|
||||
"entryPoints": ["../reacord/library/main.ts"],
|
||||
"out": ["public/api"],
|
||||
"tsconfig": "../reacord/tsconfig.json",
|
||||
"excludeInternal": true,
|
||||
"excludePrivate": true,
|
||||
"excludeProtected": true,
|
||||
"categorizeByGroup": false,
|
||||
"preserveWatchOutput": true,
|
||||
"githubPages": false,
|
||||
"readme": "none",
|
||||
"categoryOrder": [
|
||||
"Core",
|
||||
"Embed",
|
||||
"Button",
|
||||
"Link",
|
||||
"Select",
|
||||
"Action Row",
|
||||
"Component Event",
|
||||
"*"
|
||||
]
|
||||
}
|
||||
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,10 +1,10 @@
|
||||
import { setTimeout } from "node:timers/promises"
|
||||
import { toError } from "./to-error.js"
|
||||
import { setTimeout } from "node:timers/promises"
|
||||
|
||||
export async function rejectAfter(
|
||||
timeMs: number,
|
||||
error: unknown = `rejected after ${timeMs}ms`,
|
||||
): Promise<never> {
|
||||
await setTimeout(timeMs)
|
||||
return Promise.reject(toError(error))
|
||||
throw toError(error)
|
||||
}
|
||||
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
|
||||
}
|
||||
2
packages/reacord/.gitignore
vendored
Normal file
2
packages/reacord/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/README.md
|
||||
/LICENSE
|
||||
50
packages/reacord/CHANGELOG.md
Normal file
50
packages/reacord/CHANGELOG.md
Normal file
@@ -0,0 +1,50 @@
|
||||
# reacord
|
||||
|
||||
## 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,37 +0,0 @@
|
||||
import type {
|
||||
CamelCasedPropertiesDeep,
|
||||
SnakeCasedPropertiesDeep,
|
||||
} from "type-fest"
|
||||
import { camelCaseDeep, snakeCaseDeep } from "./convert-object-property-case"
|
||||
|
||||
test("camelCaseDeep", () => {
|
||||
const input = {
|
||||
some_prop: {
|
||||
some_deep_prop: "some_deep_value",
|
||||
},
|
||||
someOtherProp: "someOtherValue",
|
||||
}
|
||||
|
||||
expect(camelCaseDeep(input)).toEqual<CamelCasedPropertiesDeep<typeof input>>({
|
||||
someProp: {
|
||||
someDeepProp: "some_deep_value",
|
||||
},
|
||||
someOtherProp: "someOtherValue",
|
||||
})
|
||||
})
|
||||
|
||||
test("snakeCaseDeep", () => {
|
||||
const input = {
|
||||
someProp: {
|
||||
someDeepProp: "someDeepValue",
|
||||
},
|
||||
some_other_prop: "someOtherValue",
|
||||
}
|
||||
|
||||
expect(snakeCaseDeep(input)).toEqual<SnakeCasedPropertiesDeep<typeof input>>({
|
||||
some_prop: {
|
||||
some_deep_prop: "someDeepValue",
|
||||
},
|
||||
some_other_prop: "someOtherValue",
|
||||
})
|
||||
})
|
||||
@@ -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,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,15 +0,0 @@
|
||||
export function pruneNullishValues<T extends object>(
|
||||
object: T,
|
||||
): PruneNullishValues<T> {
|
||||
const result: any = {}
|
||||
for (const [key, value] of Object.entries(object)) {
|
||||
if (value != undefined) {
|
||||
result[key] = value
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
type PruneNullishValues<T> = {
|
||||
[Key in keyof T]: NonNullable<T[Key]>
|
||||
}
|
||||
@@ -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,15 +0,0 @@
|
||||
/** @type {import('@jest/types').Config.InitialOptions} */
|
||||
const config = {
|
||||
transform: {
|
||||
"^.+\\.[jt]sx?$": ["esbuild-jest", { format: "esm", sourcemap: true }],
|
||||
},
|
||||
extensionsToTreatAsEsm: [".ts", ".tsx"],
|
||||
moduleNameMapper: {
|
||||
"^(\\.\\.?/.+)\\.jsx?$": "$1",
|
||||
},
|
||||
verbose: true,
|
||||
cache: false,
|
||||
coverageReporters: ["text", "text-summary", "html"],
|
||||
coveragePathIgnorePatterns: ["discord-js-adapter", "test/setup-testing"],
|
||||
}
|
||||
export default config
|
||||
@@ -1,52 +1,60 @@
|
||||
import type { ReactNode } from "react"
|
||||
import type { ReacordInstance } from "./instance"
|
||||
|
||||
/** @category Component Event */
|
||||
export interface ComponentEvent {
|
||||
/**
|
||||
* @category Component Event
|
||||
*/
|
||||
export type ComponentEvent = {
|
||||
/**
|
||||
* The message associated with this event.
|
||||
* For example: with a button click,
|
||||
* The message associated with this event. For example: with a button click,
|
||||
* this is the message that the button is on.
|
||||
*
|
||||
* @see https://discord.com/developers/docs/resources/channel#message-object
|
||||
*/
|
||||
message: MessageInfo
|
||||
message: ComponentEventMessage
|
||||
|
||||
/**
|
||||
* The channel that this event occurred in.
|
||||
*
|
||||
* @see https://discord.com/developers/docs/resources/channel#channel-object
|
||||
*/
|
||||
channel: ChannelInfo
|
||||
channel: ComponentEventChannel
|
||||
|
||||
/**
|
||||
* The user that triggered this event.
|
||||
*
|
||||
* @see https://discord.com/developers/docs/resources/user#user-object
|
||||
*/
|
||||
user: UserInfo
|
||||
user: ComponentEventUser
|
||||
|
||||
/**
|
||||
* The guild that this event occurred in.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
reply(content?: ReactNode): ReacordInstance
|
||||
|
||||
/**
|
||||
* Create an ephemeral reply to this event,
|
||||
* shown only to the user who triggered it.
|
||||
* Create an ephemeral reply to this event, shown only to the user who
|
||||
* triggered it.
|
||||
*
|
||||
* @deprecated Use event.reply(content, { ephemeral: true })
|
||||
*/
|
||||
ephemeralReply(content?: ReactNode): ReacordInstance
|
||||
}
|
||||
|
||||
/**
|
||||
* @category Component Event
|
||||
*/
|
||||
export type ChannelInfo = {
|
||||
/** @category Component Event */
|
||||
export interface ComponentEventReplyOptions {
|
||||
ephemeral?: boolean
|
||||
tts?: boolean
|
||||
}
|
||||
|
||||
/** @category Component Event */
|
||||
export interface ComponentEventChannel {
|
||||
id: string
|
||||
name?: string
|
||||
topic?: string
|
||||
@@ -57,14 +65,12 @@ export type ChannelInfo = {
|
||||
rateLimitPerUser?: number
|
||||
}
|
||||
|
||||
/**
|
||||
* @category Component Event
|
||||
*/
|
||||
export type MessageInfo = {
|
||||
/** @category Component Event */
|
||||
export interface ComponentEventMessage {
|
||||
id: string
|
||||
channelId: string
|
||||
authorId: UserInfo
|
||||
member?: GuildMemberInfo
|
||||
authorId: string
|
||||
member?: ComponentEventGuildMember
|
||||
content: string
|
||||
timestamp: string
|
||||
editedTimestamp?: string
|
||||
@@ -74,19 +80,15 @@ export type MessageInfo = {
|
||||
mentions: string[]
|
||||
}
|
||||
|
||||
/**
|
||||
* @category Component Event
|
||||
*/
|
||||
export type GuildInfo = {
|
||||
/** @category Component Event */
|
||||
export interface ComponentEventGuild {
|
||||
id: string
|
||||
name: string
|
||||
member: GuildMemberInfo
|
||||
member: ComponentEventGuildMember
|
||||
}
|
||||
|
||||
/**
|
||||
* @category Component Event
|
||||
*/
|
||||
export type GuildMemberInfo = {
|
||||
/** @category Component Event */
|
||||
export interface ComponentEventGuildMember {
|
||||
id: string
|
||||
nick?: string
|
||||
displayName: string
|
||||
@@ -100,14 +102,12 @@ export type GuildMemberInfo = {
|
||||
communicationDisabledUntil?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @category Component Event
|
||||
*/
|
||||
export type UserInfo = {
|
||||
/** @category Component Event */
|
||||
export interface ComponentEventUser {
|
||||
id: string
|
||||
username: string
|
||||
discriminator: string
|
||||
tag: string
|
||||
avatarUrl: string
|
||||
avatarUrl: string | null
|
||||
accentColor?: number
|
||||
}
|
||||
|
||||
@@ -1,29 +1,30 @@
|
||||
import type { ReactNode } from "react"
|
||||
import React from "react"
|
||||
import { ReacordElement } from "../../internal/element.js"
|
||||
import type { MessageOptions } from "../../internal/message"
|
||||
import { Node } from "../../internal/node.js"
|
||||
import type { ComponentInteraction } from "../../internal/interaction.js"
|
||||
|
||||
/**
|
||||
* Props for an action row
|
||||
*
|
||||
* @category Action Row
|
||||
*/
|
||||
export type ActionRowProps = {
|
||||
export interface ActionRowProps {
|
||||
children?: ReactNode
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* But this can be useful if you want a specific layout.
|
||||
* You don't need to use this; Reacord automatically creates action rows for
|
||||
* you. But this can be useful if you want a specific layout.
|
||||
*
|
||||
* ```tsx
|
||||
* // put buttons on two separate rows
|
||||
* <ActionRow>
|
||||
* <Button onClick={handleFirst}>First</Button>
|
||||
* <Button label="First" onClick={handleFirst} />
|
||||
* </ActionRow>
|
||||
* <Button onClick={handleSecond}>Second</Button>
|
||||
* <Button label="Second" onClick={handleSecond} />
|
||||
* ```
|
||||
*
|
||||
* @category Action Row
|
||||
@@ -37,11 +38,19 @@ export function ActionRow(props: ActionRowProps) {
|
||||
)
|
||||
}
|
||||
|
||||
class ActionRowNode extends Node<{}> {
|
||||
class ActionRowNode extends Node<ActionRowProps> {
|
||||
override modifyMessageOptions(options: MessageOptions): void {
|
||||
options.actionRows.push([])
|
||||
for (const child of this.children) {
|
||||
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
|
||||
*
|
||||
* @category Button
|
||||
*/
|
||||
export type ButtonSharedProps = {
|
||||
export interface ButtonSharedProps {
|
||||
/** 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. */
|
||||
disabled?: boolean
|
||||
|
||||
/**
|
||||
* Renders an emoji to the left of the text.
|
||||
* Has to be a literal emoji character (e.g. 🍍),
|
||||
* or an emoji code, like `<:plus_one:778531744860602388>`.
|
||||
* Renders an emoji to the left of the text. Has to be a literal emoji
|
||||
* character (e.g. 🍍), or an emoji code, like
|
||||
* `<:plus_one:778531744860602388>`.
|
||||
*
|
||||
* To get an emoji code, type your emoji in Discord chat
|
||||
* with a backslash `\` in front.
|
||||
* The bot has to be in the emoji's guild to use it.
|
||||
* To get an emoji code, type your emoji in Discord chat with a backslash `\`
|
||||
* in front. The bot has to be in the emoji's guild to use it.
|
||||
*/
|
||||
emoji?: string
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { nanoid } from "nanoid"
|
||||
import React from "react"
|
||||
import { randomUUID } from "node:crypto"
|
||||
import { ReacordElement } from "../../internal/element.js"
|
||||
import type { ComponentInteraction } from "../../internal/interaction"
|
||||
import type { MessageOptions } from "../../internal/message"
|
||||
@@ -8,38 +7,41 @@ import { Node } from "../../internal/node.js"
|
||||
import type { ComponentEvent } from "../component-event"
|
||||
import type { ButtonSharedProps } from "./button-shared-props"
|
||||
|
||||
/**
|
||||
* @category Button
|
||||
*/
|
||||
/** @category Button */
|
||||
export type ButtonProps = ButtonSharedProps & {
|
||||
/**
|
||||
* The style determines the color of the button and signals intent.
|
||||
*
|
||||
* @see https://discord.com/developers/docs/interactions/message-components#button-object-button-styles
|
||||
*/
|
||||
style?: "primary" | "secondary" | "success" | "danger"
|
||||
|
||||
/**
|
||||
* Happens when a user clicks the button.
|
||||
*/
|
||||
/** Happens when a user clicks the button. */
|
||||
onClick: (event: ButtonClickEvent) => void
|
||||
}
|
||||
|
||||
/**
|
||||
* @category Button
|
||||
*/
|
||||
/** @category Button */
|
||||
export type ButtonClickEvent = ComponentEvent
|
||||
|
||||
/**
|
||||
* @category Button
|
||||
*/
|
||||
/** @category Button */
|
||||
export function Button(props: ButtonProps) {
|
||||
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> {
|
||||
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 {
|
||||
getNextActionRow(options).push({
|
||||
@@ -48,7 +50,7 @@ class ButtonNode extends Node<ButtonProps> {
|
||||
style: this.props.style ?? "secondary",
|
||||
disabled: this.props.disabled,
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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 { Node } from "../../internal/node.js"
|
||||
import { EmbedChildNode } from "./embed-child.js"
|
||||
import type { EmbedOptions } from "./embed-options"
|
||||
|
||||
/**
|
||||
* @category Embed
|
||||
*/
|
||||
export type EmbedAuthorProps = {
|
||||
name?: string
|
||||
children?: string
|
||||
/** @category Embed */
|
||||
export interface EmbedAuthorProps {
|
||||
name?: ReactNode
|
||||
children?: ReactNode
|
||||
url?: string
|
||||
iconUrl?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @category Embed
|
||||
*/
|
||||
/** @category Embed */
|
||||
export function EmbedAuthor(props: EmbedAuthorProps) {
|
||||
return (
|
||||
<ReacordElement
|
||||
props={props}
|
||||
createNode={() => new EmbedAuthorNode(props)}
|
||||
/>
|
||||
<ReacordElement props={props} createNode={() => new EmbedAuthorNode(props)}>
|
||||
<ReacordElement props={{}} createNode={() => new AuthorTextNode({})}>
|
||||
{props.name ?? props.children}
|
||||
</ReacordElement>
|
||||
</ReacordElement>
|
||||
)
|
||||
}
|
||||
|
||||
class EmbedAuthorNode extends EmbedChildNode<EmbedAuthorProps> {
|
||||
override modifyEmbedOptions(options: EmbedOptions): void {
|
||||
options.author = {
|
||||
name: this.props.name ?? this.props.children ?? "",
|
||||
name: this.children.findType(AuthorTextNode)?.text ?? "",
|
||||
url: this.props.url,
|
||||
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 { Node } from "../../internal/node.js"
|
||||
import { EmbedChildNode } from "./embed-child.js"
|
||||
import type { EmbedOptions } from "./embed-options"
|
||||
|
||||
/**
|
||||
* @category Embed
|
||||
*/
|
||||
export type EmbedFieldProps = {
|
||||
name: string
|
||||
value?: string
|
||||
/** @category Embed */
|
||||
export interface EmbedFieldProps {
|
||||
name: ReactNode
|
||||
value?: ReactNode
|
||||
inline?: boolean
|
||||
children?: string
|
||||
children?: ReactNode
|
||||
}
|
||||
|
||||
/**
|
||||
* @category Embed
|
||||
*/
|
||||
/** @category Embed */
|
||||
export function EmbedField(props: EmbedFieldProps) {
|
||||
return (
|
||||
<ReacordElement
|
||||
props={props}
|
||||
createNode={() => new EmbedFieldNode(props)}
|
||||
/>
|
||||
<ReacordElement props={props} createNode={() => new EmbedFieldNode(props)}>
|
||||
<ReacordElement props={{}} createNode={() => new FieldNameNode({})}>
|
||||
{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 {
|
||||
options.fields ??= []
|
||||
options.fields.push({
|
||||
name: this.props.name,
|
||||
value: this.props.value ?? this.props.children ?? "",
|
||||
name: this.children.findType(FieldNameNode)?.text ?? "",
|
||||
value: this.children.findType(FieldValueNode)?.text ?? "",
|
||||
inline: this.props.inline,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
class FieldNameNode extends Node<Record<string, never>> {}
|
||||
class FieldValueNode extends Node<Record<string, never>> {}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user