pejay-ui 1.2.1 → 1.3.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.
Files changed (61) hide show
  1. package/bin/cli.js +2 -2
  2. package/package.json +1 -1
  3. package/registry.json +39 -3
  4. package/templates/notes/create-pejay.md +222 -0
  5. package/templates/notes/notes-v1.md +516 -0
  6. package/templates/notes/notes-v2.md +764 -0
  7. package/templates/notes/notes-v3.md +574 -0
  8. package/templates/notes/notes-v4.md +811 -0
  9. package/templates/notes/notes-v5.md +579 -0
  10. package/templates/notes/notes-vf+1.md +311 -0
  11. package/templates/notes/notes-vfinal.md +852 -0
  12. package/templates/scaffolds/axios/api/index.ts +40 -0
  13. package/templates/scaffolds/axios/api/one.api.ts +94 -0
  14. package/templates/scaffolds/axios/endpoints.ts +9 -0
  15. package/templates/scaffolds/axios/index.ts +26 -0
  16. package/templates/scaffolds/axios/interceptors.ts +103 -0
  17. package/templates/scaffolds/axios/request.ts +32 -0
  18. package/templates/scaffolds/react-router/hook/useRouterSearch.ts +8 -0
  19. package/templates/scaffolds/react-router/router/guards/private.route.tsx +1 -0
  20. package/templates/scaffolds/react-router/router/index.ts +26 -0
  21. package/templates/scaffolds/react-router/router/layouts/error.layout.tsx +1 -1
  22. package/templates/scaffolds/redux-store/middlewares.ts +0 -0
  23. package/templates/scaffolds/redux-store/reducers.ts +30 -0
  24. package/templates/scaffolds/redux-store/selector/one.selector.ts +43 -0
  25. package/templates/scaffolds/redux-store/selector/two.selector.ts +11 -0
  26. package/templates/scaffolds/redux-store/slices/one.slice.ts +202 -0
  27. package/templates/scaffolds/redux-store/slices/two.slice.ts +21 -0
  28. package/templates/scaffolds/redux-store/store.ts +38 -0
  29. package/templates/scaffolds/rtk-query/baseApi.ts +24 -0
  30. package/templates/scaffolds/rtk-query/baseQuery.ts +12 -0
  31. package/templates/scaffolds/rtk-query/endpoints/api.one.ts +82 -0
  32. package/templates/scaffolds/rtk-query/endpoints/index.ts +1 -0
  33. package/templates/scaffolds/rtk-query/middlewares.ts +11 -0
  34. package/templates/scaffolds/rtk-query/queryTags.ts +13 -0
  35. package/templates/scaffolds/tanstack-query/api-base.ts +68 -68
  36. package/templates/scaffolds/tanstack-query/api-queries.ts +0 -19
  37. package/templates/scaffolds/tanstack-query/client.ts +8 -0
  38. package/templates/scaffolds/tanstack-query/module/index.ts +12 -12
  39. package/templates/scaffolds/tanstack-query/module/keys.ts +17 -17
  40. package/templates/scaffolds/tanstack-query/module/mappers.ts +15 -15
  41. package/templates/scaffolds/tanstack-query/module/mutations.ts +59 -55
  42. package/templates/scaffolds/tanstack-query/module/queries.ts +145 -156
  43. package/templates/scaffolds/tanstack-query/module/services.ts +74 -66
  44. package/templates/scaffolds/tanstack-router/layout/404.layout.tsx +3 -0
  45. package/templates/scaffolds/tanstack-router/layout/app.layout.tsx +10 -0
  46. package/templates/scaffolds/tanstack-router/layout/auth.layout.tsx +10 -0
  47. package/templates/scaffolds/tanstack-router/layout/error.layout.tsx +3 -0
  48. package/templates/scaffolds/tanstack-router/page/auth/login.tsx +3 -0
  49. package/templates/scaffolds/tanstack-router/page/one/index.tsx +3 -0
  50. package/templates/scaffolds/tanstack-router/page/one/one-id.tsx +128 -0
  51. package/templates/scaffolds/tanstack-router/router.ts +90 -0
  52. package/templates/scaffolds/tanstack-router/routes/_404.tsx +0 -0
  53. package/templates/scaffolds/tanstack-router/routes/__root.tsx +9 -0
  54. package/templates/scaffolds/tanstack-router/routes/_app.tsx +6 -0
  55. package/templates/scaffolds/tanstack-router/routes/_auth.tsx +6 -0
  56. package/templates/scaffolds/tanstack-router/routes/_error.tsx +0 -0
  57. package/templates/scaffolds/tanstack-router/routes/auth/login.tsx +6 -0
  58. package/templates/scaffolds/tanstack-router/routes/one/$id.tsx +191 -0
  59. package/templates/scaffolds/tanstack-router/routes/one/index.tsx +6 -0
  60. package/templates/scripts/setup.bat +284 -0
  61. package/templates/scripts/setup.ps1 +318 -0
