@nil-/doc 0.2.40 → 0.2.42
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/CHANGELOG.md +12 -0
- package/components/Layout.svelte +8 -1
- package/components/navigation/Node.svelte +5 -2
- package/components/navigation/utils/fuzz.d.ts +1 -0
- package/components/navigation/utils/fuzz.js +7 -4
- package/package.json +4 -4
- package/sveltekit/index.d.ts +10 -4
- package/sveltekit/index.js +27 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @nil-/doc
|
|
2
2
|
|
|
3
|
+
## 0.2.42
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [doc][new] added theme store in sveltekit to retain used theme ([#67](https://github.com/njaldea/mono/pull/67))
|
|
8
|
+
|
|
9
|
+
## 0.2.41
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [doc][docu] added page for fuzzy matching ([#65](https://github.com/njaldea/mono/pull/65))
|
|
14
|
+
|
|
3
15
|
## 0.2.40
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/components/Layout.svelte
CHANGED
|
@@ -97,6 +97,13 @@ const parentTheme = getTheme();
|
|
|
97
97
|
const dark = initTheme();
|
|
98
98
|
$:
|
|
99
99
|
$dark = theme === void 0 ? $parentTheme : "dark" === theme;
|
|
100
|
+
const toggle = () => {
|
|
101
|
+
if (theme !== void 0) {
|
|
102
|
+
theme = $dark ? "light" : "dark";
|
|
103
|
+
} else {
|
|
104
|
+
$dark = !$dark;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
100
107
|
</script>
|
|
101
108
|
<!--
|
|
102
109
|
@component
|
|
@@ -105,7 +112,7 @@ $:
|
|
|
105
112
|
<div class="layout" class:dark={$dark}>
|
|
106
113
|
<div class="top">
|
|
107
114
|
<slot name="title"><span>@nil-/doc</span></slot>
|
|
108
|
-
<div class="icon" on:click={
|
|
115
|
+
<div class="icon" on:click={toggle} on:keypress={null}>
|
|
109
116
|
<ThemeIcon bind:dark={$dark} />
|
|
110
117
|
</div>
|
|
111
118
|
<div
|
|
@@ -16,14 +16,16 @@
|
|
|
16
16
|
grid-template-columns: 15px 1fr;
|
|
17
17
|
align-items: center;
|
|
18
18
|
cursor: pointer;
|
|
19
|
+
gap: 5px;
|
|
20
|
+
box-sizing: border-box;
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
.header:hover {
|
|
22
|
-
background-color:
|
|
24
|
+
background-color: hsla(203, 98%, 50%, 0.07);
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
.header.selected {
|
|
26
|
-
background-color:
|
|
28
|
+
background-color: hsla(203, 98%, 50%, 0.822);
|
|
27
29
|
color: black;
|
|
28
30
|
}
|
|
29
31
|
|
|
@@ -31,6 +33,7 @@
|
|
|
31
33
|
justify-content: center;
|
|
32
34
|
height: 15px;
|
|
33
35
|
width: 15px;
|
|
36
|
+
transition: transform 350ms;
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
.icon.expanded {
|
|
@@ -107,13 +107,16 @@ const doScoreFuzzy = (query, queryLower, queryLength, target, targetLower, targe
|
|
|
107
107
|
targetIndex--;
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
return [scores[queryLength * targetLength - 1], positions.reverse()];
|
|
110
|
+
return [scores[queryLength * targetLength - 1] ?? 0, positions.reverse()];
|
|
111
111
|
};
|
|
112
|
-
export const
|
|
112
|
+
export const score = (target, query) => {
|
|
113
113
|
const targetLength = target.length;
|
|
114
114
|
const queryLength = query.length;
|
|
115
115
|
if (targetLength < queryLength) {
|
|
116
|
-
return
|
|
116
|
+
return [0, []];
|
|
117
117
|
}
|
|
118
|
-
return
|
|
118
|
+
return doScoreFuzzy(query, query.toLowerCase(), queryLength, target, target.toLowerCase(), targetLength);
|
|
119
|
+
};
|
|
120
|
+
export const fuzz = (target, query) => {
|
|
121
|
+
return score(target, query)[0] > 0;
|
|
119
122
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nil-/doc",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.42",
|
|
4
4
|
"author": {
|
|
5
5
|
"email": "njaldea@gmail.com",
|
|
6
6
|
"name": "Neil Aldea"
|
|
@@ -8,15 +8,15 @@
|
|
|
8
8
|
"license": "ISC",
|
|
9
9
|
"devDependencies": {
|
|
10
10
|
"@sveltejs/adapter-vercel": "^1.0.0",
|
|
11
|
-
"@sveltejs/kit": "^1.0.
|
|
12
|
-
"@sveltejs/package": "^1.0.
|
|
11
|
+
"@sveltejs/kit": "^1.0.5",
|
|
12
|
+
"@sveltejs/package": "^1.0.2",
|
|
13
13
|
"@vitest/coverage-c8": "^0.26.3",
|
|
14
14
|
"mdsvex": "^0.10.6",
|
|
15
15
|
"remark-admonitions": "^1.2.1",
|
|
16
16
|
"svelte-check": "^2.10.3",
|
|
17
17
|
"tslib": "^2.4.1",
|
|
18
18
|
"typescript": "^4.9.4",
|
|
19
|
-
"vite": "^4.0.
|
|
19
|
+
"vite": "^4.0.4",
|
|
20
20
|
"vitest": "^0.26.3"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
package/sveltekit/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { type Readable } from "svelte/store";
|
|
2
|
-
type
|
|
1
|
+
import { type Readable, type Writable } from "svelte/store";
|
|
2
|
+
import type { Theme } from "../components/context";
|
|
3
|
+
type Settings = {
|
|
3
4
|
/**
|
|
4
5
|
* List of routes
|
|
5
6
|
*/
|
|
@@ -13,12 +14,17 @@ type Routes = {
|
|
|
13
14
|
* @param e - event that contains detail about the target url
|
|
14
15
|
*/
|
|
15
16
|
navigate: (e: CustomEvent<string>) => Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* A store that is responsible in keeping the theme in localStorage
|
|
19
|
+
* Default is "dark"
|
|
20
|
+
*/
|
|
21
|
+
theme: Writable<Exclude<Theme, undefined>>;
|
|
16
22
|
};
|
|
17
23
|
/**
|
|
18
24
|
* Dedicated helper method to be used for sveltekit
|
|
19
25
|
* @param detail - vite's `import.meta.glob(..., { eager: true })`
|
|
20
26
|
* @param prefix - only use when layout is not in the root route
|
|
21
|
-
* @returns
|
|
27
|
+
* @returns Settings
|
|
22
28
|
*/
|
|
23
|
-
export declare const sveltekit: (detail: Record<string, unknown>, prefix?: string | null) =>
|
|
29
|
+
export declare const sveltekit: (detail: Record<string, unknown>, prefix?: string | null) => Settings;
|
|
24
30
|
export {};
|
package/sveltekit/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { derived } from "svelte/store";
|
|
1
|
+
import { derived, writable } from "svelte/store";
|
|
2
2
|
import { page } from "$app/stores";
|
|
3
3
|
import { goto } from "$app/navigation";
|
|
4
|
+
import { browser } from "$app/environment";
|
|
4
5
|
const toRoute = (p) => p.substring(1, p.lastIndexOf("/"));
|
|
5
6
|
const routeHasLayoutGroup = /\(.*\)/;
|
|
6
7
|
const collapseLayout = (p) => p
|
|
@@ -14,22 +15,30 @@ const isRouteDynamic = (p) => null == routeIsDynamic.exec(p);
|
|
|
14
15
|
* Dedicated helper method to be used for sveltekit
|
|
15
16
|
* @param detail - vite's `import.meta.glob(..., { eager: true })`
|
|
16
17
|
* @param prefix - only use when layout is not in the root route
|
|
17
|
-
* @returns
|
|
18
|
+
* @returns Settings
|
|
18
19
|
*/
|
|
19
|
-
export const sveltekit = (detail, prefix = null) =>
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
export const sveltekit = (detail, prefix = null) => {
|
|
21
|
+
const key = "@nil-/doc/theme";
|
|
22
|
+
const initialValue = browser && "light" === localStorage.getItem(key) ? "light" : "dark";
|
|
23
|
+
const theme = writable(initialValue);
|
|
24
|
+
theme.subscribe((v) => browser && localStorage.setItem(key, v));
|
|
25
|
+
const result = {
|
|
26
|
+
data: Object.keys(detail)
|
|
27
|
+
.map(toRoute)
|
|
28
|
+
.map(collapseLayout)
|
|
29
|
+
.filter(isNotRoot)
|
|
30
|
+
.filter(isRouteDynamic),
|
|
31
|
+
current: derived(page, ($page) => {
|
|
32
|
+
if ($page.route.id) {
|
|
33
|
+
if (prefix) {
|
|
34
|
+
return collapseLayout($page.route.id.substring(prefix.length));
|
|
35
|
+
}
|
|
36
|
+
return collapseLayout($page.route.id);
|
|
29
37
|
}
|
|
30
|
-
return
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
return null;
|
|
39
|
+
}),
|
|
40
|
+
navigate: prefix ? (e) => goto(`${prefix}${e.detail}`) : (e) => goto(e.detail),
|
|
41
|
+
theme
|
|
42
|
+
};
|
|
43
|
+
return result;
|
|
44
|
+
};
|