@nil-/doc 0.2.38 → 0.2.39

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,19 @@
1
1
  # @nil-/doc
2
2
 
3
+ ## 0.2.39
4
+
5
+ ### Patch Changes
6
+
7
+ - [doc][fix] force state of navigation expand icon when filtering ([#61](https://github.com/njaldea/mono/pull/61))
8
+
9
+ - [doc][patch] tighter eslint ([#61](https://github.com/njaldea/mono/pull/61))
10
+
11
+ - [doc][patch] added tests for non-UI related code ([#61](https://github.com/njaldea/mono/pull/61))
12
+
13
+ - [doc][patch] moved type definition ([#61](https://github.com/njaldea/mono/pull/61))
14
+
15
+ - [doc][patch] enabled typescript eslint rules ([#61](https://github.com/njaldea/mono/pull/61))
16
+
3
17
  ## 0.2.38
4
18
 
5
19
  ### Patch Changes
@@ -84,7 +84,7 @@
84
84
  </script>
85
85
  <script>import Container from "./etc/Container.svelte";
86
86
  import Nav from "./navigation/Nav.svelte";
87
- import { getTheme, initTheme, evalTheme } from "./context";
87
+ import { getTheme, initTheme } from "./context";
88
88
  import ThemeIcon from "./etc/ThemeIcon.svelte";
89
89
  import NilIcon from "./etc/NilIcon.svelte";
90
90
  export let data;
@@ -95,7 +95,7 @@ export let theme = void 0;
95
95
  const parentTheme = getTheme();
96
96
  const dark = initTheme();
97
97
  $:
98
- $dark = evalTheme(parentTheme ? $parentTheme : true, theme);
98
+ $dark = theme === void 0 ? $parentTheme : "dark" === theme;
99
99
  </script>
100
100
  <!--
101
101
  @component
@@ -42,7 +42,7 @@
42
42
  initControlsState,
43
43
  initOrientation
44
44
  } from "./context";
45
- import { getTheme, initTheme, evalTheme } from "../context";
45
+ import { getTheme, initTheme } from "../context";
46
46
  initParams();
47
47
  initDefaults();
48
48
  initControls();
@@ -52,7 +52,7 @@ export let theme = void 0;
52
52
  const parentTheme = getTheme();
53
53
  const dark = initTheme();
54
54
  $:
55
- $dark = evalTheme(parentTheme ? $parentTheme : false, theme);
55
+ $dark = theme === void 0 ? $parentTheme : "dark" === theme;
56
56
  </script>
57
57
  <!--
58
58
  @component
@@ -1,5 +1,5 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import { type ValueType } from "./context";
2
+ import type { ValueType } from "./types";
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  tag?: string | undefined;
@@ -1,8 +1,6 @@
1
- import type { Control } from "./controls/types";
2
1
  import type { Writable } from "svelte/store";
3
- export type ValueType = undefined | boolean | number | string | ValueType[] | {
4
- [key: string]: ValueType;
5
- };
2
+ import type { Control } from "./controls/types";
3
+ import type { ValueType } from "./types";
6
4
  export type Params = {
7
5
  id: number;
8
6
  tag: string;
@@ -1,6 +1,6 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
+ import type { ValueType } from "../types";
2
3
  import type { Control } from "./types";
3
- import type { ValueType } from "../context";
4
4
  declare const __propDef: {
5
5
  props: {
6
6
  infos: Control[];
@@ -1,19 +1,21 @@
1
1
 
2
2
  <script>import Component from "./Component.svelte";
3
3
  import Header from "./misc/GroupHeader.svelte";
4
- import { getObjectDefaults } from "./misc/defaulter";
4
+ import { getDefault } from "./misc/defaulter";
5
5
  export let value;
6
6
  export let info;
7
7
  export let depth;
8
8
  export let disabled = false;
9
- let ivalue = value ?? getObjectDefaults(info);
9
+ let ivalue = value ?? getDefault(info);
10
10
  let enabled = value !== void 0;
11
11
  $:
12
12
  value = !disabled && enabled ? ivalue : void 0;
13
+ $:
14
+ values = info.values;
13
15
  </script>
14
16
  <Header name={info.name} bind:checked={enabled} {depth} {disabled} />
15
17
  {#if enabled && !disabled}
16
- {#each info.values as info, i (i)}
18
+ {#each values as info, i (i)}
17
19
  <Component
18
20
  {info}
19
21
  bind:value={ivalue[info.name]}
@@ -1,6 +1,6 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
+ import type { ValueType } from "../types";
2
3
  import type { ControlObject } from "./types";
3
- import type { ValueType } from "../context";
4
4
  declare const __propDef: {
5
5
  props: {
6
6
  value: Record<string, ValueType> | undefined;
@@ -1,19 +1,21 @@
1
1
 
2
2
  <script>import Component from "./Component.svelte";
3
3
  import Header from "./misc/GroupHeader.svelte";
4
- import { getTupleDefaults } from "./misc/defaulter";
4
+ import { getDefault } from "./misc/defaulter";
5
5
  export let value;
6
6
  export let info;
7
7
  export let depth;
8
8
  export let disabled = false;
9
- let ivalue = value ?? getTupleDefaults(info);
9
+ let ivalue = value ?? getDefault(info);
10
10
  let enabled = value !== void 0;
11
11
  $:
12
12
  value = !disabled && enabled ? ivalue : void 0;
13
+ $:
14
+ values = info.values;
13
15
  </script>
14
16
  <Header name={info.name} bind:checked={enabled} {depth} {disabled} />
15
17
  {#if enabled && !disabled}
16
- {#each info.values as info, i (i)}
18
+ {#each values as info, i (i)}
17
19
  <Component
18
20
  info={{ ...info, name: `${i}` }}
19
21
  bind:value={ivalue[i]}
@@ -1,6 +1,6 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
+ import type { ValueType } from "../types";
2
3
  import type { ControlTuple } from "./types";
3
- import type { ValueType } from "../context";
4
4
  declare const __propDef: {
5
5
  props: {
6
6
  value: ValueType[] | undefined;
@@ -1,5 +1,10 @@
1
- import type { ValueType } from "../../context";
2
- import type { Control, ControlTuple, ControlObject } from "../types";
3
- export declare const getDefault: (i: Control) => ValueType;
4
- export declare const getObjectDefaults: (info: ControlObject) => Record<string, ValueType>;
5
- export declare const getTupleDefaults: (i: ControlTuple) => ValueType[];
1
+ import type { ValueType } from "../../types";
2
+ import type { Control, ControlNumber, ControlRange, ControlSelect, ControlSwitch, ControlText, ControlTuple, ControlObject } from "../types";
3
+ export declare function getDefault(i: ControlTuple): ValueType[];
4
+ export declare function getDefault(i: ControlObject): Record<string, ValueType>;
5
+ export declare function getDefault(i: ControlNumber): number;
6
+ export declare function getDefault(i: ControlRange): number;
7
+ export declare function getDefault(i: ControlSelect): string;
8
+ export declare function getDefault(i: ControlText): string;
9
+ export declare function getDefault(i: ControlSwitch): boolean;
10
+ export declare function getDefault(i: Control): ValueType;
@@ -1,37 +1,33 @@
1
- export const getDefault = (i) => {
2
- if ("switch" === i.type) {
3
- return false;
4
- }
5
- if ("number" === i.type) {
6
- return 0;
7
- }
8
- if ("range" === i.type) {
9
- return i.min;
10
- }
11
- if ("text" === i.type) {
12
- return "";
13
- }
14
- if ("select" === i.type) {
15
- return i.values.length > 0 ? i.values[0] : "";
16
- }
17
- if ("tuple" === i.type) {
18
- // eslint-disable-next-line no-use-before-define
19
- return [...getTupleDefaults(i)];
20
- }
21
- if ("object" === i.type) {
22
- // eslint-disable-next-line no-use-before-define
23
- return getObjectDefaults(i);
24
- }
25
- return undefined;
26
- };
27
- export const getObjectDefaults = (info) => {
1
+ // eslint-disable-next-line func-style
2
+ export function getDefault(i) {
3
+ switch (i.type) {
4
+ case "object":
5
+ // eslint-disable-next-line no-use-before-define
6
+ return getObjectDefaults(i);
7
+ case "tuple":
8
+ // eslint-disable-next-line no-use-before-define
9
+ return getTupleDefaults(i);
10
+ case "text":
11
+ return "";
12
+ case "select":
13
+ return i.values.length > 0 ? i.values[0] : "";
14
+ case "number":
15
+ return 0;
16
+ case "range":
17
+ return i.min;
18
+ case "switch":
19
+ default:
20
+ return false;
21
+ }
22
+ }
23
+ const getObjectDefaults = (info) => {
28
24
  const ret = {};
29
25
  for (const i of info.values) {
30
26
  ret[i.name] = getDefault(i);
31
27
  }
32
28
  return ret;
33
29
  };
34
- export const getTupleDefaults = (i) => {
30
+ const getTupleDefaults = (i) => {
35
31
  const ret = [];
36
32
  for (const info of i.values) {
37
33
  ret.push(getDefault(info));
@@ -0,0 +1,9 @@
1
+ export type ValueType =
2
+ | undefined
3
+ | boolean
4
+ | number
5
+ | string
6
+ | ValueType[]
7
+ | {
8
+ [key: string]: ValueType;
9
+ };
@@ -1,6 +1,4 @@
1
- import type { ValueType } from "./context";
2
- type VTObject = {
3
- [key: string]: ValueType;
4
- };
5
- export declare const resolve: <Args>(d: VTObject | undefined, p: VTObject) => Args;
1
+ import type { ValueType } from "./types";
2
+ type VTObject = Record<string, ValueType>;
3
+ export declare const resolve: <Args = Record<string, ValueType>>(destination: VTObject, override: VTObject) => Args;
6
4
  export {};
@@ -1,15 +1,12 @@
1
1
  const resolveArray = (d, p) => {
2
- if (d === undefined) {
3
- return undefined;
4
- }
5
2
  const ret = [];
6
- for (const i in d) {
3
+ for (let i = 0; i < d.length; ++i) {
7
4
  if (d[i] instanceof Array) {
8
- ret.push(resolveArray(d[i], p[i] ?? []));
5
+ ret.push(resolveArray(d[i], (p[i] ?? [])));
9
6
  }
10
7
  else if (d[i] instanceof Object) {
11
8
  // eslint-disable-next-line no-use-before-define
12
- ret.push(resolveObject(d[i], p[i] ?? {}));
9
+ ret.push(resolveObject(d[i], (p[i] ?? {})));
13
10
  }
14
11
  else {
15
12
  ret.push(p[i] ?? d[i]);
@@ -18,16 +15,13 @@ const resolveArray = (d, p) => {
18
15
  return ret;
19
16
  };
20
17
  const resolveObject = (d, p) => {
21
- if (d === undefined) {
22
- return undefined;
23
- }
24
18
  const ret = {};
25
19
  for (const [key, value] of Object.entries(d)) {
26
20
  if (value instanceof Array) {
27
- ret[key] = resolveArray(value, p[key] ?? []);
21
+ ret[key] = resolveArray(value, (p[key] ?? []));
28
22
  }
29
23
  else if (value instanceof Object) {
30
- ret[key] = resolveObject(value, p[key] ?? {});
24
+ ret[key] = resolveObject(value, (p[key] ?? {}));
31
25
  }
32
26
  else {
33
27
  ret[key] = p[key] ?? value;
@@ -35,6 +29,6 @@ const resolveObject = (d, p) => {
35
29
  }
36
30
  return ret;
37
31
  };
38
- export const resolve = (d, p) => {
39
- return resolveObject(d ?? {}, p);
32
+ export const resolve = (destination, override) => {
33
+ return resolveObject(destination, override);
40
34
  };
@@ -2,4 +2,3 @@ import type { Writable } from "svelte/store";
2
2
  export type Theme = undefined | "light" | "dark";
3
3
  export declare const getTheme: () => Writable<boolean>;
4
4
  export declare const initTheme: () => Writable<boolean>;
5
- export declare const evalTheme: (parent: boolean, theme: Theme) => boolean;
@@ -1,11 +1,5 @@
1
1
  import { setContext, getContext } from "svelte";
2
2
  import { writable } from "svelte/store";
3
3
  const theme = Symbol();
4
- export const getTheme = () => getContext(theme);
4
+ export const getTheme = () => getContext(theme) ?? writable(true);
5
5
  export const initTheme = () => setContext(theme, writable(true));
6
- export const evalTheme = (parent, theme) => {
7
- if (theme === undefined) {
8
- return parent;
9
- }
10
- return "dark" === theme;
11
- };
@@ -3,7 +3,7 @@ export const createDraggable = (offset) => {
3
3
  const position = writable(offset);
4
4
  const draggable = (div, parameter) => {
5
5
  let tm = new Date().getTime();
6
- let param = parameter ?? { reset: () => 0, vertical: true, reversed: false };
6
+ let param = parameter;
7
7
  position.set(param.reset());
8
8
  let refPage = 0;
9
9
  const disengage = () => param.moving.set(false);
@@ -15,14 +15,14 @@ export const createDraggable = (offset) => {
15
15
  };
16
16
  const engage = (e) => {
17
17
  if (checkDoubleTap()) {
18
- param?.dbltap?.();
18
+ param.dbltap?.();
19
19
  disengage();
20
20
  return;
21
21
  }
22
22
  param.moving.set(true);
23
23
  position.set(param.reset());
24
24
  refPage = param.vertical ? e.pageX : e.pageY;
25
- param?.tap?.();
25
+ param.tap?.();
26
26
  };
27
27
  const move = (e) => {
28
28
  if (get(param.moving)) {
@@ -57,15 +57,15 @@ const apply = (paths, init, pre, next, post) => {
57
57
  const filt = (path, filter, renamer) => {
58
58
  return fuzz(path, filter) || fuzz(path.split("/").map(renamer).join("/"), filter);
59
59
  };
60
- const populate = (filter, info, renamer) => apply(
61
- filter.length > 0 ? info.filter((path) => filt(path, filter, renamer)) : info,
62
- () => ({ url: null, sub: {} }),
63
- (t) => t,
64
- (t) => t.sub,
65
- (t, p) => {
66
- t.url = p;
67
- }
68
- );
60
+ const populate = (filter, info, renamer) => {
61
+ return apply(
62
+ filter.length > 0 ? info.filter((path) => filt(path, filter, renamer)) : info,
63
+ () => ({ url: null, sub: {} }),
64
+ (t) => t,
65
+ (t) => t.sub,
66
+ (t, p) => void (t.url = p)
67
+ );
68
+ };
69
69
  </script>
70
70
  <script>import Tree from "./Tree.svelte";
71
71
  export let info;
@@ -74,7 +74,7 @@ const click = (link) => {
74
74
  {style}
75
75
  class:selected={selected === value.url}
76
76
  >
77
- <div class="icon" class:expanded={hasChildren && states.expanded}>
77
+ <div class="icon" class:expanded={hasChildren && (expand || states.expanded)}>
78
78
  <div>{Object.keys(value.sub).length > 0 ? ">" : "-"}</div>
79
79
  </div>
80
80
  <span>{renamer(key)}</span>
@@ -1,12 +1,12 @@
1
- export interface Tree {
1
+ export type Tree = {
2
2
  url: string | null;
3
3
  sub: Record<string, Tree>;
4
- }
4
+ };
5
5
 
6
- export interface States {
6
+ export type States = {
7
7
  expanded: boolean;
8
8
  sub: Record<string, States>;
9
- }
9
+ };
10
10
 
11
11
  export type Sorter = (l: string, r: string) => 1 | 0 | -1;
12
12
  export type Renamer = (s: string) => string;
@@ -35,5 +35,5 @@ export const sorter = (l, r) => {
35
35
  if (null == rmatch) {
36
36
  return -1;
37
37
  }
38
- return sorterT(parseInt(lmatch[1]), parseInt(rmatch[1]));
38
+ return sorterT(parseInt(lmatch[1]), parseInt(rmatch[1])) || sorterT(lmatch[2], rmatch[2]);
39
39
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nil-/doc",
3
- "version": "0.2.38",
3
+ "version": "0.2.39",
4
4
  "author": {
5
5
  "email": "njaldea@gmail.com",
6
6
  "name": "Neil Aldea"
@@ -10,11 +10,13 @@
10
10
  "@sveltejs/adapter-vercel": "^1.0.0",
11
11
  "@sveltejs/kit": "^1.0.1",
12
12
  "@sveltejs/package": "^1.0.1",
13
+ "@vitest/coverage-c8": "^0.26.3",
13
14
  "mdsvex": "^0.10.6",
14
15
  "svelte-check": "^2.10.3",
15
16
  "tslib": "^2.4.1",
16
17
  "typescript": "^4.9.4",
17
- "vite": "^4.0.3"
18
+ "vite": "^4.0.3",
19
+ "vitest": "^0.26.3"
18
20
  },
19
21
  "peerDependencies": {
20
22
  "svelte": "^3.55.0"
@@ -12,7 +12,7 @@ type Routes = {
12
12
  * Callback to navigate to other pages
13
13
  * @param e - event that contains detail about the target url
14
14
  */
15
- navigate: (e: CustomEvent<string>) => void;
15
+ navigate: (e: CustomEvent<string>) => Promise<void>;
16
16
  };
17
17
  /**
18
18
  * Dedicated helper method to be used for sveltekit