@nil-/doc 0.2.22 → 0.2.24
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 +14 -0
- package/components/block/Template.svelte +2 -0
- package/components/block/Template.svelte.d.ts +1 -0
- package/components/navigation/utils.d.ts +22 -0
- package/components/navigation/utils.js +25 -3
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/package.json +10 -7
- package/sveltekit/index.d.ts +22 -0
- package/sveltekit/index.js +47 -0
- package/components/routes.d.ts +0 -6
- package/components/routes.js +0 -29
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @nil-/doc
|
|
2
2
|
|
|
3
|
+
## 0.2.24
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 782e6fa: [doc][breaking] simplified sveltekit glue layer
|
|
8
|
+
- 782e6fa: [doc] added documentation to public methods
|
|
9
|
+
|
|
10
|
+
## 0.2.23
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 5655f86: [feature] added slot prop `key` to Template component
|
|
15
|
+
- 5655f86: [Dependencies] moved some devDependencies to peerDependencies
|
|
16
|
+
|
|
3
17
|
## 0.2.22
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -99,6 +99,7 @@ const resolveArgs = (resolve);
|
|
|
99
99
|
id={param.id}
|
|
100
100
|
tag={param.tag}
|
|
101
101
|
props={resolveArgs(param.defaults, param.values)}
|
|
102
|
+
{key}
|
|
102
103
|
/>
|
|
103
104
|
</div>
|
|
104
105
|
{:else}
|
|
@@ -108,6 +109,7 @@ const resolveArgs = (resolve);
|
|
|
108
109
|
id={param.id}
|
|
109
110
|
tag={param.tag}
|
|
110
111
|
props={resolveArgs(param.defaults, param.values)}
|
|
112
|
+
{key}
|
|
111
113
|
/>
|
|
112
114
|
</div>
|
|
113
115
|
{/key}
|
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
import type { Tree, Sorter, Renamer } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Compares two texts for sorting.
|
|
4
|
+
*
|
|
5
|
+
* If the texts follows `<I>-<Name>` format,
|
|
6
|
+
* sorting is done by comparing the numbers in the prefix.
|
|
7
|
+
*
|
|
8
|
+
* If only one of the texts follows `<I>-<Name>` format,
|
|
9
|
+
* the text that follows the format is considered as higher in order.
|
|
10
|
+
*
|
|
11
|
+
* Else comparison is done using built-in `string` comparison.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} l
|
|
14
|
+
* @param {string} r
|
|
15
|
+
* @returns `-1 | 0 | +1`
|
|
16
|
+
*/
|
|
2
17
|
declare const sorter: Sorter;
|
|
18
|
+
/**
|
|
19
|
+
* If a text follows `<I>-<Name>` format,
|
|
20
|
+
* this method simply removes the Prefix.
|
|
21
|
+
*
|
|
22
|
+
* @param {string} text
|
|
23
|
+
* @returns `<Name>`
|
|
24
|
+
*/
|
|
3
25
|
declare const renamer: Renamer;
|
|
4
26
|
export declare function sort(t: Record<string, Tree>, order: (l: string, r: string) => 1 | 0 | -1): [string, Tree][];
|
|
5
27
|
export { sorter, renamer };
|
|
@@ -8,6 +8,21 @@ function sorterT(l, r) {
|
|
|
8
8
|
}
|
|
9
9
|
return 0;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Compares two texts for sorting.
|
|
13
|
+
*
|
|
14
|
+
* If the texts follows `<I>-<Name>` format,
|
|
15
|
+
* sorting is done by comparing the numbers in the prefix.
|
|
16
|
+
*
|
|
17
|
+
* If only one of the texts follows `<I>-<Name>` format,
|
|
18
|
+
* the text that follows the format is considered as higher in order.
|
|
19
|
+
*
|
|
20
|
+
* Else comparison is done using built-in `string` comparison.
|
|
21
|
+
*
|
|
22
|
+
* @param {string} l
|
|
23
|
+
* @param {string} r
|
|
24
|
+
* @returns `-1 | 0 | +1`
|
|
25
|
+
*/
|
|
11
26
|
const sorter = (l, r) => {
|
|
12
27
|
const lmatch = match.exec(l);
|
|
13
28
|
const rmatch = match.exec(r);
|
|
@@ -22,12 +37,19 @@ const sorter = (l, r) => {
|
|
|
22
37
|
}
|
|
23
38
|
return sorterT(parseInt(lmatch[1]), parseInt(rmatch[1]));
|
|
24
39
|
};
|
|
25
|
-
|
|
26
|
-
|
|
40
|
+
/**
|
|
41
|
+
* If a text follows `<I>-<Name>` format,
|
|
42
|
+
* this method simply removes the Prefix.
|
|
43
|
+
*
|
|
44
|
+
* @param {string} text
|
|
45
|
+
* @returns `<Name>`
|
|
46
|
+
*/
|
|
47
|
+
const renamer = (text) => {
|
|
48
|
+
const m = match.exec(text);
|
|
27
49
|
if (m) {
|
|
28
50
|
return m[2];
|
|
29
51
|
}
|
|
30
|
-
return
|
|
52
|
+
return text;
|
|
31
53
|
};
|
|
32
54
|
export function sort(t, order) {
|
|
33
55
|
return Object.entries(t).sort(([l], [r]) => order(l, r));
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nil-/doc",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.24",
|
|
4
4
|
"author": {
|
|
5
5
|
"email": "njaldea@gmail.com",
|
|
6
6
|
"name": "Neil Aldea"
|
|
7
7
|
},
|
|
8
|
+
"peerDependencies": {
|
|
9
|
+
"svelte": "^3.55.0"
|
|
10
|
+
},
|
|
8
11
|
"devDependencies": {
|
|
9
|
-
"@sveltejs/adapter-vercel": "
|
|
10
|
-
"@sveltejs/kit": "
|
|
11
|
-
"@sveltejs/package": "
|
|
12
|
+
"@sveltejs/adapter-vercel": "^1.0.0",
|
|
13
|
+
"@sveltejs/kit": "^1.0.1",
|
|
14
|
+
"@sveltejs/package": "^1.0.1",
|
|
12
15
|
"mdsvex": "^0.10.6",
|
|
13
|
-
"svelte": "^3.54.0",
|
|
14
16
|
"svelte-check": "^2.10.2",
|
|
15
17
|
"svelte-markdown": "^0.2.3",
|
|
16
18
|
"svelte-preprocess": "^4.10.7",
|
|
17
19
|
"tslib": "^2.4.1",
|
|
18
20
|
"typescript": "^4.9.4",
|
|
19
|
-
"vite": "^4.0.
|
|
21
|
+
"vite": "^4.0.1"
|
|
20
22
|
},
|
|
21
23
|
"type": "module",
|
|
22
24
|
"publishConfig": {
|
|
@@ -30,7 +32,8 @@
|
|
|
30
32
|
"license": "ISC",
|
|
31
33
|
"exports": {
|
|
32
34
|
"./package.json": "./package.json",
|
|
33
|
-
".": "./index.js"
|
|
35
|
+
".": "./index.js",
|
|
36
|
+
"./sveltekit": "./sveltekit/index.js"
|
|
34
37
|
},
|
|
35
38
|
"svelte": "./index.js"
|
|
36
39
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Readable } from "svelte/store";
|
|
2
|
+
type Routes = {
|
|
3
|
+
/**
|
|
4
|
+
* Routes
|
|
5
|
+
*/
|
|
6
|
+
data: string[];
|
|
7
|
+
/**
|
|
8
|
+
* Removes unneeded group layout in the route
|
|
9
|
+
* @param {string} route
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
current: Readable<string | null>;
|
|
13
|
+
navigate: (e: CustomEvent<string>) => void;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Dedicated helper method to be used for sveltekit
|
|
17
|
+
* @param detail - vite's `import.meta.glob(..., { eager: true })`
|
|
18
|
+
* @param prefix - only use when layout is not in the root route
|
|
19
|
+
* @returns Routes
|
|
20
|
+
*/
|
|
21
|
+
export declare function sveltekit(detail: Record<string, unknown>, prefix?: string | null): Routes;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { derived } from "svelte/store";
|
|
2
|
+
import { page } from "$app/stores";
|
|
3
|
+
import { goto } from "$app/navigation";
|
|
4
|
+
const PREFIX = ".";
|
|
5
|
+
const SUFFIX = "/+page.svelte";
|
|
6
|
+
function toRoute(p) {
|
|
7
|
+
return p.substring(PREFIX.length, p.length - SUFFIX.length);
|
|
8
|
+
}
|
|
9
|
+
const route_advanced_layout_match = /\(.*\)/;
|
|
10
|
+
function collapseLayout(p) {
|
|
11
|
+
return p
|
|
12
|
+
.split("/")
|
|
13
|
+
.filter((p) => route_advanced_layout_match.exec(p) == null)
|
|
14
|
+
.join("/");
|
|
15
|
+
}
|
|
16
|
+
function isNotRoot(p) {
|
|
17
|
+
return p !== "/";
|
|
18
|
+
}
|
|
19
|
+
const route_rest_match = /.*\[.*\].*/;
|
|
20
|
+
function isRouteDynamic(p) {
|
|
21
|
+
return route_rest_match.exec(p) == null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Dedicated helper method to be used for sveltekit
|
|
25
|
+
* @param detail - vite's `import.meta.glob(..., { eager: true })`
|
|
26
|
+
* @param prefix - only use when layout is not in the root route
|
|
27
|
+
* @returns Routes
|
|
28
|
+
*/
|
|
29
|
+
export function sveltekit(detail, prefix = null) {
|
|
30
|
+
return {
|
|
31
|
+
data: Object.keys(detail)
|
|
32
|
+
.map(toRoute)
|
|
33
|
+
.map(collapseLayout)
|
|
34
|
+
.filter(isNotRoot)
|
|
35
|
+
.filter(isRouteDynamic),
|
|
36
|
+
current: derived(page, ($page) => {
|
|
37
|
+
if ($page.route.id) {
|
|
38
|
+
if (prefix) {
|
|
39
|
+
return collapseLayout($page.route.id.substring(prefix.length));
|
|
40
|
+
}
|
|
41
|
+
return collapseLayout($page.route.id);
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}),
|
|
45
|
+
navigate: prefix ? (e) => goto(`${prefix}${e.detail}`) : (e) => goto(e.detail)
|
|
46
|
+
};
|
|
47
|
+
}
|
package/components/routes.d.ts
DELETED
package/components/routes.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const prefix = ".".length;
|
|
2
|
-
const suffix = "/+page.svelte".length;
|
|
3
|
-
function toRoute(p) {
|
|
4
|
-
return p.substring(prefix, p.length - suffix);
|
|
5
|
-
}
|
|
6
|
-
const route_advanced_layout_match = /\(.*\)/;
|
|
7
|
-
function collapseLayout(p) {
|
|
8
|
-
return p
|
|
9
|
-
.split("/")
|
|
10
|
-
.filter((p) => route_advanced_layout_match.exec(p) == null)
|
|
11
|
-
.join("/");
|
|
12
|
-
}
|
|
13
|
-
function isNotRoot(p) {
|
|
14
|
-
return p !== "/";
|
|
15
|
-
}
|
|
16
|
-
const route_rest_match = /.*\[.*\].*/;
|
|
17
|
-
function isRouteDynamic(p) {
|
|
18
|
-
return route_rest_match.exec(p) == null;
|
|
19
|
-
}
|
|
20
|
-
export function routes(files_from_import_meta) {
|
|
21
|
-
return {
|
|
22
|
-
data: Object.keys(files_from_import_meta)
|
|
23
|
-
.map(toRoute)
|
|
24
|
-
.map(collapseLayout)
|
|
25
|
-
.filter(isNotRoot)
|
|
26
|
-
.filter(isRouteDynamic),
|
|
27
|
-
process: (r) => (r ? collapseLayout(r) : null)
|
|
28
|
-
};
|
|
29
|
-
}
|