@@ -0,0 +1,3 @@
1
+ export default function One() {
2
+ return <>This is One page</>;
3
+ }
@@ -0,0 +1,128 @@
1
+ import { Route } from "../../routes/one/$id";
2
+
3
+ export default function OneId() {
4
+ const { id } = Route.useParams();
5
+
6
+ /*
7
+ when using query
8
+ const { data } = useSuspenseQuery(
9
+ apiQueries.module.fetch_query_by_id_example(id)
10
+ );
11
+
12
+ if you are mot using loader
13
+ loader: async ({ context, params }) => {
14
+ await context.queryClient.ensureQueryData(
15
+ apiQueries.module.fetch_query_by_id_example({id:params.id})
16
+ );
17
+ },
18
+
19
+ like this then use
20
+ useQuery insted of useSuspenseQuery
21
+
22
+ also for small crud you should use useQuery insted of loader and useSuspenseQuery
23
+
24
+ For important pages where you want data loaded before render (details page, edit page, dashboard, etc.), add a loader with ensureQueryData.
25
+
26
+
27
+ --------------------------------------------------------------------------------
28
+
29
+
30
+ const searchParams = Route.useSearch();
31
+
32
+ const { data } = useSuspenseQuery(
33
+ apiQueries.module.fetch_query_by_id_example({
34
+ id,
35
+ search: searchParams.search,
36
+ type: searchParams.type,
37
+ })
38
+ );
39
+
40
+
41
+
42
+ Input Change
43
+
44
+ Local State
45
+
46
+ Click Filter
47
+
48
+ navigate({ search })
49
+
50
+ URL Updates
51
+
52
+ Route.useSearch() Updates
53
+
54
+ Query Key Changes
55
+
56
+ Backend Call
57
+
58
+
59
+ and on final filter tn we just
60
+ navigate({
61
+ search: {
62
+ search: "john",
63
+ type: "active",
64
+ },
65
+ });
66
+
67
+ use navigate
68
+ -----------------------------
69
+
70
+ and this wont
71
+ ❌ Browser Refresh
72
+ ❌ Full Page Reload
73
+ ❌ Re-download JS Bundle
74
+
75
+ but insted
76
+
77
+ ---------------------
78
+ URL changes
79
+
80
+ Router state changes
81
+
82
+ Affected components re-render
83
+
84
+ ---------------------
85
+ What Actually Re-renders?
86
+ Suppose:
87
+ AppLayout
88
+
89
+ ├── Header
90
+ ├── Sidebar
91
+ └── Outlet
92
+ └── OnePage
93
+ └── DataTable
94
+
95
+ When search params change:
96
+ AppLayout ❌ stays mounted
97
+ Header ❌ stays mounted
98
+ Sidebar ❌ stays mounted
99
+
100
+ OnePage 🔄 re-render
101
+ DataTable 🔄 re-render
102
+
103
+
104
+ because:
105
+ const search = Route.useSearch();
106
+
107
+ -------------------------------
108
+ TanStack Router Flow
109
+
110
+ Input Change
111
+
112
+ Local State
113
+
114
+ Click Filter
115
+
116
+ navigate({ search })
117
+
118
+ URL Updates
119
+
120
+ Route.useSearch() Updates
121
+
122
+ Query Key Changes
123
+
124
+ Backend Call
125
+
126
+ */
127
+ return <>This is One ID page {id}</>;
128
+ }
@@ -0,0 +1,90 @@
1
+ import { createRouter } from "@tanstack/react-router";
2
+ /* import { routeTree } from "./routeTree.gen"; */
3
+ // routeTree file was automatically generated by TanStack Router.
4
+
5
+ export function getRouter() {
6
+ const router = createRouter({
7
+ /*routeTree,*/
8
+ scrollRestoration: true,
9
+ defaultPreload: "intent",
10
+ /* defaultPreloadStaleTime: 0, */
11
+
12
+ /*
13
+ context: {
14
+ queryClient: undefined!,
15
+ },
16
+ */
17
+ });
18
+
19
+ return router;
20
+ }
21
+
22
+ /*
23
+
24
+ in app
25
+
26
+ <RouterProvider
27
+ router={router}
28
+ context={{
29
+ queryClient,
30
+ }}
31
+ />
32
+
33
+ This queryClient in router context is the piece that connects TanStack Router loaders to your existing apiQueries setup.
34
+
35
+
36
+ | Option | What it does |
37
+ | ---------------------------- | ---------------------------------------------------------------------------------------- |
38
+ | `scrollRestoration: true` | Restores previous scroll position when navigating back/forward |
39
+ | `defaultPreload: "intent"` | Preloads route when user hovers or focuses a link |
40
+ | `defaultPreloadStaleTime: 0` | Preloaded data becomes stale immediately; often used when TanStack Query manages caching |
41
+
42
+
43
+
44
+
45
+ # What You Should Learn First
46
+
47
+ ## Must know
48
+
49
+ ✅ `context`
50
+
51
+ ✅ `scrollRestoration`
52
+
53
+ ✅ `defaultPreload`
54
+
55
+ ✅ `defaultPreloadStaleTime`
56
+
57
+ ✅ `defaultNotFoundComponent`
58
+
59
+ ---
60
+
61
+ ## Learn later
62
+
63
+ ✅ `defaultPendingComponent`
64
+
65
+ ✅ `defaultErrorComponent`
66
+
67
+ ---
68
+
69
+ ## Advanced
70
+
71
+ ✅ `basepath`
72
+
73
+ ✅ `defaultViewTransition`
74
+
75
+ ✅ `routeMasks`
76
+
77
+ ✅ `defaultStructuralSharing`
78
+
79
+ ---
80
+
81
+ If you're building a React + TanStack Query app, the most valuable next topic after routing basics is actually **router context + `beforeLoad` guards**. That's where authentication, permissions, and route protection become really powerful.
82
+
83
+
84
+ */
85
+
86
+ declare module "@tanstack/react-router" {
87
+ interface Register {
88
+ router: ReturnType<typeof getRouter>;
89
+ }
90
+ }
@@ -0,0 +1,9 @@
1
+ import { createFileRoute, Outlet } from "@tanstack/react-router";
2
+ import ErrorLayout from "../layout/error.layout";
3
+ import PageNotFound from "../layout/404.layout";
4
+
5
+ export const Route = createFileRoute("__root")({
6
+ component: Outlet,
7
+ errorComponent: ErrorLayout,
8
+ notFoundComponent: PageNotFound,
9
+ });
@@ -0,0 +1,6 @@
1
+ import { createFileRoute, Outlet } from "@tanstack/react-router";
2
+ import AppLayout from "../layout/app.layout";
3
+
4
+ export const Route = createFileRoute("/_app")({
5
+ component: AppLayout,
6
+ });
@@ -0,0 +1,6 @@
1
+ import { createFileRoute, Outlet } from "@tanstack/react-router";
2
+ import AuthLayout from "../layout/auth.layout";
3
+
4
+ export const Route = createFileRoute("/_auth")({
5
+ component: AuthLayout,
6
+ });
@@ -0,0 +1,6 @@
1
+ import { createFileRoute } from "@tanstack/react-router";
2
+ import Login from "../../page/auth/login";
3
+
4
+ export const Route = createFileRoute("/_auth/login")({
5
+ component: Login,
6
+ });
@@ -0,0 +1,191 @@
1
+ import { createFileRoute } from "@tanstack/react-router";
2
+ import OneId from "../../page/one/one-id";
3
+
4
+ export const Route = createFileRoute("/_app/one/$id")({
5
+ loader: async ({ params }:{params:any}) => {
6
+ console.log("Fetching id");
7
+ return { id: params.id };
8
+ },
9
+ validateSearch: (search) => ({
10
+ search: typeof search.search === "string" ? search.search : "",
11
+ type: typeof search.type === "string" ? search.type : "",
12
+ }),
13
+ pendingComponent: () => <div>Loading...</div>,
14
+ component: OneId,
15
+ });
16
+
17
+ /*
18
+
19
+ pendingComponent: () => <div>Loading...</div>,
20
+ component: OneId,
21
+ show keleton here for useSuspense
22
+
23
+ when using with tanstack Q
24
+
25
+ loader: async ({ context, params }) => {
26
+ await context.queryClient.ensureQueryData(
27
+ apiQueries.module.fetch_query_by_id_example({id:params.id})
28
+ );
29
+ },
30
+
31
+ why ?
32
+
33
+ Route Match
34
+
35
+ params.id = "123"
36
+
37
+ loader
38
+
39
+ ensureQueryData(query)
40
+
41
+ API Call
42
+
43
+ Query Cache Filled
44
+
45
+ Component Mounts
46
+
47
+ useQuery(query)
48
+
49
+ Gets data from cache
50
+
51
+
52
+
53
+
54
+ ---------------------------------------------------------------------------
55
+
56
+ code splitting vs auto code splitting
57
+
58
+
59
+ this code below is manual splitting
60
+
61
+ import { lazy, Suspense } from "react";
62
+
63
+ const HistoryDrawer = lazy(
64
+ () => import("./HistoryDrawer")
65
+ );
66
+
67
+ export default function OnePage() {
68
+ return (
69
+ <Suspense fallback={<DrawerSkeleton />}>
70
+ <HistoryDrawer />
71
+ </Suspense>
72
+ );
73
+ }
74
+
75
+
76
+
77
+ in router file i can do same by using laxy in mu component key
78
+ like i have done in react router
79
+ thats called manual code splitting
80
+ in react router we have to do it that way because no auto code splitting in react router (but comp level code splitting is same for both)
81
+
82
+ now in tanstack router we have auto code splitting so we can do like this
83
+
84
+ in file vite.config.ts
85
+ import { defineConfig } from 'vite'
86
+ import { tanstackRouter } from '@tanstack/router-plugin/vite'
87
+
88
+ export default defineConfig({
89
+ plugins: [
90
+ tanstackRouter({
91
+ autoCodeSplitting: true, // Enable automatic code splitting
92
+ }),
93
+ ],
94
+ })
95
+
96
+ just do this and all the existing file route defined in routes folder will be auto code split
97
+ and for component level we need manual
98
+
99
+ iy works with any component
100
+
101
+ what the benifit of code splitting
102
+ when i hits the end point it will not download all the code and comp
103
+ it will download only the code and comp for that route
104
+ so it will be fast
105
+
106
+ in build process it create diff files for each route
107
+
108
+ like chunk-0a1b2c.js
109
+ chunk-3d4e5f.js
110
+ chunk-6g7h8i.js
111
+ chunk-9j0k1l.js
112
+
113
+
114
+ Without code splitting, the bundler (Vite/Webpack/Rollup) might produce something like:
115
+
116
+ dist/
117
+ ├── main.js (2 MB)
118
+ ├── styles.css
119
+ └── index.html
120
+
121
+ Download main.js
122
+
123
+ Contains:
124
+ - Dashboard
125
+ - Users
126
+ - Patients
127
+ - Reports
128
+ - Settings
129
+ - Modals
130
+ - Drawers
131
+ - Charts
132
+ - Editors
133
+
134
+ With code splitting:
135
+
136
+ dist/
137
+ ├── main.js
138
+ ├── dashboard.chunk.js
139
+ ├── patients.chunk.js
140
+ ├── reports.chunk.js
141
+ ├── settings.chunk.js
142
+ ├── history-drawer.chunk.js
143
+ └── editor.chunk.js
144
+
145
+ Open App
146
+
147
+ Download main.js
148
+
149
+ Navigate to /users/123
150
+
151
+ Download users.chunk.js
152
+
153
+ Download dashboard.chunk.js
154
+
155
+
156
+ Navigate to /patients/456
157
+
158
+ Download patients.chunk.js
159
+
160
+
161
+ Without Splitting
162
+
163
+ 1 Big Truck
164
+ ┌──────────────────┐
165
+ │ Everything │
166
+ │ Dashboard │
167
+ │ Patients │
168
+ │ Reports │
169
+ │ Modals │
170
+ │ Drawers │
171
+ │ Charts │
172
+ └──────────────────┘
173
+
174
+ Truck 1 -> Core App
175
+ Truck 2 -> Patients
176
+ Truck 3 -> Reports
177
+ Truck 4 -> Drawer
178
+ Truck 5 -> Editor
179
+
180
+ what improves
181
+ Initial load speed
182
+ Time to interactive
183
+ Mobile performance
184
+ Bundle size
185
+
186
+ */
187
+
188
+
189
+
190
+
191
+
@@ -0,0 +1,6 @@
1
+ import { createFileRoute } from "@tanstack/react-router";
2
+ import One from "../../page/one";
3
+
4
+ export const Route = createFileRoute("/_app/one")({
5
+ component: One,
6
+ });