Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27,533 changes: 13,764 additions & 13,769 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions playground/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
RouterTrace,
Redirector,
location,
buildHref
buildHref,
calculateHref,
calculateState
} from '@svelte-router/core';
import { calculateHref, calculateState } from '@svelte-router/core/kernel';
import NotFound from './lib/NotFound.svelte';
import HomeView from './lib/views/home/HomeView.svelte';
import PathRoutingView from './lib/views/path-routing/PathRoutingView.svelte';
Expand Down
14 changes: 13 additions & 1 deletion src/lib/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,19 @@ describe('index', () => {
'activeBehavior',
'Redirector',
'buildHref',
'joinPaths'
'joinPaths',
'RouterEngine',
'isConformantState',
'calculateHref',
'calculateState',
'initCore',
'LocationState',
'StockHistoryApi',
'InterceptedHistoryApi',
'LocationLite',
'LocationFull',
'preserveQueryInUrl',
'calculateMultiHashFragment'
];

// Act.
Expand Down
12 changes: 12 additions & 0 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,15 @@ export * from './public-utils.js';
export * from './behaviors/active.svelte.js';
export { Redirector } from './Redirector.svelte.js';
export { buildHref } from './buildHref.js';
export { RouterEngine } from './kernel/RouterEngine.svelte.js';
export { isConformantState } from './kernel/isConformantState.js';
export { calculateHref } from './kernel/calculateHref.js';
export { calculateMultiHashFragment } from './kernel/calculateMultiHashFragment.js';
export { calculateState } from './kernel/calculateState.js';
export { initCore } from './kernel/initCore.js';
export { LocationState } from './kernel/LocationState.svelte.js';
export { StockHistoryApi } from './kernel/StockHistoryApi.svelte.js';
export { InterceptedHistoryApi } from './kernel/InterceptedHistoryApi.svelte.js';
export { LocationLite } from './kernel/LocationLite.svelte.js';
export { LocationFull } from './kernel/LocationFull.js';
export { preserveQueryInUrl } from './kernel/preserveQuery.js';
33 changes: 5 additions & 28 deletions src/routes/api/core/functions/+page.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
title: Functions
description: Complete API reference for utility functions in Svelte Router including navigation, HREF building, and active behaviors
---
:::caution[Don't Import from @svelte-router/core/kernel]
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**.

## `activeBehavior`
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.
:::

Import from: `@svelte-router/core`
## `activeBehavior`

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

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

## `buildHref`

Import from: `@svelte-router/core`

`buildHref(pathPiece: string, hashPiece: string, options?: BuildHrefOptions): string`

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.
Expand All @@ -27,8 +28,6 @@ It takes an optional third argument with options. Currently, only the `preserveQ

## `calculateHref`

Import from: `@svelte-router/core/kernel`

`calculateHref(...hrefs: (string | undefined)[]): string`

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

## `calculateMultiHashFragment`

Import from: `@svelte-router/core/kernel`

`calculateMultiHashFragment(hashPaths: Record<string, string>): string`

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.
Expand All @@ -71,8 +68,6 @@ Specify new named hash paths or modify existing ones by passing a POJO object wi

## `calculateState`

Import from: `@svelte-router/core/kernel`

`calculateState(state: any): State`

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

## `getRouterContext`

Import from: `@svelte-router/core`

`getRouterContext(hash: boolean | string): RouterEngine | undefined`

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

## `init`

Import from: `@svelte-router/core`

`init(options?: InitOptions): () => void`

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

Import from: `@svelte-router/core/kernel`

`initCore(location: Location, options?: ExtendedInitOptions): () => void`

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

## `initFull`

Import from: `@svelte-router/core`

`initFull(options?: InitOptions): () => void`

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

## `IsConformantState`

Import from: `@svelte-router/core/kernel`

`function isConformantState(state: unknown): state is State`

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

## `isRouteActive`

Import from: `@svelte-router/core`

`isRouteActive(rsOrRouter: RouterEngine | Record<string, RouteStatus> | null | undefined, key: string | null | undefined): boolean`

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.

## `joinPaths`

Import from: `@svelte-router/core`

`joinPaths(...paths: string[]): string`

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

## `preserveQueryInUrl`

Import from: `@svelte-router/core/kernel`

`preserveQueryInUrl(url: string, preserveQuery: PreserveQuery): string`

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.

## `setRouterContext`

Import from: `@svelte-router/core/kernel`

`setRouterContext(router: RouterEngine, hash?: boolean | string): void`

Sets the router context for the specific universe the hash value represents.
21 changes: 13 additions & 8 deletions src/routes/api/core/objects-and-classes/+page.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,27 @@
title: Objects & Classes
description: API reference for core objects, classes, and interfaces in Svelte Router including RouterEngine and Location
---
:::caution[Don't Import from @svelte-router/core/kernel]
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**.

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.
:::

## `InterceptedHistoryApi`

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

Type: **Class**; Import from: `@svelte-router/core/kernel`
Type: **Class**

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

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

## `location`

Type: `Location`; Import from: `@svelte-router/core`, `@svelte-router/core/kernel`
Type: `Location`

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.

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

Type: **Class**; Import from: `@svelte-router/core/kernel`
Type: **Class**

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.

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

Type: **Class**; Import from: `@svelte-router/core/kernel`
Type: **Class**

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.

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

Type: **Class**; Import from: `@svelte-router/core/kernel`
Type: **Class**

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.

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

## `Redirector`

Type: **Class**; Import from: `@svelte-router/core`
Type: **Class**

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.

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

## `RouterEngine`

Type: **Class**; Import from: `@svelte-router/core/kernel`
Type: **Class**

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.

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

Type: **Class**; Import from: `@svelte-router/core/kernel`
Type: **Class**

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.

Expand Down
4 changes: 0 additions & 4 deletions src/routes/api/kit/functions/+page.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ description: API reference for functions in the SvelteKit extension for Svelte R

## `init`

Import from: `@svelte-router/kit`

`(options?: KitInitOptions): () => void`

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

## `kitCalculateHref`

Import from: `@svelte-router/kit`

`(options: KitCalculateHrefOptions, ...hrefs: string[]): string`

Helper function that combines multiple HREF's into a single HREF using `@svelte-router/core`'s `calculateHref` function **for the path routing universe**.
Expand Down
2 changes: 1 addition & 1 deletion src/routes/docs/library-modes/+page.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ As stated above, this is the event to use if you would like the opportunity to e

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

function cancelEventForSomeReason(event: BeforeNavigateEvent) {
if (!isConformantState(event.state)) {
Expand Down
58 changes: 57 additions & 1 deletion src/routes/docs/loc/+page.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,63 @@ The total count is also shown without `RouterTrace`, which is a non-production c
For detailed information about changes between releases, see the project’s [Releases page](https://github.com/WJSoftware/svelte-router/releases).
:::

## Version 1.0.4

Lines of Code: **1,934** (**1,560** without `RouterTrace`)

Command line: `cloc .\src\lib\ --exclude-dir=testing --exclude-ext=test.ts --exclude-lang=Markdown,SVG --strip-str-comments`

cloc version: **v2.07**

```plaintext
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
TypeScript 29 152 949 1270
Svelte 6 74 350 664
-------------------------------------------------------------------------------
SUM: 35 226 1299 1934
-------------------------------------------------------------------------------
```

## Version 1.0.3

Lines of Code: **1,922** (**1,548** without `RouterTrace`)

Command line: `cloc .\src\lib\ --exclude-dir=testing --exclude-ext=test.ts --exclude-lang=Markdown,SVG --strip-str-comments`

cloc version: **v2.07**

```plaintext
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
TypeScript 29 152 949 1258
Svelte 6 74 350 664
-------------------------------------------------------------------------------
SUM: 35 226 1299 1922
-------------------------------------------------------------------------------
```

## Version 1.0.2

Lines of Code: **1,760** (**1,388** without `RouterTrace`)

Command line: `cloc .\src\lib\ --exclude-dir=testing --exclude-ext=test.ts --exclude-lang=Markdown,SVG --strip-str-comments`

cloc version: **v2.07**

```plaintext
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
TypeScript 29 155 949 1108
Svelte 6 74 350 652
-------------------------------------------------------------------------------
SUM: 35 229 1299 1760
-------------------------------------------------------------------------------
```

## Version 1.0.1

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

```plaintext
Copy
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
Expand Down
8 changes: 6 additions & 2 deletions src/routes/docs/navigating-with-javascript/+page.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,12 @@ Usage of these functions is simple:

```typescript
// Inside a component, for example:
import { calculateHref, calculateState } from '@svelte-router/core/kernel';
import { location, type Hash } from '@svelte-router/core';
import {
calculateHref,
calculateState,
location,
type Hash
} from '@svelte-router/core';

type Props = {
keyProp: string;
Expand Down
3 changes: 1 addition & 2 deletions src/routes/docs/reactive-data/+page.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ The following example shows how to react to routes becoming active:

```svelte
<script lang="ts">
import type { RouterEngine } from "@svelte-router/core/kernel";
import { Router, Route, ... } from "@svelte-router/core";
import { Router, Route, RouterEngine, ... } from "@svelte-router/core";

let router = $state<RouterEngine>();

Expand Down
Loading