create-fate 1.0.3 → 1.0.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-fate",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Create a new fate app.",
5
5
  "homepage": "https://github.com/nkzw-tech/fate",
6
6
  "license": "MIT",
@@ -3,7 +3,7 @@ import { useRouter, useShared } from '@void/react';
3
3
  import { ExternalLinkIcon } from 'lucide-react';
4
4
  import { useActionState, useEffect, useState } from 'react';
5
5
  import type { SharedData } from '../src/lib/shared.ts';
6
- import { Button } from '../src/ui/Button.tsx';
6
+ import { AsyncButton } from '../src/ui/Button.tsx';
7
7
  import Card from '../src/ui/Card.tsx';
8
8
  import H2 from '../src/ui/H2.tsx';
9
9
  import Input from '../src/ui/Input.tsx';
@@ -71,9 +71,9 @@ export default function LoginPage() {
71
71
  value={password}
72
72
  />
73
73
  <div>
74
- <Button type="submit" variant="outline">
74
+ <AsyncButton type="submit" variant="outline">
75
75
  Sign In
76
- </Button>
76
+ </AsyncButton>
77
77
  </div>
78
78
  </VStack>
79
79
  </Stack>
@@ -1,12 +1,6 @@
1
1
  import { Slot } from '@radix-ui/react-slot';
2
2
  import { cva, type VariantProps } from 'class-variance-authority';
3
- import {
4
- type ButtonHTMLAttributes,
5
- type MouseEvent,
6
- type ReactNode,
7
- useOptimistic,
8
- useTransition,
9
- } from 'react';
3
+ import { type ButtonHTMLAttributes, type ReactNode, useOptimistic, useTransition } from 'react';
10
4
  import { useFormStatus } from 'react-dom';
11
5
  import cx from '../lib/cx.tsx';
12
6
 
@@ -39,13 +33,41 @@ const buttonVariants = cva(
39
33
  const Button = ({
40
34
  action,
41
35
  asChild = false,
42
- children,
43
36
  className,
44
37
  disabled,
45
38
  onClick: initialOnClick,
39
+ size,
40
+ variant,
41
+ ...props
42
+ }: ButtonHTMLAttributes<HTMLButtonElement> &
43
+ VariantProps<typeof buttonVariants> & {
44
+ action?: () => void;
45
+ asChild?: boolean;
46
+ }) => {
47
+ const Component = asChild ? Slot : 'button';
48
+
49
+ const [isPending, startTransition] = useTransition();
50
+
51
+ const onClick = initialOnClick || (action ? () => startTransition(action) : undefined);
52
+
53
+ return (
54
+ <Component
55
+ className={cx(buttonVariants({ className, size, variant }))}
56
+ disabled={disabled !== undefined ? disabled : isPending}
57
+ onClick={onClick}
58
+ {...props}
59
+ />
60
+ );
61
+ };
62
+
63
+ const AsyncButton = ({
64
+ action,
65
+ asChild = false,
66
+ children,
67
+ className,
68
+ disabled,
46
69
  pendingPlaceholder = '...',
47
70
  size,
48
- type,
49
71
  variant,
50
72
  ...props
51
73
  }: ButtonHTMLAttributes<HTMLButtonElement> &
@@ -60,28 +82,22 @@ const Button = ({
60
82
  const [transitionIsPending, startTransition] = useTransition();
61
83
  const { pending: formIsPending } = useFormStatus();
62
84
 
63
- const onClick = (event: MouseEvent<HTMLButtonElement>) => {
64
- initialOnClick?.(event);
65
-
66
- if (!action || event.defaultPrevented) {
67
- return;
68
- }
69
-
70
- event.preventDefault();
71
- startTransition(async () => {
72
- setOptimisticIsPending(true);
73
- await action();
74
- });
75
- };
76
-
77
85
  const isPending = transitionIsPending || optimisticIsPending || formIsPending;
78
86
 
87
+ const onClick = action
88
+ ? () => {
89
+ startTransition(async () => {
90
+ setOptimisticIsPending(true);
91
+ await action();
92
+ });
93
+ }
94
+ : undefined;
95
+
79
96
  return (
80
97
  <Component
81
98
  className={cx(buttonVariants({ className, size, variant }))}
82
99
  disabled={disabled || isPending || undefined}
83
- onClick={initialOnClick || action ? onClick : undefined}
84
- type={type}
100
+ onClick={onClick}
85
101
  {...props}
86
102
  >
87
103
  {isPending ? pendingPlaceholder : children}
@@ -89,4 +105,4 @@ const Button = ({
89
105
  );
90
106
  };
91
107
 
92
- export { Button, buttonVariants };
108
+ export { AsyncButton, Button, buttonVariants };
@@ -9,29 +9,25 @@ import { voidPlugin } from 'void';
9
9
  const isTest = process.env.NODE_ENV === 'test' || process.env.VITEST;
10
10
 
11
11
  export default defineConfig({
12
+ optimizeDeps: {
13
+ exclude: ['@nkzw/fate/client', 'react-fate/client', 'void-fate/react'],
14
+ },
12
15
  environments: {
13
16
  void_worker: {
14
17
  optimizeDeps: {
15
- include: [
16
- '@nkzw/core/safeParse.js',
18
+ exclude: [
19
+ '@nkzw/fate/client',
20
+ '@nkzw/fate/server',
17
21
  '@nkzw/stack',
18
22
  '@radix-ui/react-slot',
19
23
  '@void/react',
20
24
  '@void/react/pages-server',
21
- 'better-auth',
22
- 'better-auth/adapters/drizzle',
23
- 'better-auth/plugins',
24
- 'class-variance-authority',
25
- 'clsx',
26
- 'drizzle-orm',
27
25
  'lucide-react',
28
- 'react',
29
26
  'react-error-boundary',
30
- 'react/jsx-dev-runtime',
31
- 'react/jsx-runtime',
32
- 'tailwind-merge',
33
- 'void/schema-d1',
34
- 'zod',
27
+ 'react-fate',
28
+ 'react-fate/client',
29
+ 'void-fate/react',
30
+ 'void-fate/server',
35
31
  ],
36
32
  },
37
33
  },