@nil-/doc 0.2.37 → 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.
Files changed (38) hide show
  1. package/CHANGELOG.md +64 -54
  2. package/components/Layout.svelte +22 -4
  3. package/components/block/Block.svelte +3 -3
  4. package/components/block/Params.svelte.d.ts +1 -1
  5. package/components/block/Template.svelte +2 -6
  6. package/components/block/context.d.ts +2 -4
  7. package/components/block/controls/Controls.svelte.d.ts +1 -1
  8. package/components/block/controls/Object.svelte +5 -3
  9. package/components/block/controls/Object.svelte.d.ts +1 -1
  10. package/components/block/controls/Tuple.svelte +5 -3
  11. package/components/block/controls/Tuple.svelte.d.ts +1 -1
  12. package/components/block/controls/misc/Styler.svelte +1 -0
  13. package/components/block/controls/misc/defaulter.d.ts +10 -5
  14. package/components/block/controls/misc/defaulter.js +24 -28
  15. package/components/block/types.d.ts +9 -0
  16. package/components/block/utils.d.ts +3 -5
  17. package/components/block/utils.js +7 -13
  18. package/components/context.d.ts +0 -1
  19. package/components/context.js +1 -7
  20. package/components/etc/ThemeIcon.svelte +1 -7
  21. package/components/etc/action.js +3 -3
  22. package/components/navigation/Nav.svelte +21 -17
  23. package/components/navigation/Nav.svelte.d.ts +1 -3
  24. package/components/navigation/Node.svelte +2 -2
  25. package/components/navigation/Tree.svelte +1 -1
  26. package/components/navigation/types.d.ts +4 -4
  27. package/components/navigation/utils/fuzz.d.ts +1 -0
  28. package/components/navigation/utils/fuzz.js +119 -0
  29. package/components/navigation/utils/renamer.d.ts +9 -0
  30. package/components/navigation/utils/renamer.js +15 -0
  31. package/components/navigation/utils/sort.d.ts +2 -0
  32. package/components/navigation/utils/sort.js +3 -0
  33. package/components/navigation/{utils.d.ts → utils/sorter.d.ts} +2 -12
  34. package/components/navigation/{utils.js → utils/sorter.js} +2 -18
  35. package/index.d.ts +2 -1
  36. package/index.js +2 -1
  37. package/package.json +4 -2
  38. package/sveltekit/index.d.ts +1 -1
