singularity-core 0.5.2 → 0.6.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.
@@ -0,0 +1,22 @@
1
+ import { type StaticDataRouteOption } from "@tanstack/react-router";
2
+ /**
3
+ * `staticData[key]` of the deepest matched route that sets it, so a layout
4
+ * route can act on what the page under it declares. The apps use it for the
5
+ * page shell: each route sets `staticData: { page: { width, flush } }` and
6
+ * the layout passes `useDeepestStaticData("page")` to its `GenericPage`.
7
+ *
8
+ * The key is typed by the app, which adds it to TanStack Router's
9
+ * `StaticDataRouteOption`:
10
+ *
11
+ * ```ts
12
+ * declare module "@tanstack/react-router" {
13
+ * interface StaticDataRouteOption {
14
+ * page?: PageShell;
15
+ * }
16
+ * }
17
+ * ```
18
+ *
19
+ * Static data is fixed per route. A value that depends on params or loader
20
+ * data (a breadcrumb with a post title) belongs in the loader or context.
21
+ */
22
+ export declare function useDeepestStaticData<K extends keyof StaticDataRouteOption>(key: K): StaticDataRouteOption[K] | undefined;
@@ -0,0 +1,30 @@
1
+ import { useMatches } from "@tanstack/react-router";
2
+ import { deepestStaticData } from "./static-data.js";
3
+ /**
4
+ * `staticData[key]` of the deepest matched route that sets it, so a layout
5
+ * route can act on what the page under it declares. The apps use it for the
6
+ * page shell: each route sets `staticData: { page: { width, flush } }` and
7
+ * the layout passes `useDeepestStaticData("page")` to its `GenericPage`.
8
+ *
9
+ * The key is typed by the app, which adds it to TanStack Router's
10
+ * `StaticDataRouteOption`:
11
+ *
12
+ * ```ts
13
+ * declare module "@tanstack/react-router" {
14
+ * interface StaticDataRouteOption {
15
+ * page?: PageShell;
16
+ * }
17
+ * }
18
+ * ```
19
+ *
20
+ * Static data is fixed per route. A value that depends on params or loader
21
+ * data (a breadcrumb with a post title) belongs in the loader or context.
22
+ */
23
+ export function useDeepestStaticData(key) {
24
+ // `useMatches` types its result with a conditional on the selected type,
25
+ // which stays unresolved while `K` is generic. The value is what `select`
26
+ // returns, so the cast only restates it.
27
+ return useMatches({
28
+ select: (matches) => deepestStaticData(matches, key),
29
+ });
30
+ }
@@ -0,0 +1,12 @@
1
+ import type { StaticDataRouteOption } from "@tanstack/react-router";
2
+ /** A route match, as far as its static data goes. */
3
+ type MatchWithStaticData = {
4
+ staticData: StaticDataRouteOption;
5
+ };
6
+ /**
7
+ * `staticData[key]` of the deepest match that sets it, or `undefined`.
8
+ * Matches run from the root route to the leaf, so a page's value wins over
9
+ * its layout's, and a layout's over the root's.
10
+ */
11
+ export declare function deepestStaticData<K extends keyof StaticDataRouteOption>(matches: readonly MatchWithStaticData[], key: K): StaticDataRouteOption[K] | undefined;
12
+ export {};
@@ -0,0 +1,14 @@
1
+ /**
2
+ * `staticData[key]` of the deepest match that sets it, or `undefined`.
3
+ * Matches run from the root route to the leaf, so a page's value wins over
4
+ * its layout's, and a layout's over the root's.
5
+ */
6
+ export function deepestStaticData(matches, key) {
7
+ for (let i = matches.length - 1; i >= 0; i--) {
8
+ const value = matches[i]?.staticData[key];
9
+ if (value !== undefined) {
10
+ return value;
11
+ }
12
+ }
13
+ return undefined;
14
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "singularity-core",
3
- "version": "0.5.2",
4
- "description": "Shared non-UI code for Singularity TanStack Start apps: auth sessions, API client middleware, API schemas, paging, images, formatting, theme, SEO, security headers and telemetry.",
3
+ "version": "0.6.0",
4
+ "description": "Shared non-UI code for Singularity TanStack Start apps: auth sessions, API client middleware, API schemas, paging, route data, images, formatting, theme, SEO, security headers and telemetry.",
5
5
  "type": "module",
6
6
  "author": "Filip",
7
7
  "license": "MIT",
@@ -9,6 +9,7 @@
9
9
  "dist"
10
10
  ],
