@farcaster/snap 2.1.1 → 2.1.2

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.
Files changed (41) hide show
  1. package/dist/constants.d.ts +2 -1
  2. package/dist/constants.js +2 -1
  3. package/dist/react/components/cell-grid.js +13 -14
  4. package/dist/react/components/image.js +5 -1
  5. package/dist/react/components/stack.js +53 -3
  6. package/dist/react/components/text.js +7 -1
  7. package/dist/react/stack-direction-context.d.ts +7 -0
  8. package/dist/react/stack-direction-context.js +10 -0
  9. package/dist/react-native/components/snap-cell-grid.js +5 -7
  10. package/dist/react-native/components/snap-image.js +15 -2
  11. package/dist/react-native/components/snap-item.js +12 -2
  12. package/dist/react-native/components/snap-progress.js +8 -2
  13. package/dist/react-native/components/snap-stack.d.ts +1 -1
  14. package/dist/react-native/components/snap-stack.js +85 -10
  15. package/dist/react-native/components/snap-text.js +7 -2
  16. package/dist/react-native/stack-direction-context.d.ts +7 -0
  17. package/dist/react-native/stack-direction-context.js +9 -0
  18. package/dist/stack-horizontal-utils.d.ts +4 -0
  19. package/dist/stack-horizontal-utils.js +29 -0
  20. package/dist/ui/catalog.d.ts +1 -0
  21. package/dist/ui/catalog.js +1 -1
  22. package/dist/ui/stack.d.ts +1 -0
  23. package/dist/ui/stack.js +8 -0
  24. package/llms.txt +2 -1
  25. package/package.json +1 -1
  26. package/src/constants.ts +2 -1
  27. package/src/react/components/cell-grid.tsx +17 -24
  28. package/src/react/components/image.tsx +8 -1
  29. package/src/react/components/stack.tsx +84 -11
  30. package/src/react/components/text.tsx +8 -1
  31. package/src/react/stack-direction-context.tsx +27 -0
  32. package/src/react-native/components/snap-cell-grid.tsx +5 -11
  33. package/src/react-native/components/snap-image.tsx +17 -2
  34. package/src/react-native/components/snap-item.tsx +14 -2
  35. package/src/react-native/components/snap-progress.tsx +8 -2
  36. package/src/react-native/components/snap-stack.tsx +116 -14
  37. package/src/react-native/components/snap-text.tsx +7 -2
  38. package/src/react-native/stack-direction-context.tsx +25 -0
  39. package/src/stack-horizontal-utils.ts +27 -0
  40. package/src/ui/catalog.ts +1 -1
  41. package/src/ui/stack.ts +8 -0
@@ -0,0 +1,27 @@
1
+ import { Children, isValidElement, type ReactNode } from "react";
2
+
3
+ /**
4
+ * True when every rendered child comes from a catalog `button` element.
5
+ * json-render passes `{ element: { type, props, ... } }` into each catalog component.
6
+ */
7
+ function isRenderableChild(c: ReactNode): boolean {
8
+ if (c == null) return false;
9
+ if (typeof c === "boolean") return false;
10
+ return true;
11
+ }
12
+
13
+ export function horizontalChildrenAreAllButtons(children: ReactNode): boolean {
14
+ const items = Children.toArray(children).filter(isRenderableChild);
15
+ if (items.length === 0) return false;
16
+ for (const child of items) {
17
+ if (!isValidElement(child)) return false;
18
+ const typ = (child.props as { element?: { type?: unknown } }).element?.type;
19
+ if (typ !== "button") return false;
20
+ }
21
+ return true;
22
+ }
23
+
24
+ /** Direct snap catalog children under a stack (used for all-button grid column count). */
25
+ export function countRenderableChildren(children: ReactNode): number {
26
+ return Children.toArray(children).filter(isRenderableChild).length;
27
+ }
package/src/ui/catalog.ts CHANGED
@@ -92,7 +92,7 @@ export const snapJsonRenderCatalog = defineCatalog(snapJsonRenderSchema, {
92
92
  stack: {
93
93
  props: stackProps,
94
94
  description:
95
- "Layout container — direction: vertical (default) | horizontal. Children are element ids in order.",
95
+ "Layout container — direction: vertical (default) | horizontal. Children are element ids in order. Horizontal stacks use a single flex row so peers stay side-by-side and shrink with min-width 0. Nested stacks participate as flexible row peers. All-button horizontal stacks use an equal N-column grid where N is the number of buttons (1–6). Optional `columns` (`2`–`6`) forces an explicit equal grid for mixed children.",
96
96
  },
97
97
  text: {
98
98
  props: textProps,
package/src/ui/stack.ts CHANGED
@@ -8,6 +8,14 @@ export const stackProps = z.object({
8
8
  direction: z.enum(STACK_DIRECTIONS).optional(),
9
9
  gap: z.enum(STACK_GAPS).optional(),
10
10
  justify: z.enum(STACK_JUSTIFY).optional(),
11
+ /** Horizontal stacks only: fixed column grid (`2`–`6`). Prefer omitting this when children are stacks — they flex as row peers automatically. */
12
+ columns: z.union([
13
+ z.literal(2),
14
+ z.literal(3),
15
+ z.literal(4),
16
+ z.literal(5),
17
+ z.literal(6),
18
+ ]).optional(),
11
19
  });
12
20
 
13
21
  export type StackProps = z.infer<typeof stackProps>;