@nil-/doc 0.2.23 → 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 CHANGED
@@ -1,5 +1,12 @@
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
+
3
10
  ## 0.2.23
4
11
 
5
12
  ### Patch Changes
@@ -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
- const renamer = (t) => {
26
- const m = match.exec(t);
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 t;
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
@@ -1,4 +1,3 @@
1
- export { routes } from "./components/routes";
2
1
  export { renamer, sorter } from "./components/navigation/utils";
3
2
  export type { Control } from "./components/block/controls/types";
4
3
  export { default as Layout } from "./components/Layout.svelte";
package/index.js CHANGED
@@ -1,4 +1,3 @@
1
- export { routes } from "./components/routes";
2
1
  export { renamer, sorter } from "./components/navigation/utils";
3
2
  export { default as Layout } from "./components/Layout.svelte";
4
3
  export { default as Block } from "./components/block/Block.svelte";
package/package.json CHANGED
@@ -1,24 +1,24 @@
1
1
  {
2
2
  "name": "@nil-/doc",
3
- "version": "0.2.23",
3
+ "version": "0.2.24",
4
4
  "author": {
5
5
  "email": "njaldea@gmail.com",
6
6
  "name": "Neil Aldea"
7
7
  },
8
8
  "peerDependencies": {
9
- "svelte": "^3.54.0"
9
+ "svelte": "^3.55.0"
10
10
  },
11
11
  "devDependencies": {
12
12
  "@sveltejs/adapter-vercel": "^1.0.0",
13
- "@sveltejs/kit": "^1.0.0",
14
- "@sveltejs/package": "^1.0.0",
13
+ "@sveltejs/kit": "^1.0.1",
14
+ "@sveltejs/package": "^1.0.1",
15
15
  "mdsvex": "^0.10.6",
16
16
  "svelte-check": "^2.10.2",
17
17
  "svelte-markdown": "^0.2.3",
18
18
  "svelte-preprocess": "^4.10.7",
19
19
  "tslib": "^2.4.1",
20
20
  "typescript": "^4.9.4",
21
- "vite": "^4.0.0"
21
+ "vite": "^4.0.1"
22
22
  },
23
23
  "type": "module",
24
24
  "publishConfig": {
@@ -32,7 +32,8 @@
32
32
  "license": "ISC",
33
33
  "exports": {
34
34
  "./package.json": "./package.json",
35
- ".": "./index.js"
35
+ ".": "./index.js",
36
+ "./sveltekit": "./sveltekit/index.js"
36
37
  },
37
38
  "svelte": "./index.js"
38
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
+ }
@@ -1,6 +0,0 @@
1
- type Routes = {
2
- data: string[];
3
- process: (r: string | null) => string | null;
4
- };
5
- export declare function routes(files_from_import_meta: Record<string, unknown>): Routes;
6
- export {};
@@ -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
- }