@tightknitai/block-kit-builder 0.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +111 -0
- package/dist/index.cjs +5890 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +352 -0
- package/dist/index.d.ts +352 -0
- package/dist/index.js +5857 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +2 -0
- package/package.json +104 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tightknit and block-kit-builder contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# block-kit-builder
|
|
2
|
+
|
|
3
|
+
[](https://github.com/TightknitAI/block-kit-builder/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/@tightknitai/block-kit-builder)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
A drag-and-drop, no-code-friendly visual builder for Slack Block Kit messages, packaged as an **integration-agnostic React component**.
|
|
8
|
+
|
|
9
|
+
The package owns the entire builder UX — palette, sortable preview surface, per-block popover editors, send dialog. It knows nothing about how channels are listed, who the user is, or how messages are sent. The consumer wires those concerns through callback props. A working end-to-end app is shown in [block-kit-builder-template](https://github.com/TightknitAI/block-kit-builder-template).
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add @tightknitai/block-kit-builder
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Peer deps: `react`, `react-dom`, `slack-web-api-client`.
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { BlockKitBuilder } from "@tightknitai/block-kit-builder";
|
|
23
|
+
import "@tightknitai/block-kit-builder/styles.css";
|
|
24
|
+
|
|
25
|
+
export function MyBuilderPage() {
|
|
26
|
+
return (
|
|
27
|
+
<BlockKitBuilder
|
|
28
|
+
workspaceName="Acme Inc."
|
|
29
|
+
loadChannels={async () => {
|
|
30
|
+
const res = await fetch("/api/slack/channels");
|
|
31
|
+
return res.json();
|
|
32
|
+
}}
|
|
33
|
+
loadSendAsUserStatus={async () => {
|
|
34
|
+
const res = await fetch("/api/slack/me/can-send-as-user");
|
|
35
|
+
return res.json();
|
|
36
|
+
}}
|
|
37
|
+
onSend={async ({ channelId, blocks, sendAsUser }) => {
|
|
38
|
+
const res = await fetch("/api/slack/messages/send", {
|
|
39
|
+
method: "POST",
|
|
40
|
+
body: JSON.stringify({ channelId, blocks, sendAsUser }),
|
|
41
|
+
});
|
|
42
|
+
return res.json();
|
|
43
|
+
}}
|
|
44
|
+
/>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Props
|
|
50
|
+
|
|
51
|
+
| Prop | Type | Required | Description |
|
|
52
|
+
|---|---|---|---|
|
|
53
|
+
| `workspaceName` | `string` | no | Shown in the preview chrome to mimic a real Slack message header. |
|
|
54
|
+
| `initialBlocks` | `SupportedBlock[]` | no | Starting draft. If omitted, the builder starts empty. |
|
|
55
|
+
| `onChange` | `(blocks: SupportedBlock[]) => void` | no | Fires on every state change. Use this to persist the draft (URL, localStorage, etc). |
|
|
56
|
+
| `loadChannels` | `() => Promise<{ id: string; name: string }[]>` | yes | Returns channels available to send to. The package never makes Slack API calls itself. |
|
|
57
|
+
| `loadSendAsUserStatus` | `() => Promise<{ canSendAsUser: boolean; oauthUrl?: string }>` | yes | Whether the current user has a Slack user-token and can post as themselves. If `canSendAsUser` is false, `oauthUrl` is shown as a "Sign in with Slack" link. |
|
|
58
|
+
| `onSend` | `(payload) => Promise<{ ok: boolean; error?: string }>` | yes | Called when the user submits the send dialog. Payload is `{ channelId, blocks, sendAsUser }`. |
|
|
59
|
+
| `previewHooks` | `PreviewHooks` | no | Hooks forwarded to `slack-blocks-to-jsx`'s `<Message>` for resolving user / channel / emoji directives. |
|
|
60
|
+
| `showSurfaceControl` | `boolean` | no | Defaults to `true`. When `false`, the surface is locked to `'message'`. |
|
|
61
|
+
| `showThemeControl` | `boolean` | no | Defaults to `true`. When `false`, the theme is locked to `'light'`. |
|
|
62
|
+
| `defaultPreviewTheme` | `'light' \| 'dark'` | no | Pass the host app's current theme so the preview opens matched to the consuming app's appearance. |
|
|
63
|
+
|
|
64
|
+
## Boundary
|
|
65
|
+
|
|
66
|
+
The package is deliberately decoupled from any Slack SDK or backend. It does not import HTTP clients, OAuth libraries, or workspace-state systems. Everything I/O-shaped is brokered through props.
|
|
67
|
+
|
|
68
|
+
Helpers also exported:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import {
|
|
72
|
+
toSlackBlocks, // strips builder-only fields (e.g. header `level`) before sending
|
|
73
|
+
encodeBlocksToString, // base64url-encode a blocks array (for URL state)
|
|
74
|
+
decodeBlocksFromString,
|
|
75
|
+
} from "@tightknitai/block-kit-builder";
|
|
76
|
+
|
|
77
|
+
import type {
|
|
78
|
+
SupportedBlock,
|
|
79
|
+
SupportedBlockType,
|
|
80
|
+
BlockKitBuilderProps,
|
|
81
|
+
SendPayload,
|
|
82
|
+
SendResult,
|
|
83
|
+
ChannelOption,
|
|
84
|
+
SendAsUserStatus,
|
|
85
|
+
PreviewHooks,
|
|
86
|
+
} from "@tightknitai/block-kit-builder";
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Backend
|
|
90
|
+
|
|
91
|
+
The builder is frontend-only. For a full app that handles OAuth, channel listing, and `chat.postMessage`, see [block-kit-builder-template](https://github.com/TightknitAI/block-kit-builder-template) — a Vite + React SPA on Cloudflare Workers that wires this package to [slack-hono](https://github.com/TightknitAI/slack-hono) on the backend.
|
|
92
|
+
|
|
93
|
+
## Validation
|
|
94
|
+
|
|
95
|
+
Defense-in-depth: blocks are validated against [slack-block-kit-validator](https://github.com/TightknitAI/slack-block-kit-validator) before send. Issues are surfaced in the issues sheet with line numbers — users can fix them inline before posting.
|
|
96
|
+
|
|
97
|
+
## Styling
|
|
98
|
+
|
|
99
|
+
Ships a compiled stylesheet at `@tightknitai/block-kit-builder/styles.css`. The styles use CSS custom properties (`--background`, `--primary`, `--border`, etc.) for theming. Consumers must provide values for these vars — the standard shadcn/ui token set works as-is.
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import "@tightknitai/block-kit-builder/styles.css";
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## License
|
|
106
|
+
|
|
107
|
+
MIT. See [LICENSE](./LICENSE).
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
Maintained by the [Tightknit](https://tightknit.ai) team.
|