@nkootstra/block-kit 0.1.1 → 0.2.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/README.md +3 -3
- package/dist/index.js +16 -7
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
`@nkootstra/block-kit` renders Slack [Block Kit](https://docs.slack.dev/block-kit/) JSON in React, pixel-for-pixel the way Slack does. Pass it the `blocks` your app sends to `chat.postMessage` or `views.open` and it draws the message, modal or Home tab, with working buttons, menus, date pickers and inputs.
|
|
4
4
|
|
|
5
|
-
Documentation: **<https://block-kit.
|
|
5
|
+
Documentation: **<https://docs.block-kit.dev>**
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
|
-
The package needs React
|
|
9
|
+
The package needs React 18 or later.
|
|
10
10
|
|
|
11
11
|
```sh
|
|
12
12
|
bun add @nkootstra/block-kit @fontsource/lato @fontsource/roboto-mono
|
|
@@ -33,7 +33,7 @@ export function App() {
|
|
|
33
33
|
}
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
The [installation guide](https://block-kit.
|
|
36
|
+
The [installation guide](https://docs.block-kit.dev/installation) lists the remaining font weights and the entry points, and the [quickstart](https://docs.block-kit.dev/quickstart) wires up an interactive approval message.
|
|
37
37
|
|
|
38
38
|
## Entry points
|
|
39
39
|
|
package/dist/index.js
CHANGED
|
@@ -1228,6 +1228,13 @@ function actionTs(now = Date.now()) {
|
|
|
1228
1228
|
return (now / 1e3).toFixed(6);
|
|
1229
1229
|
}
|
|
1230
1230
|
//#endregion
|
|
1231
|
+
//#region src/useClientLayoutEffect.ts
|
|
1232
|
+
/**
|
|
1233
|
+
* `useLayoutEffect` in the browser and `useEffect` on the server, where neither runs. React 18
|
|
1234
|
+
* warns about every `useLayoutEffect` it meets while server rendering; React 19 doesn't.
|
|
1235
|
+
*/
|
|
1236
|
+
const useClientLayoutEffect = typeof document === "undefined" ? useEffect : useLayoutEffect;
|
|
1237
|
+
//#endregion
|
|
1231
1238
|
//#region src/Tooltip.tsx
|
|
1232
1239
|
/** How long the pointer rests on an anchor before its tooltip shows. */
|
|
1233
1240
|
const SHOW_DELAY_MS = 300;
|
|
@@ -1245,7 +1252,7 @@ function Tooltip({ label, children, placement = "top" }) {
|
|
|
1245
1252
|
const tipRef = useRef(null);
|
|
1246
1253
|
const timer = useRef(void 0);
|
|
1247
1254
|
useEffect(() => () => clearTimeout(timer.current), []);
|
|
1248
|
-
|
|
1255
|
+
useClientLayoutEffect(() => {
|
|
1249
1256
|
if (!open) {
|
|
1250
1257
|
setPosition(null);
|
|
1251
1258
|
return;
|
|
@@ -5623,7 +5630,7 @@ function UserMention({ id, name }) {
|
|
|
5623
5630
|
const anchorRef = useRef(null);
|
|
5624
5631
|
const cardRef = useRef(null);
|
|
5625
5632
|
const cardId = useId();
|
|
5626
|
-
|
|
5633
|
+
useClientLayoutEffect(() => {
|
|
5627
5634
|
if (!open) {
|
|
5628
5635
|
setPosition(null);
|
|
5629
5636
|
return;
|
|
@@ -5979,7 +5986,9 @@ function Button({ element, blockId }) {
|
|
|
5979
5986
|
* Slack's `focus_on_load`: the element takes focus when its modal or Home tab opens. Slack ignores
|
|
5980
5987
|
* it in messages and allows it on only one element per view.
|
|
5981
5988
|
*
|
|
5982
|
-
* Pass the element's own ref when it already has one; otherwise attach the returned ref.
|
|
5989
|
+
* Pass the element's own ref when it already has one; otherwise attach the returned ref. The return
|
|
5990
|
+
* type is `useRef`'s own, which differs between @types/react 18 and 19, so it fits a `ref` prop in
|
|
5991
|
+
* both.
|
|
5983
5992
|
*/
|
|
5984
5993
|
function useFocusOnLoad(element, existing) {
|
|
5985
5994
|
const { surface } = useBlockKit();
|
|
@@ -6247,10 +6256,10 @@ function Popover({ anchorRef, onDismiss, gap = DEFAULT_GAP, children }) {
|
|
|
6247
6256
|
const layerRef = useRef(null);
|
|
6248
6257
|
const [position, setPosition] = useState(null);
|
|
6249
6258
|
const dismiss = useRef(onDismiss);
|
|
6250
|
-
|
|
6259
|
+
useClientLayoutEffect(() => {
|
|
6251
6260
|
dismiss.current = onDismiss;
|
|
6252
6261
|
});
|
|
6253
|
-
|
|
6262
|
+
useClientLayoutEffect(() => {
|
|
6254
6263
|
function place() {
|
|
6255
6264
|
const anchor = anchorRef.current;
|
|
6256
6265
|
const layer = layerRef.current;
|
|
@@ -8179,7 +8188,8 @@ function Collapse({ open, className, children }) {
|
|
|
8179
8188
|
const [shown, setShown] = useState(open);
|
|
8180
8189
|
if (open && !shown) setShown(true);
|
|
8181
8190
|
const was = useRef(open);
|
|
8182
|
-
|
|
8191
|
+
useClientLayoutEffect(() => {
|
|
8192
|
+
ref.current?.toggleAttribute("inert", !open);
|
|
8183
8193
|
if (was.current === open) return;
|
|
8184
8194
|
was.current = open;
|
|
8185
8195
|
const el = ref.current;
|
|
@@ -8197,7 +8207,6 @@ function Collapse({ open, className, children }) {
|
|
|
8197
8207
|
return /* @__PURE__ */ jsx("div", {
|
|
8198
8208
|
ref,
|
|
8199
8209
|
className: className ? `sbk-collapse ${className}` : "sbk-collapse",
|
|
8200
|
-
inert: !open,
|
|
8201
8210
|
onTransitionEnd: (e) => {
|
|
8202
8211
|
if (e.target !== e.currentTarget || e.propertyName !== "height") return;
|
|
8203
8212
|
if (open) e.currentTarget.style.height = "";
|