Skip to content

Commit 60e5afe

Browse files
authored
feat: Export everything under a single module name (#176)
1 parent 2fb397d commit 60e5afe

14 files changed

Lines changed: 13881 additions & 13828 deletions

File tree

package-lock.json

Lines changed: 13764 additions & 13769 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

playground/src/App.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
RouterTrace,
1010
Redirector,
1111
location,
12-
buildHref
12+
buildHref,
13+
calculateHref,
14+
calculateState
1315
} from '@svelte-router/core';
14-
import { calculateHref, calculateState } from '@svelte-router/core/kernel';
1516
import NotFound from './lib/NotFound.svelte';
1617
import HomeView from './lib/views/home/HomeView.svelte';
1718
import PathRoutingView from './lib/views/path-routing/PathRoutingView.svelte';

src/lib/index.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,19 @@ describe('index', () => {
2121
'activeBehavior',
2222
'Redirector',
2323
'buildHref',
24-
'joinPaths'
24+
'joinPaths',
25+
'RouterEngine',
26+
'isConformantState',
27+
'calculateHref',
28+
'calculateState',
29+
'initCore',
30+
'LocationState',
31+
'StockHistoryApi',
32+
'InterceptedHistoryApi',
33+
'LocationLite',
34+
'LocationFull',
35+
'preserveQueryInUrl',
36+
'calculateMultiHashFragment'
2537
];
2638

2739
// Act.

src/lib/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,15 @@ export * from './public-utils.js';
1616
export * from './behaviors/active.svelte.js';
1717
export { Redirector } from './Redirector.svelte.js';
1818
export { buildHref } from './buildHref.js';
19+
export { RouterEngine } from './kernel/RouterEngine.svelte.js';
20+
export { isConformantState } from './kernel/isConformantState.js';
21+
export { calculateHref } from './kernel/calculateHref.js';
22+
export { calculateMultiHashFragment } from './kernel/calculateMultiHashFragment.js';
23+
export { calculateState } from './kernel/calculateState.js';
24+
export { initCore } from './kernel/initCore.js';
25+
export { LocationState } from './kernel/LocationState.svelte.js';
26+
export { StockHistoryApi } from './kernel/StockHistoryApi.svelte.js';
27+
export { InterceptedHistoryApi } from './kernel/InterceptedHistoryApi.svelte.js';
28+
export { LocationLite } from './kernel/LocationLite.svelte.js';
29+
export { LocationFull } from './kernel/LocationFull.js';
30+
export { preserveQueryInUrl } from './kernel/preserveQuery.js';

src/routes/api/core/functions/+page.md

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
title: Functions
33
description: Complete API reference for utility functions in Svelte Router including navigation, HREF building, and active behaviors
44
---
5+
:::caution[Don't Import from @svelte-router/core/kernel]
6+
The sub-module `@svelte-router/core/kernel` has been deprecated as of **v1.0.4**. While it is still possible to use it, it must not be used. **It will be removed in v2.0 without fail**.
57

6-
## `activeBehavior`
8+
This change responds to the fact that sometimes, in micro-frontend scenarios, people will externalize the routing library. To avoid headaches regarding different module names, the submodule is now completely discouraged.
9+
:::
710

8-
Import from: `@svelte-router/core`
11+
## `activeBehavior`
912

1013
`activeBehavior(rsOrRouter: Record<string, RouteStatus> | RouterEngine | null | undefined, activeState: ActiveState & { key: string }, baseStyle: string = '', ): Attachment<HTMLElement>`
1114

@@ -15,8 +18,6 @@ This functionality is built-in in the `Link` component, but sometimes and depend
1518

1619
## `buildHref`
1720

18-
Import from: `@svelte-router/core`
19-
2021
`buildHref(pathPiece: string, hashPiece: string, options?: BuildHrefOptions): string`
2122

2223
This is a utility function whose primary objective is help in cross-universe redirection scenarios where one of the universes is the path routing universe.
@@ -27,8 +28,6 @@ It takes an optional third argument with options. Currently, only the `preserveQ
2728

2829
## `calculateHref`
2930

30-
Import from: `@svelte-router/core/kernel`
31-
3231
`calculateHref(...hrefs: (string | undefined)[]): string`
3332

3433
`calculateHref(options: CalculateHrefOptions, ...hrefs: (string | undefined)[]): string`
@@ -61,8 +60,6 @@ Option to preserve the current hash by copying it from the location’s URL to t
6160

6261
## `calculateMultiHashFragment`
6362

64-
Import from: `@svelte-router/core/kernel`
65-
6663
`calculateMultiHashFragment(hashPaths: Record<string, string>): string`
6764

6865
Calculates a hash fragment that preserves all currently-existing named hash paths, plus it modifies/adds/removes the named hash paths enumerated in its only argument.
@@ -71,8 +68,6 @@ Specify new named hash paths or modify existing ones by passing a POJO object wi
7168

7269
## `calculateState`
7370

74-
Import from: `@svelte-router/core/kernel`
75-
7671
`calculateState(state: any): State`
7772

7873
`calculateState(hash: Hash, state: any): State`
@@ -83,16 +78,12 @@ Use this function when not depending on the `Link` component or `location.naviga
8378

8479
## `getRouterContext`
8580

86-
Import from: `@svelte-router/core`
87-
8881
`getRouterContext(hash: boolean | string): RouterEngine | undefined`
8982

9083
Obtains the closest router context in the component hierarchy. The returned value will be for the specific universe the hash value represents.
9184

9285
## `init`
9386

94-
Import from: `@svelte-router/core`
95-
9687
`init(options?: InitOptions): () => void`
9788

9889
Initializes the library by creating the global `location` object with standard capabilities and setting the desired options.
@@ -123,16 +114,12 @@ Turns router hierarchy tracking on. Its default value is `false`, and `RouterTra
123114
Only used by extension packages. Read the [Creating an Extension Package](/docs/creating-an-extension-package) document in this guide for details.
124115
:::
125116

126-
Import from: `@svelte-router/core/kernel`
127-
128117
`initCore(location: Location, options?: ExtendedInitOptions): () => void`
129118

130119
This function initializes the library, allowing the caller to pass a custom implementation of the `Location` interface.
131120

132121
## `initFull`
133122

134-
Import from: `@svelte-router/core`
135-
136123
`initFull(options?: InitOptions): () => void`
137124

138125
Initializes the library by creating the global location with full capabilities object and setting the desired options.
@@ -141,40 +128,30 @@ Refer to the [init](#init) function for details on the accepted properties.
141128

142129
## `IsConformantState`
143130

144-
Import from: `@svelte-router/core/kernel`
145-
146131
`function isConformantState(state: unknown): state is State`
147132

148133
Tests the given state data to see if it conforms to the expected `State` structure.
149134

150135
## `isRouteActive`
151136

152-
Import from: `@svelte-router/core`
153-
154137
`isRouteActive(rsOrRouter: RouterEngine | Record<string, RouteStatus> | null | undefined, key: string | null | undefined): boolean`
155138

156139
Returns a Boolean value that indicates if the route with the specified key is currently matching (is active) according to the provided router or route status data.
157140

158141
## `joinPaths`
159142

160-
Import from: `@svelte-router/core`
161-
162143
`joinPaths(...paths: string[]): string`
163144

164145
Joins any number of path segments into one, making sure slashes are not repeated.
165146

166147
## `preserveQueryInUrl`
167148

168-
Import from: `@svelte-router/core/kernel`
169-
170149
`preserveQueryInUrl(url: string, preserveQuery: PreserveQuery): string`
171150

172151
Function that can be used to preserve query string (search parameters) key/value pairs when building URL’s. While typically used by extension packages only, it could be used by users with very specific needs.
173152

174153
## `setRouterContext`
175154

176-
Import from: `@svelte-router/core/kernel`
177-
178155
`setRouterContext(router: RouterEngine, hash?: boolean | string): void`
179156

180157
Sets the router context for the specific universe the hash value represents.

src/routes/api/core/objects-and-classes/+page.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,27 @@
22
title: Objects & Classes
33
description: API reference for core objects, classes, and interfaces in Svelte Router including RouterEngine and Location
44
---
5+
:::caution[Don't Import from @svelte-router/core/kernel]
6+
The sub-module `@svelte-router/core/kernel` has been deprecated as of **v1.0.4**. While it is still possible to use it, it must not be used. **It will be removed in v2.0 without fail**.
7+
8+
This change responds to the fact that sometimes, in micro-frontend scenarios, people will externalize the routing library. To avoid headaches regarding different module names, the submodule is now completely discouraged.
9+
:::
510

611
## `InterceptedHistoryApi`
712

813
:::info[Usage]
914
Only used by extension packages. Read the [Creating an Extension Package](/docs/creating-an-extension-package) document in this guide for details.
1015
:::
1116

12-
Type: **Class**; Import from: `@svelte-router/core/kernel`
17+
Type: **Class**
1318

1419
This is the stock implementation of the `FullModeHistoryApi` interface, and the history manager used whenever the library runs in **full** mode.
1520

1621
It can also serve as a base class per the standard rules of the JavaScript language.
1722

1823
## `location`
1924

20-
Type: `Location`; Import from: `@svelte-router/core`, `@svelte-router/core/kernel`
25+
Type: `Location`
2126

2227
This is the global object that provides URL reactivity to all other library assets. This object is created by the library’s `init()` function, based on the options given to it.
2328

@@ -83,7 +88,7 @@ Only available in full library mode, allows subscription to the `beforeNavigate`
8388
Only used by extension packages. Read the [Creating an Extension Package](/docs/creating-an-extension-package) document in this guide for details.
8489
:::
8590

86-
Type: **Class**; Import from: `@svelte-router/core/kernel`
91+
Type: **Class**
8792

8893
This is the main stock implementation of the `Location` interface. Extension packages may use it when all the extension does is provide a custom implementation of the `HistoryApi` or `FullModeHistoryApi` interfaces. Using this class locks the library in **lite** mode.
8994

@@ -95,7 +100,7 @@ It can also serve as a base class per the standard rules of the JavaScript langu
95100
Only used by extension packages. Read the [Creating an Extension Package](/docs/creating-an-extension-package) document in this guide for details.
96101
:::
97102

98-
Type: **Class**; Import from: `@svelte-router/core/kernel`
103+
Type: **Class**
99104

100105
This is the stock implementation of the `Location` interface used when the library is initialized in **full** mode. Its constructor only accepts **FullModeHistoryApi** implementations. Use it in extension packages that don’t create custom **Location** implementations, but desire to provide a custom full mode experience by customizing the behavior of the backing environment History manager.
101106

@@ -107,7 +112,7 @@ It can also serve as a base class per the standard rules of the JavaScript langu
107112
Only used by extension packages. Read the [Creating an Extension Package](/docs/creating-an-extension-package) document in this guide for details.
108113
:::
109114

110-
Type: **Class**; Import from: `@svelte-router/core/kernel`
115+
Type: **Class**
111116

112117
This is a very simple class that merely initializes 2 public fields: The `url` field is initialized with a `SvelteURL` instance; the `state` field initializes with a state object that is conformant with the `State` data type.
113118

@@ -117,7 +122,7 @@ The class’ constructor currently accepts two optional parameters. The first on
117122

118123
## `Redirector`
119124

120-
Type: **Class**; Import from: `@svelte-router/core`
125+
Type: **Class**
121126

122127
Use this class inside components to enable automatic URL redirection. It is used to keep deprecated URL’s out of sight but still functional. It allows routing in the same routing universe as well as routing from one routing universe to another.
123128

@@ -129,7 +134,7 @@ Array used to register redirections. Redirections are objects that define the sh
129134

130135
## `RouterEngine`
131136

132-
Type: **Class**; Import from: `@svelte-router/core/kernel`
137+
Type: **Class**
133138

134139
This class powers all `Router` components and can be used directly. Note, however, that when directly used you’re the responsible for creating proper parent-child relationships between `RouterEngine` instances.
135140

@@ -213,7 +218,7 @@ You don’t need to dispose a `RouterEngine` instance that has been given to or
213218
Only used by extension packages. Read the [Creating an Extension Package](/docs/creating-an-extension-package) document in this guide for details.
214219
:::
215220

216-
Type: **Class**; Import from: `@svelte-router/core/kernel`
221+
Type: **Class**
217222

218223
This is the stock implementation of the `HistoryApi` interface. It is the default class used by the `LocationLite` class whenever the library runs in **lite** mode.
219224

src/routes/api/kit/functions/+page.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@ description: API reference for functions in the SvelteKit extension for Svelte R
55

66
## `init`
77

8-
Import from: `@svelte-router/kit`
9-
108
`(options?: KitInitOptions): () => void`
119

1210
Initializes the library. This is a must-do operation before any other functionality can be used.
1311

1412
## `kitCalculateHref`
1513

16-
Import from: `@svelte-router/kit`
17-
1814
`(options: KitCalculateHrefOptions, ...hrefs: string[]): string`
1915

2016
Helper function that combines multiple HREF's into a single HREF using `@svelte-router/core`'s `calculateHref` function **for the path routing universe**.

src/routes/docs/library-modes/+page.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ As stated above, this is the event to use if you would like the opportunity to e
134134

135135
```typescript
136136
import { location, type BeforeNavigateEvent } from '@svelte-router/core';
137-
import { isConformantState } from '@svelte-router/core/kernel';
137+
import { isConformantState } from '@svelte-router/core';
138138

139139
function cancelEventForSomeReason(event: BeforeNavigateEvent) {
140140
if (!isConformantState(event.state)) {

src/routes/docs/loc/+page.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,63 @@ The total count is also shown without `RouterTrace`, which is a non-production c
1111
For detailed information about changes between releases, see the project’s [Releases page](https://github.com/WJSoftware/svelte-router/releases).
1212
:::
1313

14+
## Version 1.0.4
15+
16+
Lines of Code: **1,934** (**1,560** without `RouterTrace`)
17+
18+
Command line: `cloc .\src\lib\ --exclude-dir=testing --exclude-ext=test.ts --exclude-lang=Markdown,SVG --strip-str-comments`
19+
20+
cloc version: **v2.07**
21+
22+
```plaintext
23+
-------------------------------------------------------------------------------
24+
Language files blank comment code
25+
-------------------------------------------------------------------------------
26+
TypeScript 29 152 949 1270
27+
Svelte 6 74 350 664
28+
-------------------------------------------------------------------------------
29+
SUM: 35 226 1299 1934
30+
-------------------------------------------------------------------------------
31+
```
32+
33+
## Version 1.0.3
34+
35+
Lines of Code: **1,922** (**1,548** without `RouterTrace`)
36+
37+
Command line: `cloc .\src\lib\ --exclude-dir=testing --exclude-ext=test.ts --exclude-lang=Markdown,SVG --strip-str-comments`
38+
39+
cloc version: **v2.07**
40+
41+
```plaintext
42+
-------------------------------------------------------------------------------
43+
Language files blank comment code
44+
-------------------------------------------------------------------------------
45+
TypeScript 29 152 949 1258
46+
Svelte 6 74 350 664
47+
-------------------------------------------------------------------------------
48+
SUM: 35 226 1299 1922
49+
-------------------------------------------------------------------------------
50+
```
51+
52+
## Version 1.0.2
53+
54+
Lines of Code: **1,760** (**1,388** without `RouterTrace`)
55+
56+
Command line: `cloc .\src\lib\ --exclude-dir=testing --exclude-ext=test.ts --exclude-lang=Markdown,SVG --strip-str-comments`
57+
58+
cloc version: **v2.07**
59+
60+
```plaintext
61+
-------------------------------------------------------------------------------
62+
Language files blank comment code
63+
-------------------------------------------------------------------------------
64+
TypeScript 29 155 949 1108
65+
Svelte 6 74 350 652
66+
-------------------------------------------------------------------------------
67+
SUM: 35 229 1299 1760
68+
-------------------------------------------------------------------------------
69+
```
70+
1471
## Version 1.0.1
1572

1673
Lines of Code: **1,760** (**1,388** without `RouterTrace`)
@@ -20,7 +77,6 @@ Command line: `cloc .\src\lib\ --exclude-dir=testing --exclude-ext=test.ts --exc
2077
cloc version: **v2.07**
2178

2279
```plaintext
23-
Copy
2480
-------------------------------------------------------------------------------
2581
Language files blank comment code
2682
-------------------------------------------------------------------------------

src/routes/docs/navigating-with-javascript/+page.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,12 @@ Usage of these functions is simple:
7575

7676
```typescript
7777
// Inside a component, for example:
78-
import { calculateHref, calculateState } from '@svelte-router/core/kernel';
79-
import { location, type Hash } from '@svelte-router/core';
78+
import {
79+
calculateHref,
80+
calculateState,
81+
location,
82+
type Hash
83+
} from '@svelte-router/core';
8084

8185
type Props = {
8286
keyProp: string;

0 commit comments

Comments
 (0)