11
11
  "sideEffects": false,
12
+ "packageManager": "pnpm@12.3.4",
12
13
  "engines": {
13
14
  "node": ">=25.0.0 <26.0.0",
14
15
  "pnpm": ">=12.0.0 <13.0.0"
@@ -38,6 +39,10 @@
38
39
  "types": "./dist/paging/react.d.ts",
39
40
  "import": "./dist/paging/react.js"
40
41
  },
42
+ "./router/react": {
43
+ "types": "./dist/router/react.d.ts",
44
+ "import": "./dist/router/react.js"
45
+ },
41
46
  "./theme": {
42
47
  "types": "./dist/theme/index.d.ts",
43
48
  "import": "./dist/theme/index.js"
@@ -79,7 +84,19 @@
79
84
  "import": "./dist/http/index.js"
80
85
  }
81
86
  },
87
+ "scripts": {
88
+ "build": "tsc -p tsconfig.build.json",
89
+ "typecheck": "tsc --noEmit",
90
+ "test": "vitest run",
91
+ "test:watch": "vitest",
92
+ "openapi-dev-types": "openapi-typescript http://localhost:5268/swagger/v1/swagger.json -o ./src/api/v1.ts --alphabetize --default-non-nullable --enum-values",
93
+ "prepack": "pnpm build",
94
+ "biome:check": "biome check --write",
95
+ "biome:lint": "biome lint --fix",
96
+ "biome:format": "biome format --write"
97
+ },
82
98
  "peerDependencies": {
99
+ "@tanstack/react-router": "^1.170.0",
83
100
  "@tanstack/react-start": "^1.168.0",
84
101
  "jose": "^6.0.0",
85
102
  "openapi-fetch": "^0.17.0",
@@ -87,6 +104,9 @@
87
104
  "zod": "^4.0.0"
88
105
  },
89
106
  "peerDependenciesMeta": {
107
+ "@tanstack/react-router": {
108
+ "optional": true
109
+ },
90
110
  "@tanstack/react-start": {
91
111
  "optional": true
92
112
  },
@@ -102,6 +122,7 @@
102
122
  },
103
123
  "devDependencies": {
104
124
  "@biomejs/biome": "2.5.15",
125
+ "@tanstack/react-router": "1.170.42",
105
126
  "@tanstack/react-start": "1.168.61",
106
127
  "@types/node": "25.9.5",
107
128
  "@types/react": "19.3.0",
@@ -109,18 +130,9 @@
109
130
  "openapi-fetch": "0.17.0",
110
131
  "openapi-typescript": "7.13.0",
111
132
  "react": "19.3.0",
133
+ "react-dom": "19.3.0",
112
134
  "typescript": "6.0.3",
113
135
  "vitest": "5.0.3",
114
136
  "zod": "4.6.5"
115
- },
116
- "scripts": {
117
- "build": "tsc -p tsconfig.build.json",
118
- "typecheck": "tsc --noEmit",
119
- "test": "vitest run",
120
- "test:watch": "vitest",
121
- "openapi-dev-types": "openapi-typescript http://localhost:5268/swagger/v1/swagger.json -o ./src/api/v1.ts --alphabetize --default-non-nullable --enum-values",
122
- "biome:check": "biome check --write",
123
- "biome:lint": "biome lint --fix",
124
- "biome:format": "biome format --write"
125
137
  }
126
- }
138
+ }