package/CHANGELOG.md CHANGED
@@ -1,30 +1,47 @@
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
+
17
+ ## 0.2.38
18
+
19
+ ### Patch Changes
20
+
21
+ - [doc][new] added fuzzy match for nav filter ([#59](https://github.com/njaldea/mono/pull/59))
22
+
3
23
  ## 0.2.37
4
24
 
5
25
  ### Patch Changes
6
26
 
7
27
  - [doc][fix] params prop is now reactive ([#57](https://github.com/njaldea/mono/pull/57))
8
- [doc] added component documentation link to deployment
9
- [doc] removed inRoot
10
-
11
- - [doc][cleanup] refactored Instance/Template/Params ([#57](https://github.com/njaldea/mono/pull/57))
28
+ - [doc][docu] added component documentation link to deployment ([#57](https://github.com/njaldea/mono/pull/57))
29
+ - [doc][patch] removed inRoot ([#57](https://github.com/njaldea/mono/pull/57))
30
+ - [doc][patch] refactored Instance/Template/Params ([#57](https://github.com/njaldea/mono/pull/57))
12
31
 
13
32
  ## 0.2.36
14
33
 
15
34
  ### Patch Changes
16
35
 
17
36
  - [doc][fix] color changes and transition ([#55](https://github.com/njaldea/mono/pull/55))
18
-
19
- - [all] added html meta details ([#55](https://github.com/njaldea/mono/pull/55))
37
+ - [doc][patch] added html meta details ([#55](https://github.com/njaldea/mono/pull/55))
20
38
 
21
39
  ## 0.2.35
22
40
 
23
41
  ### Patch Changes
24
42
 
25
- - [doc] changed Control "side" flag to "position" prop ([#53](https://github.com/njaldea/mono/pull/53))
26
-
27
- - [misc] added nil icon ([#53](https://github.com/njaldea/mono/pull/53))
43
+ - [doc][break] changed Control "side" flag to "position" prop ([#53](https://github.com/njaldea/mono/pull/53))
44
+ - [doc][new] added nil icon ([#53](https://github.com/njaldea/mono/pull/53))
28
45
 
29
46
  ## 0.2.34
30
47
 
@@ -38,21 +55,20 @@
38
55
 
39
56
  ### Patch Changes
40
57
 
41
- - [doc] update formatting (camel case use) ([#49](https://github.com/njaldea/mono/pull/49))
58
+ - [doc][patch] update formatting (camel case use) ([#49](https://github.com/njaldea/mono/pull/49))
42
59
 
43
60
  ## 0.2.32
44
61
 
45
62
  ### Patch Changes
46
63
 
47
- - [doc] relaxed file extension for sveltekit helper ([#47](https://github.com/njaldea/mono/pull/47))
64
+ - [doc][new] relaxed file extension for sveltekit helper ([#47](https://github.com/njaldea/mono/pull/47))
48
65
 
49
66
  ## 0.2.31
50
67
 
51
68
  ### Patch Changes
52
69
 
53
- - [doc] better container style ([#45](https://github.com/njaldea/mono/pull/45))
54
-
55
- - [doc] improved ThemeIcon ([#45](https://github.com/njaldea/mono/pull/45))
70
+ - [doc][patch] better container style ([#45](https://github.com/njaldea/mono/pull/45))
71
+ - [doc][patch] improved ThemeIcon ([#45](https://github.com/njaldea/mono/pull/45))
56
72
 
57
73
  ## 0.2.30
58
74
 
@@ -79,56 +95,56 @@
79
95
 
80
96
  ### Patch Changes
81
97
 
82
- - [doc] fix fira code css import ([#35](https://github.com/njaldea/mono/pull/35))
98
+ - [doc][fix] fix fira code css import ([#35](https://github.com/njaldea/mono/pull/35))
83
99
 
84
100
  ## 0.2.26
85
101
 
86
102
  ### Patch Changes
87
103
 
88
- - [doc] removed fallback page in documentation ([#30](https://github.com/njaldea/mono/pull/30))
104
+ - [doc][docu] removed fallback page in documentation ([#30](https://github.com/njaldea/mono/pull/30))
89
105
 
90
106
  ## 0.2.25
91
107
 
92
108
  ### Patch Changes
93
109
 
94
- - 186187c: [doc][breaking] removed layout slot prop for content. all unnamed slots will be part of the default slot
95
- - 186187c: [doc] fix range tooltip styling
96
- - a82c0de: [doc] support dark/light mode
110
+ - 186187c: [doc][new] removed layout slot prop for content. all unnamed slots will be part of the default slot
111
+ - 186187c: [doc][fix] fix range tooltip styling
112
+ - a82c0de: [doc][new] support dark/light mode
97
113
 
98
114
  ## 0.2.24
99
115
 
100
116
  ### Patch Changes
101
117
 
102
- - 782e6fa: [doc][breaking] simplified sveltekit glue layer
103
- - 782e6fa: [doc] added documentation to public methods
118
+ - 782e6fa: [doc][new] simplified sveltekit glue layer
119
+ - 782e6fa: [doc][docu] added documentation to public methods
104
120
 
105
121
  ## 0.2.23
106
122
 
107
123
  ### Patch Changes
108
124
 
109
- - 5655f86: [feature] added slot prop `key` to Template component
110
- - 5655f86: [Dependencies] moved some devDependencies to peerDependencies
125
+ - 5655f86: [doc][new] added slot prop `key` to Template component
126
+ - 5655f86: [doc][patch] moved some devDependencies to peerDependencies
111
127
 
112
128
  ## 0.2.22
113
129
 
114
130
  ### Patch Changes
115
131
 
116
- - 3ce0a62: [doc] support for touch event via pointerevent (draggable container)
132
+ - 3ce0a62: [doc][new] support for touch event via pointerevent (draggable container)
117
133
 
118
134
  ## 0.2.21
119
135
 
120
136
  ### Patch Changes
121
137
 
122
138
  - 0398a72: [doc][fix] remove dependency on box-sizing
123
- [doc][fix] control min width
124
- [doc][feature] made template configurable by column prop
139
+ - 0398a72: [doc][fix] control min width
140
+ - 0398a72: [doc][new] made template configurable by column prop
125
141
 
126
142
  ## 0.2.20
127
143
 
128
144
  ### Patch Changes
129
145
 
130
146
  - 3eee0ce: [doc][fix] removed setting of margin/padding
131
- [doc][fix] only propagate box-sizing (inherit)
147
+ - 3eee0ce: [doc][fix] only propagate box-sizing (inherit)
132
148
 
133
149
  ## 0.2.19
134
150
 
@@ -146,68 +162,62 @@
146
162
 
147
163
  ### Patch Changes
148
164
 
149
- - af86341: [doc] moved default mapping in a common lib
150
- [doc] fix typing
151
- [doc] if Param's tag is not provided, use stringified id
165
+ - af86341: [doc][fix] moved default mapping in a common lib
166
+ - af86341: [doc][fix] fix typing
167
+ - af86341: [doc][patch] if Param's tag is not provided, use stringified id
152
168
 
153
169
  ## 0.2.16
154
170
 
155
171
  ### Patch Changes
156
172
 
157
- - 650eb4b: [doc] revived proper ordering of params
158
- [doc] each param now has its own defaults (which is resolved from template's default and pram's props)
173
+ - 650eb4b: [doc][fix] revived proper ordering of params
174
+ - 650eb4b: [doc][new] each param now has its own defaults (which is resolved from template's default and pram's props)
159
175
 
160
176
  ## 0.2.15
161
177
 
162
178
  ### Patch Changes
163
179
 
164
- - 44a7113: [doc] added documentation for internal Container
165
- [doc] adjusted api for load (now `routes`)
166
- [doc] fix for layout group route
180
+ - 44a7113: [doc][docu] added documentation for internal Container
181
+ - 44a7113: [doc][new] adjusted api for load (now `routes`)
182
+ - 44a7113: [doc][fix] fix for layout group route
167
183
 
168
184
  ## 0.2.14
169
185
 
170
186
  ### Patch Changes
171
187
 
172
- - 6265fa6: [doc] added Tuple and Object Controls
173
- [doc] added temporary internal doc
188
+ - 6265fa6: [doc][new] added Tuple and Object Controls
189
+ - 6265fa6: [doc][docu] added temporary internal doc
174
190
 
175
191
  ## 0.2.13
176
192
 
177
193
  ### Patch Changes
178
194
 
179
- - 39dbce9: [doc] navigation now automatically opens when redirected to a route that is still collapsed
195
+ - 39dbce9: [doc][new] navigation now automatically opens when redirected to a route that is still collapsed
180
196
 
181
197
  ## 0.2.12
182
198
 
183
199
  ### Patch Changes
184
200
 
185
- - 6c2d946: [fix] Nav now is not scrollable
186
- [fix] Removes Container's "reversed" flag
187
- [fix] Adds "secondary" flag to Container
188
- [fix] Changes Container slot name (primary is top or left, seconadry is bottom or right)
189
- [fix] load now removes routes with parameters
190
- [fix] Template now supports `noreset`
191
- [fix] Updates documentation
192
-
193
- ## 0.2.11
194
-
195
- ### Patch Changes
196
-
197
- - 8d16322: noop
201
+ - 6c2d946: [doc][fix] Nav now is not scrollable
202
+ - 6c2d946: [doc][fix] Removes Container's "reversed" flag
203
+ - 6c2d946: [doc][fix] Adds "secondary" flag to Container
204
+ - 6c2d946: [doc][fix] Changes Container slot name (primary is top or left, seconadry is bottom or right)
205
+ - 6c2d946: [doc][fix] load now removes routes with parameters
206
+ - 6c2d946: [doc][fix] Template now supports `noreset`
207
+ - 6c2d946: [doc][fix] Updates documentation
198
208
 
199
209
  ## 0.2.10
200
210
 
201
211
  ### Patch Changes
202
212
 
203
- - c6de380: [feature] container collapsing now supported
204
- [cleanup] styling of container now uses grid for easier handling
213
+ - c6de380: [doc][new] container collapsing now supported
214
+ - c6de380: [doc][patch] styling of container now uses grid for easier handling
205
215
 
206
216
  ## 0.2.9
207
217
 
208
218
  ### Patch Changes
209
219
 
210
- - 5c10f11: [fix] layout fill height
220
+ - 5c10f11: [doc][patch] layout fill height
211
221
 
212
222
  ## 0.2.8
213
223
 
@@ -27,6 +27,16 @@
27
27
  overflow: hidden;
28
28
  }
29
29
 
30
+ .icon {
31
+ width: 100%;
32
+ height: 100%;
33
+ transition: transform 350ms;
34
+ }
35
+
36
+ .icon:hover {
37
+ transform: scale(1.5);
38
+ }
39
+
30
40
  .content {
31
41
  height: 100%;
32
42
  padding: 5px;
@@ -74,7 +84,7 @@
74
84
  </script>
75
85
  <script>import Container from "./etc/Container.svelte";
76
86
  import Nav from "./navigation/Nav.svelte";
77
- import { getTheme, initTheme, evalTheme } from "./context";
87
+ import { getTheme, initTheme } from "./context";
78
88
  import ThemeIcon from "./etc/ThemeIcon.svelte";
79
89
  import NilIcon from "./etc/NilIcon.svelte";
80
90
  export let data;
@@ -85,7 +95,7 @@ export let theme = void 0;
85
95
  const parentTheme = getTheme();
86
96
  const dark = initTheme();
87
97
  $:
88
- $dark = evalTheme(parentTheme ? $parentTheme : true, theme);
98
+ $dark = theme === void 0 ? $parentTheme : "dark" === theme;
89
99
  </script>
90
100
  <!--
91
101
  @component
@@ -94,8 +104,16 @@ $:
94
104
  <div class="layout" class:dark={$dark}>
95
105
  <div class="top">
96
106
  <slot name="title"><span>@nil-/doc</span></slot>
97
- <ThemeIcon bind:dark={$dark} />
98
- <NilIcon />
107
+ <div class="icon" on:click={() => ($dark = !$dark)} on:keypress={null}>
108
+ <ThemeIcon bind:dark={$dark} />
109
+ </div>
110
+ <div
111
+ class="icon"
112
+ title="Double click to open repo: https://github.com/njaldea/mono"
113
+ on:dblclick={() => window.open("https://github.com/njaldea/mono", "_blank")}
114
+ >
115
+ <NilIcon />
116
+ </div>
99
117
  </div>
100
118
  <div class="main">
101
119
  <Container offset={250} vertical b>
@@ -10,7 +10,7 @@
10
10
 
11
11
  box-sizing: border-box;
12
12
  font-family: "Fira Code", "Courier New", Courier, monospace;
13
- padding: 3px;
13
+ padding: 13px 3px;
14
14
  gap: 3px;
15
15
  }
16
16
 
@@ -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,10 +1,6 @@
1
1
 
2
2
  <script>import { beforeUpdate } from "svelte";
3
- import {
4
- getDefaults,
5
- getParams,
6
- getOrientation
7
- } from "./context";
3
+ import { getDefaults, getParams, getOrientation } from "./context";
8
4
  import { resolve } from "./utils";
9
5
  import Instance from "./Instance.svelte";
10
6
  const params = getParams();
@@ -17,9 +13,9 @@ $:
17
13
  $defaultsStore = defaults ?? {};
18
14
  $:
19
15
  $orientation = columns;
20
- const resolveArgs = resolve;
21
16
  let key = false;
22
17
  beforeUpdate(() => key = !key);
18
+ const resolveArgs = resolve;
23
19
  const cast = (t) => t;
24
20
  </script>
25
21
  <!--
@@ -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;
@@ -36,6 +36,7 @@ const dark = getTheme();
36
36
 
37
37
  /* colors */
38
38
  div > :global(div) {
39
+ transition: background-color 350ms;
39
40
  background-color: hsl(0, 0%, 100%);
40
41
  }
41
42
 
@@ -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
- };
@@ -44,13 +44,7 @@ const vdark = {
44
44
  v: 1
45
45
  };
46
46
  </script>
47
- <svg
48
- class:dark
49
- viewBox="-25 -25 50 50"
50
- transform={`rotate(${$values.rotate})`}
51
- on:click={() => (dark = !dark)}
52
- on:keypress={null}
53
- >
47
+ <svg class:dark viewBox="-25 -25 50 50" transform={`rotate(${$values.rotate})`}>
54
48
  <mask id={`nil_doc_theme_icon_${index}`}>
55
49
  <rect x="-25" y="-25" fill="white" />
56
50
  <circle cy={$values.mcy} r="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)) {
@@ -3,20 +3,22 @@
3
3
  width: 100%;
4
4
  height: 100%;
5
5
  min-width: 200px;
6
- gap: 10px;
7
6
  display: flex;
8
7
  flex-direction: column;
9
8
  }
10
9
 
11
- .logo,
12
10
  .search-bar {
13
- padding-left: 20px;
14
- padding-right: 20px;
11
+ padding: 5px;
15
12
  }
16
13
 
17
14
  input {
18
- height: 20px;
15
+ height: 30px;
19
16
  width: 100%;
17
+ padding: 0px 10px;
18
+ }
19
+
20
+ input:focus {
21
+ outline: none;
20
22
  }
21
23
 
22
24
  * {
@@ -26,7 +28,8 @@
26
28
  }
27
29
  </style>
28
30
 
29
- <script context="module">const apply = (paths, init, pre, next, post) => {
31
+ <script context="module">import { fuzz } from "./utils/fuzz";
32
+ const apply = (paths, init, pre, next, post) => {
30
33
  const retval = {};
31
34
  for (const path of paths) {
32
35
  const parts = path.split("/");
@@ -51,16 +54,18 @@
51
54
  }
52
55
  return retval;
53
56
  };
54
- const filt = (path, filter, renamer) => path.includes(filter) || path.split("/").map(renamer).join("/").includes(filter);
55
- const populate = (filter, info, renamer) => apply(
56
- filter.length > 0 ? info.filter((path) => filt(path, filter, renamer)) : info,
57
- () => ({ url: null, sub: {} }),
58
- (t) => t,
59
- (t) => t.sub,
60
- (t, p) => {
61
- t.url = p;
62
- }
63
- );
57
+ const filt = (path, filter, renamer) => {
58
+ return fuzz(path, filter) || fuzz(path.split("/").map(renamer).join("/"), filter);
59
+ };
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
+ };
64
69
  </script>
65
70
  <script>import Tree from "./Tree.svelte";
66
71
  export let info;
@@ -91,7 +96,6 @@ $:
91
96
  update(selected);
92
97
  </script>
93
98
  <div class="nav">
94
- <div class="logo"><slot /></div>
95
99
  <div class="search-bar">
96
100
  <input bind:value={filter} type="text" />
97
101
  </div>
@@ -12,9 +12,7 @@ declare const __propDef: {
12
12
  } & {
13
13
  [evt: string]: CustomEvent<any>;
14
14
  };
15
- slots: {
16
- default: {};
17
- };
15
+ slots: {};
18
16
  };
19
17
  export type NavProps = typeof __propDef.props;
20
18
  export type NavEvents = typeof __propDef.events;
@@ -43,7 +43,7 @@
43
43
  </style>
44
44
 
45
45
  <script>import { slide } from "svelte/transition";
46
- import { sort } from "./utils";
46
+ import { sort } from "./utils/sort";
47
47
  import { createEventDispatcher } from "svelte";
48
48
  export let key;
49
49
  export let value;
@@ -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,6 +1,6 @@
1
1
 
2
2
  <script>import Node from "./Node.svelte";
3
- import { sort } from "./utils";
3
+ import { sort } from "./utils/sort";
4
4
  export let tree;
5
5
  export let states;
6
6
  export let sorter;
@@ -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;
@@ -0,0 +1 @@
1
+ export declare const fuzz: (target: string, query: string) => boolean;
@@ -0,0 +1,119 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ * See License.txt in https://github.com/microsoft/vscode/blob/main/LICENSE.txt
5
+ *--------------------------------------------------------------------------------------------*/
6
+ /*
7
+ * This implementation is inspired by:
8
+ * https://github.com/microsoft/vscode/blob/main/src/vs/base/common/fuzzyScorer.ts
9
+ *
10
+ * It is simplified to fit the use case for @nil-/doc
11
+ */
12
+ const isUpper = (code) => {
13
+ // A == 65
14
+ // Z == 90
15
+ return 65 <= code && code <= 90;
16
+ };
17
+ const scoreSeparatorAtPos = (charCode) => {
18
+ switch (charCode) {
19
+ case 47: // Slash
20
+ // prefer path separators...
21
+ return 5;
22
+ case 95: // Underline
23
+ case 45: // Dash
24
+ case 46: // Period
25
+ case 32: // Space
26
+ case 58: // Colon:
27
+ // ...over other separators
28
+ return 4;
29
+ default:
30
+ return 0;
31
+ }
32
+ };
33
+ const computeCharScore = (queryCharAtIndex, queryLowerCharAtIndex, target, targetLower, targetIndex, matchesSequenceLength) => {
34
+ let score = 0;
35
+ if (queryLowerCharAtIndex !== targetLower[targetIndex]) {
36
+ // no match of characters
37
+ return score;
38
+ }
39
+ // Character match bonus
40
+ score += 1;
41
+ // Consecutive match bonus
42
+ if (matchesSequenceLength > 0) {
43
+ score += matchesSequenceLength * 5;
44
+ }
45
+ // Same case bonus
46
+ if (queryCharAtIndex === target[targetIndex]) {
47
+ score += 1;
48
+ }
49
+ // Start of word bonus
50
+ if (0 === targetIndex) {
51
+ score += 8;
52
+ }
53
+ else {
54
+ const separatorBonus = scoreSeparatorAtPos(target.charCodeAt(targetIndex - 1));
55
+ if (separatorBonus) {
56
+ score += separatorBonus;
57
+ }
58
+ else if (isUpper(target.charCodeAt(targetIndex)) && 0 === matchesSequenceLength) {
59
+ score += 2;
60
+ }
61
+ }
62
+ return score;
63
+ };
64
+ const doScoreFuzzy = (query, queryLower, queryLength, target, targetLower, targetLength) => {
65
+ const scores = [];
66
+ const matches = [];
67
+ for (let queryIndex = 0; queryIndex < queryLength; queryIndex++) {
68
+ const queryIndexOffset = queryIndex * targetLength;
69
+ const queryIndexPreviousOffset = queryIndexOffset - targetLength;
70
+ const queryIndexGtNull = queryIndex > 0;
71
+ const queryCharAtIndex = query[queryIndex];
72
+ const queryLowerCharAtIndex = queryLower[queryIndex];
73
+ for (let targetIndex = 0; targetIndex < targetLength; targetIndex++) {
74
+ const targetIndexGtNull = targetIndex > 0;
75
+ const currentIndex = queryIndexOffset + targetIndex;
76
+ const leftIndex = currentIndex - 1;
77
+ const diagIndex = queryIndexPreviousOffset + targetIndex - 1;
78
+ const leftScore = targetIndexGtNull ? scores[leftIndex] : 0;
79
+ const diagScore = queryIndexGtNull && targetIndexGtNull ? scores[diagIndex] : 0;
80
+ const matchesSequenceLength = queryIndexGtNull && targetIndexGtNull ? matches[diagIndex] : 0;
81
+ const score = !diagScore && queryIndexGtNull
82
+ ? 0
83
+ : computeCharScore(queryCharAtIndex, queryLowerCharAtIndex, target, targetLower, targetIndex, matchesSequenceLength);
84
+ const isValidScore = score && diagScore + score >= leftScore;
85
+ if (isValidScore) {
86
+ matches[currentIndex] = matchesSequenceLength + 1;
87
+ scores[currentIndex] = diagScore + score;
88
+ }
89
+ else {
90
+ matches[currentIndex] = 0;
91
+ scores[currentIndex] = leftScore;
92
+ }
93
+ }
94
+ }
95
+ const positions = [];
96
+ let queryIndex = queryLength - 1;
97
+ let targetIndex = targetLength - 1;
98
+ while (queryIndex >= 0 && targetIndex >= 0) {
99
+ const currentIndex = queryIndex * targetLength + targetIndex;
100
+ const match = matches[currentIndex];
101
+ if (0 === match) {
102
+ targetIndex--;
103
+ }
104
+ else {
105
+ positions.push(targetIndex);
106
+ queryIndex--;
107
+ targetIndex--;
108
+ }
109
+ }
110
+ return [scores[queryLength * targetLength - 1], positions.reverse()];
111
+ };
112
+ export const fuzz = (target, query) => {
113
+ const targetLength = target.length;
114
+ const queryLength = query.length;
115
+ if (targetLength < queryLength) {
116
+ return false;
117
+ }
118
+ return (doScoreFuzzy(query, query.toLowerCase(), queryLength, target, target.toLowerCase(), targetLength)[0] > 0);
119
+ };
@@ -0,0 +1,9 @@
1
+ import type { Renamer } from "../types";
2
+ /**
3
+ * If a text follows `<I>-<Name>` format,
4
+ * this method simply removes the Prefix.
5
+ *
6
+ * @param text
7
+ * @returns `<Name>`
8
+ */
9
+ export declare const renamer: Renamer;
@@ -0,0 +1,15 @@
1
+ const match = /(\d+)-(.+)/;
2
+ /**
3
+ * If a text follows `<I>-<Name>` format,
4
+ * this method simply removes the Prefix.
5
+ *
6
+ * @param text
7
+ * @returns `<Name>`
8
+ */
9
+ export const renamer = (text) => {
10
+ const m = match.exec(text);
11
+ if (m) {
12
+ return m[2];
13
+ }
14
+ return text;
15
+ };
@@ -0,0 +1,2 @@
1
+ import type { Tree } from "../types";
2
+ export declare const sort: (t: Record<string, Tree>, order: (l: string, r: string) => 1 | 0 | -1) => [string, Tree][];
@@ -0,0 +1,3 @@
1
+ export const sort = (t, order) => {
2
+ return Object.entries(t).sort(([l], [r]) => order(l, r));
3
+ };
@@ -1,4 +1,4 @@
1
- import type { Tree, Sorter, Renamer } from "./types";
1
+ import type { Sorter } from "../types";
2
2
  /**
3
3
  * Compares two texts for sorting.
4
4
  *
@@ -14,14 +14,4 @@ import type { Tree, Sorter, Renamer } from "./types";
14
14
  * @param r - right operand
15
15
  * @returns `-1 | 0 | +1`
16
16
  */
17
- declare const sorter: Sorter;
18
- /**
19
- * If a text follows `<I>-<Name>` format,
20
- * this method simply removes the Prefix.
21
- *
22
- * @param text
23
- * @returns `<Name>`
24
- */
25
- declare const renamer: Renamer;
26
- export declare const sort: (t: Record<string, Tree>, order: (l: string, r: string) => 1 | 0 | -1) => [string, Tree][];
27
- export { sorter, renamer };
17
+ export declare const sorter: Sorter;
@@ -23,7 +23,7 @@ const sorterT = (l, r) => {
23
23
  * @param r - right operand
24
24
  * @returns `-1 | 0 | +1`
25
25
  */
26
- const sorter = (l, r) => {
26
+ export const sorter = (l, r) => {
27
27
  const lmatch = match.exec(l);
28
28
  const rmatch = match.exec(r);
29
29
  if (null == lmatch && null == rmatch) {
@@ -35,21 +35,5 @@ 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
  };
40
- /**
41
- * If a text follows `<I>-<Name>` format,
42
- * this method simply removes the Prefix.
43
- *
44
- * @param text
45
- * @returns `<Name>`
46
- */
47
- const renamer = (text) => {
48
- const m = match.exec(text);
49
- if (m) {
50
- return m[2];
51
- }
52
- return text;
53
- };
54
- export const sort = (t, order) => Object.entries(t).sort(([l], [r]) => order(l, r));
55
- export { sorter, renamer };
package/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export { renamer, sorter } from "./components/navigation/utils";
1
+ export { renamer } from "./components/navigation/utils/renamer";
2
+ export { sorter } from "./components/navigation/utils/sorter";
2
3
  export type { Control } from "./components/block/controls/types";
3
4
  export { default as Layout } from "./components/Layout.svelte";
4
5
  export { default as Instance } from "./components/block/Instance.svelte";
package/index.js CHANGED
@@ -1,4 +1,5 @@
1
- export { renamer, sorter } from "./components/navigation/utils";
1
+ export { renamer } from "./components/navigation/utils/renamer";
2
+ export { sorter } from "./components/navigation/utils/sorter";
2
3
  export { default as Layout } from "./components/Layout.svelte";
3
4
  export { default as Instance } from "./components/block/Instance.svelte";
4
5
  export { default as Block } from "./components/block/Block.svelte";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nil-/doc",
3
- "version": "0.2.37",
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