Compare commits
235 Commits
0.1.0
...
reacord@0.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
661a253d8c | ||
|
|
5b68a1f0ea | ||
|
|
8c4a450bfb | ||
|
|
14b74a0a3f | ||
|
|
f2d309b2a7 | ||
|
|
adeb0fb0d9 | ||
|
|
4f8308dc73 | ||
|
|
f5d8fa5271 | ||
|
|
ac759412b3 | ||
|
|
608b008659 | ||
|
|
87cbf1b74d | ||
|
|
4f463bfa23 | ||
|
|
2e65218083 | ||
|
|
1e4a2bd006 | ||
|
|
76bd0b0b98 | ||
|
|
021afc154f | ||
|
|
fe39859b68 | ||
|
|
c55fb22a8f | ||
|
|
7d8336c7a7 | ||
|
|
c6ea101330 | ||
|
|
4e9b358731 | ||
|
|
a66520829a | ||
|
|
e2b150bbe2 | ||
|
|
be42042552 | ||
|
|
3bfc5f4977 |
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,17 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": ["./node_modules/@itsmapleleaf/configs/eslint"],
|
|
||||||
"ignorePatterns": [
|
|
||||||
"**/node_modules/**",
|
|
||||||
"**/.cache/**",
|
|
||||||
"**/build/**",
|
|
||||||
"**/dist/**",
|
|
||||||
"**/coverage/**"
|
|
||||||
],
|
|
||||||
"parserOptions": {
|
|
||||||
"project": "./tsconfig.base.json"
|
|
||||||
},
|
|
||||||
"rules": {
|
|
||||||
"import/no-unused-modules": "off",
|
|
||||||
"unicorn/prevent-abbreviations": "off"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
16
.github/workflows/deploy-docs.yml
vendored
16
.github/workflows/deploy-docs.yml
vendored
@@ -1,16 +0,0 @@
|
|||||||
name: deploy docs
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [main]
|
|
||||||
paths: [packages/docs/**, reacord/library/**/*.ts]
|
|
||||||
|
|
||||||
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
|
.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
|
||||||
|
|||||||
13
Dockerfile
13
Dockerfile
@@ -1,13 +0,0 @@
|
|||||||
FROM node:lts-slim
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
COPY / ./
|
|
||||||
RUN ls -R
|
|
||||||
|
|
||||||
RUN npm install -g pnpm
|
|
||||||
RUN pnpm install --unsafe-perm --frozen-lockfile
|
|
||||||
RUN pnpm build -C packages/docs
|
|
||||||
RUN pnpm install --prod --unsafe-perm --frozen-lockfile
|
|
||||||
|
|
||||||
CMD [ "pnpm", "start", "-C", "packages/docs" ]
|
|
||||||
26
README.md
26
README.md
@@ -1,6 +1,26 @@
|
|||||||
# reacord
|
<center>
|
||||||
|
<img src="./packages/website/app/assets/banner.png" alt="Reacord: Create interactive Discord messages using React">
|
||||||
|
</center>
|
||||||
|
|
||||||
Create interactive Discord messages using React! [Visit the docs to get started.](https://reacord.fly.dev/guides/getting-started)
|
## Installation ∙ [](https://www.npmjs.com/package/reacord)
|
||||||
|
|
||||||
|
```console
|
||||||
|
# npm
|
||||||
|
npm install 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.mapleleaf.dev/guides/getting-started)
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
<!-- prettier-ignore -->
|
<!-- prettier-ignore -->
|
||||||
```tsx
|
```tsx
|
||||||
@@ -21,3 +41,5 @@ function Counter() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|||||||
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"
|
|
||||||
62
package.json
62
package.json
@@ -1,29 +1,47 @@
|
|||||||
{
|
{
|
||||||
|
"name": "reacord-monorepo",
|
||||||
"private": true,
|
"private": true,
|
||||||
"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 . --write --cache --list-different",
|
||||||
},
|
"lint:types": "tsc -b & pnpm -r --parallel run typecheck",
|
||||||
"dependencies": {
|
"astro-sync": "pnpm --filter website exec astro sync",
|
||||||
"@itsmapleleaf/configs": "^1.1.2"
|
"format": "run-s --continue-on-error format:*",
|
||||||
|
"format:eslint": "eslint . --report-unused-disable-directives --fix",
|
||||||
|
"format:prettier": "prettier --cache --write . \"**/*.astro\"",
|
||||||
|
"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": {
|
"devDependencies": {
|
||||||
"@typescript-eslint/eslint-plugin": "^5.8.1",
|
"@changesets/cli": "^2.26.2",
|
||||||
"@typescript-eslint/parser": "^5.8.1",
|
"@itsmapleleaf/configs": "github:itsMapleLeaf/configs",
|
||||||
"eslint": "^8.5.0",
|
"eslint": "^8.50.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.3",
|
"react": "^18.2.0",
|
||||||
"eslint-plugin-jsx-a11y": "^6.5.1",
|
"tailwindcss": "^3.3.3",
|
||||||
"eslint-plugin-react": "^7.28.0",
|
"typescript": "^5.2.2",
|
||||||
"eslint-plugin-react-hooks": "^4.3.0",
|
"vitest": "^0.34.5"
|
||||||
"eslint-plugin-unicorn": "^39.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",
|
||||||
|
"packages/website/public/api"
|
||||||
|
],
|
||||||
|
"rules": {
|
||||||
|
"@typescript-eslint/no-non-null-assertion": "warn",
|
||||||
|
"@typescript-eslint/require-await": "off"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
3
packages/docs/.gitignore
vendored
3
packages/docs/.gitignore
vendored
@@ -1,3 +0,0 @@
|
|||||||
.asset-cache
|
|
||||||
node_modules
|
|
||||||
/api
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "reacord-docs-new",
|
|
||||||
"type": "module",
|
|
||||||
"private": true,
|
|
||||||
"scripts": {
|
|
||||||
"prepare": "node ./scripts/fix-heroicons.js",
|
|
||||||
"serve": "esmo --experimental-import-meta-resolve --experimental-json-modules --no-warnings --enable-source-maps src/main.tsx | pino-colada",
|
|
||||||
"dev": "npm-run-all --parallel --print-label --race dev-*",
|
|
||||||
"dev-server": "nodemon --inspect --exec \"pnpm serve\" --watch src --ext ts,tsx,md,css",
|
|
||||||
"dev-docs": "typedoc --watch",
|
|
||||||
"build": "typedoc",
|
|
||||||
"start": "cross-env NODE_ENV=production pnpm serve",
|
|
||||||
"typecheck": "tsc --noEmit"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@heroicons/react": "^1.0.5",
|
|
||||||
"@tailwindcss/typography": "^0.5.0",
|
|
||||||
"alpinejs": "^3.7.1",
|
|
||||||
"autoprefixer": "^10.4.1",
|
|
||||||
"clsx": "^1.1.1",
|
|
||||||
"compression": "^1.7.4",
|
|
||||||
"cross-env": "^7.0.3",
|
|
||||||
"cssnano": "^5.0.15",
|
|
||||||
"esbuild": "^0.14.10",
|
|
||||||
"esno": "^0.13.0",
|
|
||||||
"express": "^4.17.2",
|
|
||||||
"express-promise-router": "^4.1.1",
|
|
||||||
"fast-glob": "^3.2.7",
|
|
||||||
"gray-matter": "^4.0.3",
|
|
||||||
"http-terminator": "^3.0.4",
|
|
||||||
"markdown-it": "^12.3.0",
|
|
||||||
"markdown-it-prism": "^2.2.1",
|
|
||||||
"pino": "^7.6.2",
|
|
||||||
"pino-colada": "^2.2.2",
|
|
||||||
"pino-http": "^6.5.0",
|
|
||||||
"postcss": "^8.4.5",
|
|
||||||
"reacord": "workspace:*",
|
|
||||||
"react": "^18.0.0-rc.0",
|
|
||||||
"react-dom": "^18.0.0-rc.0",
|
|
||||||
"react-ssr-prepass": "^1.5.0",
|
|
||||||
"tailwindcss": "^3.0.8"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@types/browser-sync": "^2.26.3",
|
|
||||||
"@types/compression": "^1.7.2",
|
|
||||||
"@types/cssnano": "^5.0.0",
|
|
||||||
"@types/express": "^4.17.13",
|
|
||||||
"@types/markdown-it": "^12.2.3",
|
|
||||||
"@types/node": "*",
|
|
||||||
"@types/react": "^17.0.38",
|
|
||||||
"@types/react-dom": "^17.0.9",
|
|
||||||
"@types/tailwindcss": "^3.0.0",
|
|
||||||
"@types/wait-on": "^5.3.1",
|
|
||||||
"browser-sync": "^2.27.7",
|
|
||||||
"execa": "^6.0.0",
|
|
||||||
"nodemon": "^2.0.15",
|
|
||||||
"npm-run-all": "^4.1.5",
|
|
||||||
"rxjs": "^7.5.1",
|
|
||||||
"tsup": "^5.11.10",
|
|
||||||
"type-fest": "^2.8.0",
|
|
||||||
"typedoc": "^0.22.10",
|
|
||||||
"typescript": "^4.5.4",
|
|
||||||
"wait-on": "^6.0.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
plugins: {
|
|
||||||
tailwindcss: {},
|
|
||||||
autoprefixer: {},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
// heroicons doesn't have "sideEffects": false in it's package json,
|
|
||||||
// which causes esbuild to bundle in 460+ imports of react for some reason,
|
|
||||||
// which causes memory issues
|
|
||||||
import glob from "fast-glob"
|
|
||||||
import { readFile, writeFile } from "node:fs/promises"
|
|
||||||
|
|
||||||
const files = await glob("node_modules/@heroicons/react/**/*.json", {
|
|
||||||
absolute: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
for (const file of files) {
|
|
||||||
const data = JSON.parse(await readFile(file, "utf8"))
|
|
||||||
data.sideEffects = false
|
|
||||||
await writeFile(file, JSON.stringify(data, undefined, 2))
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
import { createContext, useContext } from "react"
|
|
||||||
import type { AssetBuilder } from "../asset-builder/asset-builder.js"
|
|
||||||
import { raise } from "../helpers/raise.js"
|
|
||||||
|
|
||||||
const Context = createContext<AssetBuilder>()
|
|
||||||
|
|
||||||
export const AssetBuilderProvider = Context.Provider
|
|
||||||
|
|
||||||
export const useAssetBuilder = () =>
|
|
||||||
useContext(Context) ?? raise("AssetBuilderProvider not found")
|
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
import type { RequestHandler } from "express"
|
|
||||||
import express from "express"
|
|
||||||
import { createHash } from "node:crypto"
|
|
||||||
import { mkdir, rm } from "node:fs/promises"
|
|
||||||
import { join, parse } from "node:path"
|
|
||||||
import React from "react"
|
|
||||||
import { renderToStaticMarkup } from "react-dom/server"
|
|
||||||
import ssrPrepass from "react-ssr-prepass"
|
|
||||||
import type { Promisable } from "type-fest"
|
|
||||||
import { ensureWrite, normalizeAsFilePath } from "../helpers/filesystem.js"
|
|
||||||
import { AssetBuilderProvider } from "./asset-builder-context.js"
|
|
||||||
|
|
||||||
export type AssetTransformer<Asset> = {
|
|
||||||
transform: (context: AssetTransformContext) => Promise<Asset>
|
|
||||||
}
|
|
||||||
|
|
||||||
export class AssetBuilder {
|
|
||||||
private constructor(private cacheFolder: string) {}
|
|
||||||
|
|
||||||
static async create(cacheFolder: string) {
|
|
||||||
if (process.env.NODE_ENV !== "production") {
|
|
||||||
await rm(cacheFolder, { recursive: true }).catch(() => {})
|
|
||||||
}
|
|
||||||
await mkdir(cacheFolder, { recursive: true })
|
|
||||||
return new AssetBuilder(cacheFolder)
|
|
||||||
}
|
|
||||||
|
|
||||||
async build<Asset>(
|
|
||||||
input: Promisable<string | URL>,
|
|
||||||
transformer: AssetTransformer<Asset>,
|
|
||||||
alias?: string,
|
|
||||||
): Promise<Asset> {
|
|
||||||
const inputFile = normalizeAsFilePath(await input)
|
|
||||||
// TODO: cache assets by inputFile in production
|
|
||||||
|
|
||||||
return transformer.transform(
|
|
||||||
new AssetTransformContext({
|
|
||||||
inputFile,
|
|
||||||
cacheFolder: this.cacheFolder,
|
|
||||||
alias: alias || parse(inputFile).name,
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
async render(element: React.ReactElement) {
|
|
||||||
element = (
|
|
||||||
<AssetBuilderProvider value={this}>
|
|
||||||
<React.Suspense fallback={<></>}>{element}</React.Suspense>
|
|
||||||
</AssetBuilderProvider>
|
|
||||||
)
|
|
||||||
await ssrPrepass(element)
|
|
||||||
return `<!DOCTYPE html>\n${renderToStaticMarkup(element)}`
|
|
||||||
}
|
|
||||||
|
|
||||||
middleware(): RequestHandler {
|
|
||||||
return express.static(this.cacheFolder, {
|
|
||||||
immutable: true,
|
|
||||||
maxAge: "1y",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export type AssetTransformOptions = {
|
|
||||||
inputFile: string
|
|
||||||
cacheFolder: string
|
|
||||||
alias: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export class AssetTransformContext {
|
|
||||||
constructor(private options: AssetTransformOptions) {}
|
|
||||||
|
|
||||||
get inputFile() {
|
|
||||||
return this.options.inputFile
|
|
||||||
}
|
|
||||||
|
|
||||||
get cacheFolder() {
|
|
||||||
return this.options.cacheFolder
|
|
||||||
}
|
|
||||||
|
|
||||||
get alias() {
|
|
||||||
return this.options.alias
|
|
||||||
}
|
|
||||||
|
|
||||||
getOutputFileName(content: string) {
|
|
||||||
const { ext } = parse(this.inputFile)
|
|
||||||
const hash = createHash("sha256").update(content).digest("hex").slice(0, 8)
|
|
||||||
return `${this.alias}.${hash}${ext}`
|
|
||||||
}
|
|
||||||
|
|
||||||
async writeOutputFile(content: string) {
|
|
||||||
const outputFileName = this.getOutputFileName(content)
|
|
||||||
const outputFile = join(this.cacheFolder, outputFileName)
|
|
||||||
await ensureWrite(outputFile, content)
|
|
||||||
return { outputFileName, outputFile }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
import type { ReactNode } from "react";
|
|
||||||
import React from "react"
|
|
||||||
import { normalizeAsFilePath } from "../helpers/filesystem.js"
|
|
||||||
import { useAssetBuilder } from "./asset-builder-context.js"
|
|
||||||
import type { AssetBuilder, AssetTransformer } from "./asset-builder.js"
|
|
||||||
|
|
||||||
type AssetState =
|
|
||||||
| { status: "building"; promise: Promise<unknown> }
|
|
||||||
| { status: "built"; asset: unknown }
|
|
||||||
|
|
||||||
const cache = new Map<string, AssetState>()
|
|
||||||
|
|
||||||
function useAssetBuild<Asset>(
|
|
||||||
cacheKey: string,
|
|
||||||
build: (builder: AssetBuilder) => Promise<Asset>,
|
|
||||||
) {
|
|
||||||
const builder = useAssetBuilder()
|
|
||||||
|
|
||||||
const state = cache.get(cacheKey)
|
|
||||||
if (!state) {
|
|
||||||
const promise = build(builder).then((asset) => {
|
|
||||||
cache.set(cacheKey, { status: "built", asset })
|
|
||||||
})
|
|
||||||
|
|
||||||
cache.set(cacheKey, { status: "building", promise })
|
|
||||||
throw promise
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state.status === "building") {
|
|
||||||
throw state.promise
|
|
||||||
}
|
|
||||||
|
|
||||||
return state.asset as Asset
|
|
||||||
}
|
|
||||||
|
|
||||||
export function LocalFileAsset<Asset>({
|
|
||||||
from,
|
|
||||||
using: transformer,
|
|
||||||
as: alias,
|
|
||||||
children,
|
|
||||||
}: {
|
|
||||||
from: string | URL
|
|
||||||
using: AssetTransformer<Asset>
|
|
||||||
as?: string
|
|
||||||
children: (url: Asset) => ReactNode
|
|
||||||
}) {
|
|
||||||
const inputFile = normalizeAsFilePath(from)
|
|
||||||
|
|
||||||
const asset = useAssetBuild(inputFile, (builder) => {
|
|
||||||
return builder.build(inputFile, transformer, alias)
|
|
||||||
})
|
|
||||||
|
|
||||||
return <>{children(asset)}</>
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ModuleAsset<Asset>({
|
|
||||||
from,
|
|
||||||
using: transformer,
|
|
||||||
as: name,
|
|
||||||
children,
|
|
||||||
}: {
|
|
||||||
from: string
|
|
||||||
using: AssetTransformer<Asset>
|
|
||||||
as?: string
|
|
||||||
children: (url: Asset) => ReactNode
|
|
||||||
}) {
|
|
||||||
const cacheKey = `node:${from}`
|
|
||||||
|
|
||||||
const asset = useAssetBuild(cacheKey, async (builder) => {
|
|
||||||
const inputFile = await import.meta.resolve!(from)
|
|
||||||
return await builder.build(inputFile, transformer, name)
|
|
||||||
})
|
|
||||||
|
|
||||||
return <>{children(asset)}</>
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
import grayMatter from "gray-matter"
|
|
||||||
import MarkdownIt from "markdown-it"
|
|
||||||
import prism from "markdown-it-prism"
|
|
||||||
import { readFile } from "node:fs/promises"
|
|
||||||
import type { AssetTransformer } from "./asset-builder.jsx"
|
|
||||||
|
|
||||||
const renderer = new MarkdownIt({
|
|
||||||
html: true,
|
|
||||||
linkify: true,
|
|
||||||
}).use(prism)
|
|
||||||
|
|
||||||
export type MarkdownAsset = {
|
|
||||||
content: { __html: string }
|
|
||||||
data: Record<string, any>
|
|
||||||
}
|
|
||||||
|
|
||||||
export const markdownTransformer: AssetTransformer<MarkdownAsset> = {
|
|
||||||
async transform(context) {
|
|
||||||
const { data, content } = grayMatter(
|
|
||||||
await readFile(context.inputFile, "utf8"),
|
|
||||||
)
|
|
||||||
const html = renderer.render(content)
|
|
||||||
|
|
||||||
return {
|
|
||||||
content: { __html: html },
|
|
||||||
data,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
import { build } from "esbuild"
|
|
||||||
import type { AssetTransformer } from "./asset-builder.jsx"
|
|
||||||
|
|
||||||
type ScriptAsset = {
|
|
||||||
url: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export const scriptTransformer: AssetTransformer<ScriptAsset> = {
|
|
||||||
async transform(context) {
|
|
||||||
const scriptBuild = await build({
|
|
||||||
entryPoints: [context.inputFile],
|
|
||||||
bundle: true,
|
|
||||||
target: ["chrome89", "firefox89"],
|
|
||||||
format: "esm",
|
|
||||||
write: false,
|
|
||||||
minify: process.env.NODE_ENV === "production",
|
|
||||||
})
|
|
||||||
|
|
||||||
const content = scriptBuild.outputFiles[0]!.text
|
|
||||||
const { outputFileName } = await context.writeOutputFile(content)
|
|
||||||
|
|
||||||
return {
|
|
||||||
url: "/" + outputFileName,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
import autoprefixer from "autoprefixer"
|
|
||||||
import cssnano from "cssnano"
|
|
||||||
import { readFile } from "node:fs/promises"
|
|
||||||
import type { AcceptedPlugin } from "postcss"
|
|
||||||
import postcss from "postcss"
|
|
||||||
import tailwindcss from "tailwindcss"
|
|
||||||
import type { AssetTransformer } from "./asset-builder.jsx"
|
|
||||||
|
|
||||||
export type StylesheetAsset = { url: string }
|
|
||||||
|
|
||||||
export const stylesheetTransformer: AssetTransformer<StylesheetAsset> = {
|
|
||||||
async transform(context) {
|
|
||||||
const plugins: AcceptedPlugin[] = [tailwindcss, autoprefixer]
|
|
||||||
if (process.env.NODE_ENV === "production") {
|
|
||||||
plugins.push(cssnano)
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await postcss(plugins).process(
|
|
||||||
await readFile(context.inputFile),
|
|
||||||
{ from: context.inputFile },
|
|
||||||
)
|
|
||||||
|
|
||||||
const { outputFileName } = await context.writeOutputFile(result.css)
|
|
||||||
return { url: "/" + outputFileName }
|
|
||||||
},
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
import { join } from "node:path"
|
|
||||||
|
|
||||||
const projectRoot = new URL("../", import.meta.url).pathname
|
|
||||||
|
|
||||||
export function fromProjectRoot(...subPaths: string[]) {
|
|
||||||
return join(projectRoot, ...subPaths)
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
import type { ComponentPropsWithoutRef } from "react"
|
|
||||||
import React from "react"
|
|
||||||
|
|
||||||
export function ExternalLink(props: ComponentPropsWithoutRef<"a">) {
|
|
||||||
return (
|
|
||||||
<a target="_blank" rel="noopener noreferrer" {...props}>
|
|
||||||
{props.children}
|
|
||||||
</a>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
---
|
|
||||||
order: 3
|
|
||||||
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) for more information.
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
---
|
|
||||||
order: 0
|
|
||||||
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,56 +0,0 @@
|
|||||||
import clsx from "clsx"
|
|
||||||
import React from "react"
|
|
||||||
import { LocalFileAsset } from "../asset-builder/asset.js"
|
|
||||||
import { markdownTransformer } from "../asset-builder/markdown-transformer.js"
|
|
||||||
import { Html } from "../html.js"
|
|
||||||
import { AppLink } from "../navigation/app-link"
|
|
||||||
import { guideLinks } from "../navigation/guide-links"
|
|
||||||
import { MainNavigation } from "../navigation/main-navigation"
|
|
||||||
import { docsProseClass, linkClass, maxWidthContainer } from "../ui/components"
|
|
||||||
|
|
||||||
export function GuidePage({ url }: { url: string }) {
|
|
||||||
return (
|
|
||||||
<LocalFileAsset
|
|
||||||
from={new URL(`${url}.md`, import.meta.url)}
|
|
||||||
using={markdownTransformer}
|
|
||||||
>
|
|
||||||
{(asset) => (
|
|
||||||
<Html title={asset.data.title} description={asset.data.description}>
|
|
||||||
<Header />
|
|
||||||
<Body content={asset.content} />
|
|
||||||
</Html>
|
|
||||||
)}
|
|
||||||
</LocalFileAsset>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function Header() {
|
|
||||||
return (
|
|
||||||
<header className="bg-slate-700/30 shadow sticky top-0 backdrop-blur-sm transition z-10 flex">
|
|
||||||
<div className={maxWidthContainer}>
|
|
||||||
<MainNavigation />
|
|
||||||
</div>
|
|
||||||
</header>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function Body({ content }: { content: { __html: string } }) {
|
|
||||||
return (
|
|
||||||
<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")}
|
|
||||||
dangerouslySetInnerHTML={content}
|
|
||||||
/>
|
|
||||||
</main>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
---
|
|
||||||
order: 4
|
|
||||||
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) for more information.
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import { mkdir, writeFile } from "node:fs/promises"
|
|
||||||
import { dirname } from "node:path"
|
|
||||||
|
|
||||||
export async function ensureWrite(file: string, content: string) {
|
|
||||||
await mkdir(dirname(file), { recursive: true })
|
|
||||||
await writeFile(file, content)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function normalizeAsFilePath(file: string | URL) {
|
|
||||||
return new URL(file, "file:").pathname
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
import grayMatter from "gray-matter"
|
|
||||||
import MarkdownIt from "markdown-it"
|
|
||||||
import prism from "markdown-it-prism"
|
|
||||||
import { readFile } from "node:fs/promises"
|
|
||||||
|
|
||||||
const renderer = new MarkdownIt({
|
|
||||||
html: true,
|
|
||||||
linkify: true,
|
|
||||||
}).use(prism)
|
|
||||||
|
|
||||||
export async function renderMarkdownFile(filePath: string) {
|
|
||||||
const { data, content } = grayMatter(await readFile(filePath, "utf8"))
|
|
||||||
const html = renderer.render(content)
|
|
||||||
return { html, data }
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
export function raise(error: unknown): never {
|
|
||||||
throw error instanceof Error ? error : new Error(String(error))
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
import packageJson from "reacord/package.json"
|
|
||||||
import type { ReactNode } from "react"
|
|
||||||
import React from "react"
|
|
||||||
import { LocalFileAsset, ModuleAsset } from "./asset-builder/asset.js"
|
|
||||||
import { scriptTransformer } from "./asset-builder/script-transformer.js"
|
|
||||||
import { stylesheetTransformer } from "./asset-builder/stylesheet-transformer.js"
|
|
||||||
|
|
||||||
export function Html({
|
|
||||||
title: titleProp,
|
|
||||||
description = packageJson.description,
|
|
||||||
children,
|
|
||||||
}: {
|
|
||||||
title?: string
|
|
||||||
description?: string
|
|
||||||
children: ReactNode
|
|
||||||
}) {
|
|
||||||
const title = [titleProp, "Reacord"].filter(Boolean).join(" | ")
|
|
||||||
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 name="description" content={description} />
|
|
||||||
|
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
||||||
<link
|
|
||||||
rel="preconnect"
|
|
||||||
href="https://fonts.gstatic.com"
|
|
||||||
crossOrigin=""
|
|
||||||
/>
|
|
||||||
<link
|
|
||||||
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"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<ModuleAsset
|
|
||||||
from="tailwindcss/tailwind.css"
|
|
||||||
using={stylesheetTransformer}
|
|
||||||
>
|
|
||||||
{(asset) => <link rel="stylesheet" href={asset.url} />}
|
|
||||||
</ModuleAsset>
|
|
||||||
|
|
||||||
<LocalFileAsset
|
|
||||||
from={new URL("ui/prism-theme.css", import.meta.url)}
|
|
||||||
using={stylesheetTransformer}
|
|
||||||
>
|
|
||||||
{(asset) => <link rel="stylesheet" href={asset.url} />}
|
|
||||||
</LocalFileAsset>
|
|
||||||
<LocalFileAsset
|
|
||||||
from={new URL("ui/markdown.css", import.meta.url)}
|
|
||||||
using={stylesheetTransformer}
|
|
||||||
>
|
|
||||||
{(asset) => <link rel="stylesheet" href={asset.url} />}
|
|
||||||
</LocalFileAsset>
|
|
||||||
|
|
||||||
<title>{title}</title>
|
|
||||||
|
|
||||||
<ModuleAsset
|
|
||||||
from="alpinejs/dist/cdn.js"
|
|
||||||
as="alpine"
|
|
||||||
using={scriptTransformer}
|
|
||||||
>
|
|
||||||
{(asset) => <script defer src={asset.url} />}
|
|
||||||
</ModuleAsset>
|
|
||||||
</head>
|
|
||||||
<body>{children}</body>
|
|
||||||
</html>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -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,42 +0,0 @@
|
|||||||
import packageJson from "reacord/package.json"
|
|
||||||
import React from "react"
|
|
||||||
import { LocalFileAsset } from "../asset-builder/asset.js"
|
|
||||||
import { markdownTransformer } from "../asset-builder/markdown-transformer.js"
|
|
||||||
import { Html } from "../html.js"
|
|
||||||
import { MainNavigation } from "../navigation/main-navigation"
|
|
||||||
import { maxWidthContainer } from "../ui/components"
|
|
||||||
|
|
||||||
export function Landing() {
|
|
||||||
return (
|
|
||||||
<Html>
|
|
||||||
<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>
|
|
||||||
<LocalFileAsset
|
|
||||||
from={new URL("landing-example.md", import.meta.url)}
|
|
||||||
using={markdownTransformer}
|
|
||||||
>
|
|
||||||
{(asset) => (
|
|
||||||
<section
|
|
||||||
className="mx-auto text-sm sm:text-base"
|
|
||||||
dangerouslySetInnerHTML={asset.content}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</LocalFileAsset>
|
|
||||||
<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>
|
|
||||||
</Html>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
import compression from "compression"
|
|
||||||
import type { ErrorRequestHandler, Request } from "express"
|
|
||||||
import express from "express"
|
|
||||||
import PromiseRouter from "express-promise-router"
|
|
||||||
import httpTerminator from "http-terminator"
|
|
||||||
import pino from "pino"
|
|
||||||
import pinoHttp from "pino-http"
|
|
||||||
import * as React from "react"
|
|
||||||
import { AssetBuilder } from "./asset-builder/asset-builder.js"
|
|
||||||
import { fromProjectRoot } from "./constants"
|
|
||||||
import { GuidePage } from "./guides/guide-page"
|
|
||||||
import { Landing } from "./landing/landing"
|
|
||||||
|
|
||||||
const port = process.env.PORT || 3000
|
|
||||||
const builder = await AssetBuilder.create(fromProjectRoot(".asset-cache"))
|
|
||||||
const logger = pino()
|
|
||||||
|
|
||||||
const errorHandler: ErrorRequestHandler = (error, request, response, next) => {
|
|
||||||
response.status(500).send(error.message)
|
|
||||||
logger.error(error)
|
|
||||||
}
|
|
||||||
|
|
||||||
const router = PromiseRouter()
|
|
||||||
.use(pinoHttp({ logger }))
|
|
||||||
.use(compression())
|
|
||||||
.use(builder.middleware())
|
|
||||||
.use("/api", express.static("dist/api"))
|
|
||||||
|
|
||||||
.get("/guides/*", async (req: Request<{ 0: string }>, res) => {
|
|
||||||
res
|
|
||||||
.type("html")
|
|
||||||
.send(await builder.render(<GuidePage url={req.params[0]} />))
|
|
||||||
})
|
|
||||||
|
|
||||||
.get("/", async (req, res) => {
|
|
||||||
res.type("html").send(await builder.render(<Landing />))
|
|
||||||
})
|
|
||||||
|
|
||||||
.use(errorHandler)
|
|
||||||
|
|
||||||
const server = express()
|
|
||||||
.use(router)
|
|
||||||
.listen(port, () => {
|
|
||||||
logger.info(`Server is running on http://localhost:${port}`)
|
|
||||||
})
|
|
||||||
|
|
||||||
const terminator = httpTerminator.createHttpTerminator({ server })
|
|
||||||
|
|
||||||
process.on("SIGINT", () => {
|
|
||||||
terminator
|
|
||||||
.terminate()
|
|
||||||
.then(() => {
|
|
||||||
logger.info("Server terminated")
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
logger.error(error)
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
process.exit()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
import React from "react"
|
|
||||||
import { ExternalLink } from "../dom/external-link"
|
|
||||||
|
|
||||||
export type AppLinkProps = {
|
|
||||||
type: "internal" | "external"
|
|
||||||
label: React.ReactNode
|
|
||||||
to: string
|
|
||||||
className?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export function AppLink(props: AppLinkProps) {
|
|
||||||
switch (props.type) {
|
|
||||||
case "internal":
|
|
||||||
return (
|
|
||||||
<a className={props.className} href={props.to}>
|
|
||||||
{props.label}
|
|
||||||
</a>
|
|
||||||
)
|
|
||||||
|
|
||||||
case "external":
|
|
||||||
return (
|
|
||||||
<ExternalLink className={props.className} href={props.to}>
|
|
||||||
{props.label}
|
|
||||||
</ExternalLink>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
import glob from "fast-glob"
|
|
||||||
import grayMatter from "gray-matter"
|
|
||||||
import { readFile } from "node:fs/promises"
|
|
||||||
import { join } from "node:path"
|
|
||||||
import type { AppLinkProps } from "./app-link"
|
|
||||||
|
|
||||||
const docsFolder = new URL("../guides", import.meta.url).pathname
|
|
||||||
const guideFiles = await glob("**/*.md", { cwd: docsFolder })
|
|
||||||
|
|
||||||
const entries = await Promise.all(
|
|
||||||
guideFiles.map(async (file) => {
|
|
||||||
const content = await readFile(join(docsFolder, file), "utf-8")
|
|
||||||
const { data } = grayMatter(content)
|
|
||||||
|
|
||||||
let order = Number(data.order)
|
|
||||||
if (!Number.isFinite(order)) {
|
|
||||||
order = Number.POSITIVE_INFINITY
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
route: `/guides/${file.replace(/\.mdx?$/, "")}`,
|
|
||||||
title: String(data.title || ""),
|
|
||||||
order,
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
|
|
||||||
export const guideLinks: AppLinkProps[] = entries
|
|
||||||
.sort((a, b) => a.order - b.order)
|
|
||||||
.map((item) => ({
|
|
||||||
type: "internal",
|
|
||||||
label: item.title,
|
|
||||||
to: item.route,
|
|
||||||
}))
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
import {
|
|
||||||
CodeIcon,
|
|
||||||
DocumentTextIcon,
|
|
||||||
ExternalLinkIcon,
|
|
||||||
} from "@heroicons/react/solid/esm"
|
|
||||||
import React from "react"
|
|
||||||
import { inlineIconClass } from "../ui/components"
|
|
||||||
import type { AppLinkProps } from "./app-link"
|
|
||||||
|
|
||||||
export const mainLinks: AppLinkProps[] = [
|
|
||||||
{
|
|
||||||
type: "internal",
|
|
||||||
to: "/guides/getting-started",
|
|
||||||
label: (
|
|
||||||
<>
|
|
||||||
<DocumentTextIcon className={inlineIconClass} /> Guides
|
|
||||||
</>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "internal",
|
|
||||||
to: "/api",
|
|
||||||
label: (
|
|
||||||
<>
|
|
||||||
<CodeIcon className={inlineIconClass} /> API Reference
|
|
||||||
</>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "external",
|
|
||||||
to: "https://github.com/itsMapleLeaf/reacord",
|
|
||||||
label: (
|
|
||||||
<>
|
|
||||||
<ExternalLinkIcon className={inlineIconClass} /> GitHub
|
|
||||||
</>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
]
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
import React from "react"
|
|
||||||
import { linkClass } from "../ui/components"
|
|
||||||
import { PopoverMenu } from "../ui/popover-menu"
|
|
||||||
import { AppLink } from "./app-link"
|
|
||||||
import { guideLinks } from "./guide-links"
|
|
||||||
import { mainLinks } from "./main-links"
|
|
||||||
|
|
||||||
export function MainNavigation() {
|
|
||||||
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" id="main-navigation-popover">
|
|
||||||
<PopoverMenu>
|
|
||||||
{mainLinks.map((link) => (
|
|
||||||
<AppLink
|
|
||||||
{...link}
|
|
||||||
key={link.to}
|
|
||||||
className={PopoverMenu.itemClass}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
<hr className="border-0 h-[2px] bg-black/50" />
|
|
||||||
{guideLinks.map((link) => (
|
|
||||||
<AppLink
|
|
||||||
{...link}
|
|
||||||
key={link.to}
|
|
||||||
className={PopoverMenu.itemClass}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</PopoverMenu>
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
10
packages/docs/src/react.d.ts
vendored
10
packages/docs/src/react.d.ts
vendored
@@ -1,10 +0,0 @@
|
|||||||
import "react"
|
|
||||||
declare module "react" {
|
|
||||||
export function createContext<Value>(): Context<Value | undefined>
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module "react-dom" {
|
|
||||||
export function createRoot(element: Element): {
|
|
||||||
render(element: React.ReactNode): void
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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,3 +0,0 @@
|
|||||||
.prose aside {
|
|
||||||
@apply opacity-75 italic border-l-4 pl-3 border-white/50;
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
import clsx from "clsx"
|
|
||||||
|
|
||||||
const menus = document.querySelectorAll("[data-popover]")
|
|
||||||
|
|
||||||
for (const menu of menus) {
|
|
||||||
const button = menu.querySelector<HTMLButtonElement>("[data-popover-button]")!
|
|
||||||
|
|
||||||
const panel = menu.querySelector<HTMLDivElement>("[data-popover-panel]")!
|
|
||||||
const panelClasses = clsx`${panel.className} transition-all`
|
|
||||||
|
|
||||||
const visibleClass = clsx`${panelClasses} visible opacity-100 translate-y-0`
|
|
||||||
const hiddenClass = clsx`${panelClasses} invisible opacity-0 translate-y-2`
|
|
||||||
|
|
||||||
let visible = false
|
|
||||||
|
|
||||||
const setVisible = (newVisible: boolean) => {
|
|
||||||
visible = newVisible
|
|
||||||
panel.className = visible ? visibleClass : hiddenClass
|
|
||||||
|
|
||||||
if (!visible) return
|
|
||||||
|
|
||||||
requestAnimationFrame(() => {
|
|
||||||
const handleClose = (event: MouseEvent) => {
|
|
||||||
if (panel.contains(event.target as Node)) return
|
|
||||||
setVisible(false)
|
|
||||||
window.removeEventListener("click", handleClose)
|
|
||||||
}
|
|
||||||
window.addEventListener("click", handleClose)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const toggleVisible = () => setVisible(!visible)
|
|
||||||
|
|
||||||
button.addEventListener("click", toggleVisible)
|
|
||||||
|
|
||||||
setVisible(false)
|
|
||||||
panel.hidden = false
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
import { MenuAlt4Icon } from "@heroicons/react/outline/esm"
|
|
||||||
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
|
|
||||||
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,15 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
module.exports = {
|
|
||||||
content: ["./src/**/*.{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,3 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "../../tsconfig.base.json"
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
{
|
|
||||||
"entryPoints": ["../reacord/library/main.ts"],
|
|
||||||
"out": ["dist/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
|
||||||
|
}
|
||||||
14
packages/helpers/package.json
Normal file
14
packages/helpers/package.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "@reacord/helpers",
|
||||||
|
"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.3.2",
|
||||||
|
"vitest": "^0.34.5"
|
||||||
|
}
|
||||||
|
}
|
||||||
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 { toError } from "./to-error.js"
|
||||||
|
import { setTimeout } from "node:timers/promises"
|
||||||
|
|
||||||
export async function rejectAfter(
|
export async function rejectAfter(
|
||||||
timeMs: number,
|
timeMs: number,
|
||||||
error: unknown = `rejected after ${timeMs}ms`,
|
error: unknown = `rejected after ${timeMs}ms`,
|
||||||
): Promise<never> {
|
): Promise<never> {
|
||||||
await setTimeout(timeMs)
|
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
|
||||||
32
packages/reacord/CHANGELOG.md
Normal file
32
packages/reacord/CHANGELOG.md
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# reacord
|
||||||
|
|
||||||
|
## 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,22 +1,49 @@
|
|||||||
import type { ReactNode } from "react"
|
import type { ReactNode } from "react"
|
||||||
import type { ReacordInstance } from "./instance"
|
import type { ReacordInstance } from "./instance"
|
||||||
|
|
||||||
/**
|
/** @category Component Event */
|
||||||
* @category Component Event
|
export interface ComponentEvent {
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
*/
|
*/
|
||||||
export type ComponentEvent = {
|
|
||||||
message: MessageInfo
|
message: MessageInfo
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The channel that this event occurred in.
|
||||||
|
*
|
||||||
|
* @see https://discord.com/developers/docs/resources/channel#channel-object
|
||||||
|
*/
|
||||||
channel: ChannelInfo
|
channel: ChannelInfo
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The user that triggered this event.
|
||||||
|
*
|
||||||
|
* @see https://discord.com/developers/docs/resources/user#user-object
|
||||||
|
*/
|
||||||
user: UserInfo
|
user: UserInfo
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The guild that this event occurred in.
|
||||||
|
*
|
||||||
|
* @see https://discord.com/developers/docs/resources/guild#guild-object
|
||||||
|
*/
|
||||||
guild?: GuildInfo
|
guild?: GuildInfo
|
||||||
|
|
||||||
|
/** Create a new reply to this event. */
|
||||||
reply(content?: ReactNode): ReacordInstance
|
reply(content?: ReactNode): ReacordInstance
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 ChannelInfo {
|
||||||
*/
|
|
||||||
export type ChannelInfo = {
|
|
||||||
id: string
|
id: string
|
||||||
name?: string
|
name?: string
|
||||||
topic?: string
|
topic?: string
|
||||||
@@ -27,13 +54,11 @@ export type ChannelInfo = {
|
|||||||
rateLimitPerUser?: number
|
rateLimitPerUser?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @category Component Event */
|
||||||
* @category Component Event
|
export interface MessageInfo {
|
||||||
*/
|
|
||||||
export type MessageInfo = {
|
|
||||||
id: string
|
id: string
|
||||||
channelId: string
|
channelId: string
|
||||||
authorId: UserInfo
|
authorId: string
|
||||||
member?: GuildMemberInfo
|
member?: GuildMemberInfo
|
||||||
content: string
|
content: string
|
||||||
timestamp: string
|
timestamp: string
|
||||||
@@ -44,19 +69,15 @@ export type MessageInfo = {
|
|||||||
mentions: string[]
|
mentions: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @category Component Event */
|
||||||
* @category Component Event
|
export interface GuildInfo {
|
||||||
*/
|
|
||||||
export type GuildInfo = {
|
|
||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
member: GuildMemberInfo
|
member: GuildMemberInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @category Component Event */
|
||||||
* @category Component Event
|
export interface GuildMemberInfo {
|
||||||
*/
|
|
||||||
export type GuildMemberInfo = {
|
|
||||||
id: string
|
id: string
|
||||||
nick?: string
|
nick?: string
|
||||||
displayName: string
|
displayName: string
|
||||||
@@ -70,14 +91,12 @@ export type GuildMemberInfo = {
|
|||||||
communicationDisabledUntil?: string
|
communicationDisabledUntil?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @category Component Event */
|
||||||
* @category Component Event
|
export interface UserInfo {
|
||||||
*/
|
|
||||||
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,29 +1,30 @@
|
|||||||
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
|
||||||
* <ActionRow>
|
* <ActionRow>
|
||||||
* <Button onClick={handleFirst}>First</Button>
|
* <Button label="First" onClick={handleFirst} />
|
||||||
* </ActionRow>
|
* </ActionRow>
|
||||||
* <Button onClick={handleSecond}>Second</Button>
|
* <Button label="Second" onClick={handleSecond} />
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @category Action Row
|
* @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 {
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import type { ReactNode } from "react"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common props between button-like components
|
||||||
|
*
|
||||||
|
* @category Button
|
||||||
|
*/
|
||||||
|
export interface ButtonSharedProps {
|
||||||
|
/** The text on the button. Rich formatting (markdown) is not supported here. */
|
||||||
|
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>`.
|
||||||
|
*
|
||||||
|
* 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,38 +1,47 @@
|
|||||||
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"
|
||||||
import { getNextActionRow } from "../../internal/message"
|
import { getNextActionRow } from "../../internal/message"
|
||||||
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 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
|
||||||
*/
|
*/
|
||||||
export type ButtonProps = {
|
|
||||||
label?: string
|
|
||||||
style?: "primary" | "secondary" | "success" | "danger"
|
style?: "primary" | "secondary" | "success" | "danger"
|
||||||
disabled?: boolean
|
|
||||||
emoji?: string
|
/** 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({
|
||||||
@@ -41,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,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,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
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user