@nil-/doc 0.2.31 → 0.2.33
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 +3 -1
- package/components/block/Template.svelte +2 -2
- package/components/block/context.js +2 -2
- package/components/block/controls/Component.svelte +7 -7
- package/components/block/controls/Number.svelte +1 -1
- package/components/block/controls/Range.svelte +1 -1
- package/components/block/controls/Select.svelte +1 -1
- package/components/block/controls/Switch.svelte +1 -1
- package/components/block/controls/Text.svelte +1 -1
- package/components/block/controls/misc/GroupHeader.svelte +1 -1
- package/components/block/controls/misc/Styler.svelte +8 -0
- package/components/block/controls/misc/defaulter.d.ts +3 -3
- package/components/block/controls/misc/defaulter.js +25 -23
- package/components/block/controls/types.d.ts +11 -10
- package/components/block/utils.d.ts +1 -1
- package/components/block/utils.js +7 -6
- package/components/context.d.ts +4 -4
- package/components/context.js +10 -11
- package/components/etc/Container.svelte +9 -9
- package/components/etc/ThemeIcon.svelte +1 -1
- package/components/etc/action.js +13 -15
- package/components/navigation/Nav.svelte +16 -20
- package/components/navigation/Node.svelte +8 -8
- package/components/navigation/Node.svelte.d.ts +1 -1
- package/components/navigation/Tree.svelte +2 -2
- package/components/navigation/Tree.svelte.d.ts +1 -1
- package/components/navigation/utils.d.ts +1 -1
- package/components/navigation/utils.js +6 -8
- package/package.json +1 -2
- package/sveltekit/index.d.ts +1 -1
- package/sveltekit/index.js +25 -37
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @nil-/doc
|
|
2
2
|
|
|
3
|
+
## 0.2.33
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [doc] update formatting (camel case use) ([#49](https://github.com/njaldea/mono/pull/49))
|
|
8
|
+
|
|
9
|
+
## 0.2.32
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [doc] relaxed file extension for sveltekit helper ([#47](https://github.com/njaldea/mono/pull/47))
|
|
14
|
+
|
|
3
15
|
## 0.2.31
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/components/Layout.svelte
CHANGED
|
@@ -70,6 +70,8 @@
|
|
|
70
70
|
}
|
|
71
71
|
</style>
|
|
72
72
|
|
|
73
|
+
<script context="module">const defaultSorter = (l, r) => l.localeCompare(r);
|
|
74
|
+
</script>
|
|
73
75
|
<script>import Container from "./etc/Container.svelte";
|
|
74
76
|
import Nav from "./navigation/Nav.svelte";
|
|
75
77
|
import { inRoot, getTheme, initTheme, evalTheme } from "./context";
|
|
@@ -96,7 +98,7 @@ $:
|
|
|
96
98
|
<Nav
|
|
97
99
|
info={data}
|
|
98
100
|
selected={current ?? ""}
|
|
99
|
-
sorter={sorter ??
|
|
101
|
+
sorter={sorter ?? defaultSorter}
|
|
100
102
|
renamer={renamer ?? ((s) => s)}
|
|
101
103
|
on:navigate
|
|
102
104
|
/>
|
|
@@ -81,10 +81,10 @@ const isDark = getTheme();
|
|
|
81
81
|
export let defaults = void 0;
|
|
82
82
|
export let noreset = false;
|
|
83
83
|
export let columns = false;
|
|
84
|
-
|
|
84
|
+
const reset = () => {
|
|
85
85
|
$params = [];
|
|
86
86
|
$defaultsStore = defaults;
|
|
87
|
-
}
|
|
87
|
+
};
|
|
88
88
|
$:
|
|
89
89
|
$defaultsStore, reset();
|
|
90
90
|
let hovered = null;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { getContext, setContext } from "svelte";
|
|
2
2
|
import { writable } from "svelte/store";
|
|
3
|
-
|
|
3
|
+
const create = (defaulter) => {
|
|
4
4
|
const symbol = Symbol();
|
|
5
5
|
return {
|
|
6
6
|
init: () => setContext(symbol, writable(defaulter())),
|
|
7
7
|
get: () => getContext(symbol)
|
|
8
8
|
};
|
|
9
|
-
}
|
|
9
|
+
};
|
|
10
10
|
export const { init: initCurrent, get: getCurrent } = create(() => null);
|
|
11
11
|
export const { init: initParams, get: getParams } = create(() => []);
|
|
12
12
|
export const { init: initControls, get: getControls } = create(() => []);
|
|
@@ -11,18 +11,18 @@ export let info;
|
|
|
11
11
|
export let depth;
|
|
12
12
|
export let disabled = false;
|
|
13
13
|
</script>
|
|
14
|
-
{#if info.type
|
|
14
|
+
{#if "object" === info.type}
|
|
15
15
|
<Object {info} bind:value {depth} {disabled} />
|
|
16
|
-
{:else if info.type
|
|
16
|
+
{:else if "tuple" === info.type}
|
|
17
17
|
<Tuple {info} bind:value {depth} {disabled} />
|
|
18
|
-
{:else if info.type
|
|
18
|
+
{:else if "text" === info.type}
|
|
19
19
|
<Text {info} bind:value {depth} {disabled} />
|
|
20
|
-
{:else if info.type
|
|
20
|
+
{:else if "number" === info.type}
|
|
21
21
|
<Number {info} bind:value {depth} {disabled} />
|
|
22
|
-
{:else if info.type
|
|
22
|
+
{:else if "range" === info.type}
|
|
23
23
|
<Range {info} bind:value {depth} {disabled} />
|
|
24
|
-
{:else if info.type
|
|
24
|
+
{:else if "select" === info.type}
|
|
25
25
|
<Select {info} bind:value {depth} {disabled} />
|
|
26
|
-
{:else if info.type
|
|
26
|
+
{:else if "switch" === info.type}
|
|
27
27
|
<Switch {info} bind:value {depth} {disabled} />
|
|
28
28
|
{/if}
|
|
@@ -10,7 +10,7 @@ $:
|
|
|
10
10
|
value = enabled && !disabled ? ivalue : void 0;
|
|
11
11
|
</script>
|
|
12
12
|
<div>
|
|
13
|
-
<div style:padding-left={`${depth}px`}>- {info.name}</div>
|
|
13
|
+
<div style:padding-left={`${depth}px`} title={info.name}>- {info.name}</div>
|
|
14
14
|
<div><input type="number" bind:value={ivalue} disabled={!enabled || disabled} /></div>
|
|
15
15
|
<div><input type="checkbox" bind:checked={enabled} {disabled} /></div>
|
|
16
16
|
</div>
|
|
@@ -43,7 +43,7 @@ $:
|
|
|
43
43
|
value = enabled && !disabled ? ivalue : void 0;
|
|
44
44
|
</script>
|
|
45
45
|
<div>
|
|
46
|
-
<div style:padding-left={`${depth}px`}>- {info.name}</div>
|
|
46
|
+
<div style:padding-left={`${depth}px`} title={info.name}>- {info.name}</div>
|
|
47
47
|
<div class="input">
|
|
48
48
|
<div class="tooltip">
|
|
49
49
|
Current Value: {ivalue}
|
|
@@ -10,7 +10,7 @@ $:
|
|
|
10
10
|
value = enabled && !disabled ? ivalue : void 0;
|
|
11
11
|
</script>
|
|
12
12
|
<div>
|
|
13
|
-
<div style:padding-left={`${depth}px`}>- {info.name}</div>
|
|
13
|
+
<div style:padding-left={`${depth}px`} title={info.name}>- {info.name}</div>
|
|
14
14
|
<div>
|
|
15
15
|
<select bind:value={ivalue} disabled={!enabled || disabled}>
|
|
16
16
|
{#each info.values as value}
|
|
@@ -10,7 +10,7 @@ $:
|
|
|
10
10
|
value = enabled && !disabled ? ivalue : void 0;
|
|
11
11
|
</script>
|
|
12
12
|
<div>
|
|
13
|
-
<div style:padding-left={`${depth}px`}>- {info.name}</div>
|
|
13
|
+
<div style:padding-left={`${depth}px`} title={info.name}>- {info.name}</div>
|
|
14
14
|
<div><input type="checkbox" bind:checked={ivalue} disabled={!enabled || disabled} /></div>
|
|
15
15
|
<div><input type="checkbox" bind:checked={enabled} {disabled} /></div>
|
|
16
16
|
</div>
|
|
@@ -10,7 +10,7 @@ $:
|
|
|
10
10
|
value = ienabled && !disabled ? ivalue : void 0;
|
|
11
11
|
</script>
|
|
12
12
|
<div>
|
|
13
|
-
<div style:padding-left={`${depth}px`}>- {info.name}</div>
|
|
13
|
+
<div style:padding-left={`${depth}px`} title={info.name}>- {info.name}</div>
|
|
14
14
|
<div><input type="text" bind:value={ivalue} disabled={!ienabled || disabled} /></div>
|
|
15
15
|
<div><input type="checkbox" bind:checked={ienabled} {disabled} /></div>
|
|
16
16
|
</div>
|
|
@@ -47,6 +47,14 @@ const isDark = getTheme();
|
|
|
47
47
|
background-color: hsl(210, 100%, 90%);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
div > :global(div:nth-child(n + 2) > div:first-child) {
|
|
51
|
+
overflow: hidden;
|
|
52
|
+
white-space: nowrap;
|
|
53
|
+
text-overflow: ellipsis;
|
|
54
|
+
padding-right: 10px;
|
|
55
|
+
display: block;
|
|
56
|
+
}
|
|
57
|
+
|
|
50
58
|
div > :global(div:hover .tooltip) {
|
|
51
59
|
background-color: hsl(0, 0%, 100%);
|
|
52
60
|
outline: hsl(0, 100%, 0%) 1px solid;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ValueType } from "../../context";
|
|
2
2
|
import type { Control, ControlTuple, ControlObject } from "../types";
|
|
3
|
-
export declare
|
|
4
|
-
export declare
|
|
5
|
-
export declare
|
|
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,38 +1,40 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
for (const i of info.values) {
|
|
4
|
-
ret[i.name] = getDefault(i);
|
|
5
|
-
}
|
|
6
|
-
return ret;
|
|
7
|
-
}
|
|
8
|
-
export function getTupleDefaults(i) {
|
|
9
|
-
const ret = [];
|
|
10
|
-
for (const info of i.values) {
|
|
11
|
-
ret.push(getDefault(info));
|
|
12
|
-
}
|
|
13
|
-
return ret;
|
|
14
|
-
}
|
|
15
|
-
export function getDefault(i) {
|
|
16
|
-
if (i.type === "switch") {
|
|
1
|
+
export const getDefault = (i) => {
|
|
2
|
+
if ("switch" === i.type) {
|
|
17
3
|
return false;
|
|
18
4
|
}
|
|
19
|
-
if (i.type
|
|
5
|
+
if ("number" === i.type) {
|
|
20
6
|
return 0;
|
|
21
7
|
}
|
|
22
|
-
if (i.type
|
|
8
|
+
if ("range" === i.type) {
|
|
23
9
|
return i.min;
|
|
24
10
|
}
|
|
25
|
-
if (i.type
|
|
11
|
+
if ("text" === i.type) {
|
|
26
12
|
return "";
|
|
27
13
|
}
|
|
28
|
-
if (i.type
|
|
14
|
+
if ("select" === i.type) {
|
|
29
15
|
return i.values.length > 0 ? i.values[0] : "";
|
|
30
16
|
}
|
|
31
|
-
if (i.type
|
|
17
|
+
if ("tuple" === i.type) {
|
|
18
|
+
// eslint-disable-next-line no-use-before-define
|
|
32
19
|
return [...getTupleDefaults(i)];
|
|
33
20
|
}
|
|
34
|
-
if (i.type
|
|
21
|
+
if ("object" === i.type) {
|
|
22
|
+
// eslint-disable-next-line no-use-before-define
|
|
35
23
|
return getObjectDefaults(i);
|
|
36
24
|
}
|
|
37
25
|
return undefined;
|
|
38
|
-
}
|
|
26
|
+
};
|
|
27
|
+
export const getObjectDefaults = (info) => {
|
|
28
|
+
const ret = {};
|
|
29
|
+
for (const i of info.values) {
|
|
30
|
+
ret[i.name] = getDefault(i);
|
|
31
|
+
}
|
|
32
|
+
return ret;
|
|
33
|
+
};
|
|
34
|
+
export const getTupleDefaults = (i) => {
|
|
35
|
+
const ret = [];
|
|
36
|
+
for (const info of i.values) {
|
|
37
|
+
ret.push(getDefault(info));
|
|
38
|
+
}
|
|
39
|
+
return ret;
|
|
40
|
+
};
|
|
@@ -1,22 +1,14 @@
|
|
|
1
|
-
export type NonNamed<T> = Omit<T, "name">;
|
|
2
|
-
export type NonNamedControl =
|
|
3
|
-
| NonNamed<ControlTuple>
|
|
4
|
-
| NonNamed<ControlObject>
|
|
5
|
-
| NonNamed<ControlText>
|
|
6
|
-
| NonNamed<ControlNumber>
|
|
7
|
-
| NonNamed<ControlRange>
|
|
8
|
-
| NonNamed<ControlSelect>
|
|
9
|
-
| NonNamed<ControlSwitch>;
|
|
10
|
-
|
|
11
1
|
export type ControlTuple = {
|
|
12
2
|
name: string;
|
|
13
3
|
type: "tuple";
|
|
4
|
+
// eslint-disable-next-line no-use-before-define
|
|
14
5
|
values: NonNamedControl[];
|
|
15
6
|
};
|
|
16
7
|
|
|
17
8
|
export type ControlObject = {
|
|
18
9
|
name: string;
|
|
19
10
|
type: "object";
|
|
11
|
+
// eslint-disable-next-line no-use-before-define
|
|
20
12
|
values: Control[];
|
|
21
13
|
};
|
|
22
14
|
|
|
@@ -57,3 +49,12 @@ export type Control =
|
|
|
57
49
|
| ControlRange
|
|
58
50
|
| ControlSelect
|
|
59
51
|
| ControlSwitch;
|
|
52
|
+
|
|
53
|
+
type NonNamedControl =
|
|
54
|
+
| Omit<ControlTuple, "name">
|
|
55
|
+
| Omit<ControlObject, "name">
|
|
56
|
+
| Omit<ControlText, "name">
|
|
57
|
+
| Omit<ControlNumber, "name">
|
|
58
|
+
| Omit<ControlRange, "name">
|
|
59
|
+
| Omit<ControlSelect, "name">
|
|
60
|
+
| Omit<ControlSwitch, "name">;
|
|
@@ -2,5 +2,5 @@ import type { ValueType } from "./context";
|
|
|
2
2
|
type VTObject = {
|
|
3
3
|
[key: string]: ValueType;
|
|
4
4
|
};
|
|
5
|
-
export declare
|
|
5
|
+
export declare const resolve: <Args>(d: VTObject | undefined, p: VTObject) => Args;
|
|
6
6
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
const resolveArray = (d, p) => {
|
|
2
2
|
if (d === undefined) {
|
|
3
3
|
return undefined;
|
|
4
4
|
}
|
|
@@ -8,6 +8,7 @@ function resolveArray(d, p) {
|
|
|
8
8
|
ret.push(resolveArray(d[i], p[i] ?? []));
|
|
9
9
|
}
|
|
10
10
|
else if (d[i] instanceof Object) {
|
|
11
|
+
// eslint-disable-next-line no-use-before-define
|
|
11
12
|
ret.push(resolveObject(d[i], p[i] ?? {}));
|
|
12
13
|
}
|
|
13
14
|
else {
|
|
@@ -15,8 +16,8 @@ function resolveArray(d, p) {
|
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
18
|
return ret;
|
|
18
|
-
}
|
|
19
|
-
|
|
19
|
+
};
|
|
20
|
+
const resolveObject = (d, p) => {
|
|
20
21
|
if (d === undefined) {
|
|
21
22
|
return undefined;
|
|
22
23
|
}
|
|
@@ -33,7 +34,7 @@ function resolveObject(d, p) {
|
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
return ret;
|
|
36
|
-
}
|
|
37
|
-
export
|
|
37
|
+
};
|
|
38
|
+
export const resolve = (d, p) => {
|
|
38
39
|
return resolveObject(d ?? {}, p);
|
|
39
|
-
}
|
|
40
|
+
};
|
package/components/context.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Writable } from "svelte/store";
|
|
2
|
-
export declare
|
|
2
|
+
export declare const inRoot: () => boolean;
|
|
3
3
|
export type Theme = undefined | "light" | "dark";
|
|
4
|
-
export declare
|
|
5
|
-
export declare
|
|
6
|
-
export declare
|
|
4
|
+
export declare const getTheme: () => Writable<boolean>;
|
|
5
|
+
export declare const initTheme: () => Writable<boolean>;
|
|
6
|
+
export declare const evalTheme: (parent: boolean, theme: Theme) => boolean;
|
package/components/context.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { setContext, getContext } from "svelte";
|
|
2
2
|
import { writable } from "svelte/store";
|
|
3
3
|
const root = Symbol();
|
|
4
|
-
export
|
|
4
|
+
export const inRoot = () => {
|
|
5
5
|
const value = getContext(root);
|
|
6
6
|
setContext(root, false);
|
|
7
7
|
return value !== false;
|
|
8
|
-
}
|
|
8
|
+
};
|
|
9
9
|
const theme = Symbol();
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
10
|
+
export const getTheme = () => getContext(theme);
|
|
11
|
+
export const initTheme = () => setContext(theme, writable(true));
|
|
12
|
+
export const evalTheme = (parent, theme) => {
|
|
13
|
+
if (theme === undefined) {
|
|
14
|
+
return parent;
|
|
15
|
+
}
|
|
16
|
+
return "dark" === theme;
|
|
17
|
+
};
|
|
@@ -102,12 +102,12 @@ let height;
|
|
|
102
102
|
const { position, draggable } = createDraggable(offset);
|
|
103
103
|
$:
|
|
104
104
|
span = vertical ? width : height;
|
|
105
|
-
|
|
106
|
-
if (
|
|
105
|
+
const update = (limit, value) => {
|
|
106
|
+
if (null == span) {
|
|
107
107
|
return;
|
|
108
108
|
}
|
|
109
109
|
offset = Math.max(Math.min(value, span - limit), limit);
|
|
110
|
-
}
|
|
110
|
+
};
|
|
111
111
|
const off = tweened(offset, { duration: 50 });
|
|
112
112
|
let last = [];
|
|
113
113
|
$:
|
|
@@ -117,7 +117,7 @@ $:
|
|
|
117
117
|
$:
|
|
118
118
|
style = !secondary ? `auto 5px ${$off}px` : `${$off}px 5px auto`;
|
|
119
119
|
const moving = writable(false);
|
|
120
|
-
|
|
120
|
+
const addLast = (v) => {
|
|
121
121
|
if (v > 10) {
|
|
122
122
|
if (last.length < 2) {
|
|
123
123
|
last = [...last, v];
|
|
@@ -125,22 +125,22 @@ function addLast(v) {
|
|
|
125
125
|
last = [last[1], v];
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
|
-
}
|
|
129
|
-
|
|
128
|
+
};
|
|
129
|
+
const dbltap = () => {
|
|
130
130
|
if ($off > 10) {
|
|
131
131
|
addLast(offset);
|
|
132
132
|
offset = 10;
|
|
133
133
|
} else if (last.length > 0) {
|
|
134
134
|
offset = last.pop();
|
|
135
135
|
}
|
|
136
|
-
}
|
|
137
|
-
|
|
136
|
+
};
|
|
137
|
+
const check = (v, flag, s) => {
|
|
138
138
|
if (flag) {
|
|
139
139
|
return v < s - 10;
|
|
140
140
|
} else {
|
|
141
141
|
return v > 10;
|
|
142
142
|
}
|
|
143
|
-
}
|
|
143
|
+
};
|
|
144
144
|
</script>
|
|
145
145
|
<div
|
|
146
146
|
class="container"
|
package/components/etc/action.js
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import { get, writable } from "svelte/store";
|
|
2
2
|
export const createDraggable = (offset) => {
|
|
3
3
|
const position = writable(offset);
|
|
4
|
-
|
|
4
|
+
const draggable = (div, parameter) => {
|
|
5
5
|
let tm = new Date().getTime();
|
|
6
6
|
let param = parameter ?? { reset: () => 0, vertical: true, reversed: false };
|
|
7
7
|
position.set(param.reset());
|
|
8
|
-
let
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
function checkDoubleTap() {
|
|
8
|
+
let refPage = 0;
|
|
9
|
+
const disengage = () => param.moving.set(false);
|
|
10
|
+
const checkDoubleTap = () => {
|
|
13
11
|
const tm2 = new Date().getTime();
|
|
14
12
|
const diff = tm2 - tm;
|
|
15
13
|
tm = tm2;
|
|
16
14
|
return diff < 200;
|
|
17
|
-
}
|
|
18
|
-
|
|
15
|
+
};
|
|
16
|
+
const engage = (e) => {
|
|
19
17
|
if (checkDoubleTap()) {
|
|
20
18
|
param?.dbltap?.();
|
|
21
19
|
disengage();
|
|
@@ -23,16 +21,16 @@ export const createDraggable = (offset) => {
|
|
|
23
21
|
}
|
|
24
22
|
param.moving.set(true);
|
|
25
23
|
position.set(param.reset());
|
|
26
|
-
|
|
24
|
+
refPage = param.vertical ? e.pageX : e.pageY;
|
|
27
25
|
param?.tap?.();
|
|
28
|
-
}
|
|
29
|
-
|
|
26
|
+
};
|
|
27
|
+
const move = (e) => {
|
|
30
28
|
if (get(param.moving)) {
|
|
31
29
|
const page = param.vertical ? e.pageX : e.pageY;
|
|
32
|
-
position.update((v) => v + (page -
|
|
33
|
-
|
|
30
|
+
position.update((v) => v + (page - refPage) * (param.reversed ? -1 : 1));
|
|
31
|
+
refPage = page;
|
|
34
32
|
}
|
|
35
|
-
}
|
|
33
|
+
};
|
|
36
34
|
div.addEventListener("pointerdown", engage);
|
|
37
35
|
window.addEventListener("pointerup", disengage);
|
|
38
36
|
window.addEventListener("pointercancel", disengage);
|
|
@@ -48,7 +46,7 @@ export const createDraggable = (offset) => {
|
|
|
48
46
|
window.removeEventListener("pointermove", move);
|
|
49
47
|
}
|
|
50
48
|
};
|
|
51
|
-
}
|
|
49
|
+
};
|
|
52
50
|
return {
|
|
53
51
|
position,
|
|
54
52
|
draggable
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
}
|
|
26
26
|
</style>
|
|
27
27
|
|
|
28
|
-
<script context="module">
|
|
28
|
+
<script context="module">const apply = (paths, init, pre, next, post) => {
|
|
29
29
|
const retval = {};
|
|
30
30
|
for (const path of paths) {
|
|
31
31
|
const parts = path.split("/");
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
let t = retval;
|
|
36
36
|
for (let i = 1; i < parts.length; ++i) {
|
|
37
37
|
const part = parts[i];
|
|
38
|
-
if (t[part]
|
|
38
|
+
if (null == t[part]) {
|
|
39
39
|
t[part] = init();
|
|
40
40
|
}
|
|
41
41
|
if (i !== parts.length - 1) {
|
|
@@ -49,21 +49,17 @@
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
return retval;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
t.url = p;
|
|
64
|
-
}
|
|
65
|
-
);
|
|
66
|
-
}
|
|
52
|
+
};
|
|
53
|
+
const filt = (path, filter, renamer) => path.includes(filter) || path.split("/").map(renamer).join("/").includes(filter);
|
|
54
|
+
const populate = (filter, info, renamer) => apply(
|
|
55
|
+
filter.length > 0 ? info.filter((path) => filt(path, filter, renamer)) : info,
|
|
56
|
+
() => ({ url: null, sub: {} }),
|
|
57
|
+
(t) => t,
|
|
58
|
+
(t) => t.sub,
|
|
59
|
+
(t, p) => {
|
|
60
|
+
t.url = p;
|
|
61
|
+
}
|
|
62
|
+
);
|
|
67
63
|
</script>
|
|
68
64
|
<script>import Tree from "./Tree.svelte";
|
|
69
65
|
export let info;
|
|
@@ -77,7 +73,7 @@ let states = apply(
|
|
|
77
73
|
(t, path) => ({ expanded: t.expanded || selected === path, sub: t.sub }),
|
|
78
74
|
(t) => t.sub
|
|
79
75
|
);
|
|
80
|
-
|
|
76
|
+
const update = (selected2) => {
|
|
81
77
|
if (!info.includes(selected2)) {
|
|
82
78
|
return;
|
|
83
79
|
}
|
|
@@ -89,7 +85,7 @@ function update(selected2) {
|
|
|
89
85
|
}
|
|
90
86
|
node = node[p].sub;
|
|
91
87
|
}
|
|
92
|
-
}
|
|
88
|
+
};
|
|
93
89
|
$:
|
|
94
90
|
update(selected);
|
|
95
91
|
</script>
|
|
@@ -106,7 +102,7 @@ $:
|
|
|
106
102
|
{renamer}
|
|
107
103
|
bind:states
|
|
108
104
|
on:navigate
|
|
109
|
-
|
|
105
|
+
expand={filter.length > 0}
|
|
110
106
|
/>
|
|
111
107
|
</div>
|
|
112
108
|
</div>
|
|
@@ -49,7 +49,7 @@ export let key;
|
|
|
49
49
|
export let value;
|
|
50
50
|
export let depth;
|
|
51
51
|
export let selected;
|
|
52
|
-
export let
|
|
52
|
+
export let expand;
|
|
53
53
|
export let states;
|
|
54
54
|
export let sorter;
|
|
55
55
|
export let renamer;
|
|
@@ -57,14 +57,14 @@ const dispatch = createEventDispatcher();
|
|
|
57
57
|
$:
|
|
58
58
|
style = `padding-left: ${10 + depth * 10}px;`;
|
|
59
59
|
$:
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
hasChildren = Object.keys(value.sub).length > 0;
|
|
61
|
+
const click = (link) => {
|
|
62
62
|
if (link != null && selected !== link) {
|
|
63
63
|
dispatch("navigate", link);
|
|
64
|
-
} else if (
|
|
64
|
+
} else if (hasChildren) {
|
|
65
65
|
states.expanded = !states.expanded;
|
|
66
66
|
}
|
|
67
|
-
}
|
|
67
|
+
};
|
|
68
68
|
</script>
|
|
69
69
|
<div class="wrapper">
|
|
70
70
|
<div
|
|
@@ -74,12 +74,12 @@ function click(link) {
|
|
|
74
74
|
{style}
|
|
75
75
|
class:selected={selected === value.url}
|
|
76
76
|
>
|
|
77
|
-
<div class="icon" class:expanded={
|
|
77
|
+
<div class="icon" class:expanded={hasChildren && states.expanded}>
|
|
78
78
|
<div>{Object.keys(value.sub).length > 0 ? ">" : "-"}</div>
|
|
79
79
|
</div>
|
|
80
80
|
<span>{renamer(key)}</span>
|
|
81
81
|
</div>
|
|
82
|
-
{#if
|
|
82
|
+
{#if expand || states.expanded}
|
|
83
83
|
<div class="sub" transition:slide|local>
|
|
84
84
|
{#each sort(value.sub, sorter) as [k, v] (k)}
|
|
85
85
|
<svelte:self
|
|
@@ -89,7 +89,7 @@ function click(link) {
|
|
|
89
89
|
{selected}
|
|
90
90
|
{renamer}
|
|
91
91
|
{sorter}
|
|
92
|
-
{
|
|
92
|
+
{expand}
|
|
93
93
|
bind:states={states.sub[k]}
|
|
94
94
|
on:navigate
|
|
95
95
|
/>
|
|
@@ -5,7 +5,7 @@ export let tree;
|
|
|
5
5
|
export let states;
|
|
6
6
|
export let sorter;
|
|
7
7
|
export let renamer;
|
|
8
|
-
export let
|
|
8
|
+
export let expand;
|
|
9
9
|
export let selected;
|
|
10
10
|
</script>
|
|
11
11
|
{#each sort(tree, sorter) as [key, value] (key)}
|
|
@@ -16,7 +16,7 @@ export let selected;
|
|
|
16
16
|
{selected}
|
|
17
17
|
{sorter}
|
|
18
18
|
{renamer}
|
|
19
|
-
{
|
|
19
|
+
{expand}
|
|
20
20
|
bind:states={states[key]}
|
|
21
21
|
on:navigate
|
|
22
22
|
/>
|
|
@@ -23,5 +23,5 @@ declare const sorter: Sorter;
|
|
|
23
23
|
* @returns `<Name>`
|
|
24
24
|
*/
|
|
25
25
|
declare const renamer: Renamer;
|
|
26
|
-
export declare
|
|
26
|
+
export declare const sort: (t: Record<string, Tree>, order: (l: string, r: string) => 1 | 0 | -1) => [string, Tree][];
|
|
27
27
|
export { sorter, renamer };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const match = /(\d+)-(.+)/;
|
|
2
|
-
|
|
2
|
+
const sorterT = (l, r) => {
|
|
3
3
|
if (l < r) {
|
|
4
4
|
return -1;
|
|
5
5
|
}
|
|
@@ -7,7 +7,7 @@ function sorterT(l, r) {
|
|
|
7
7
|
return +1;
|
|
8
8
|
}
|
|
9
9
|
return 0;
|
|
10
|
-
}
|
|
10
|
+
};
|
|
11
11
|
/**
|
|
12
12
|
* Compares two texts for sorting.
|
|
13
13
|
*
|
|
@@ -26,13 +26,13 @@ function sorterT(l, r) {
|
|
|
26
26
|
const sorter = (l, r) => {
|
|
27
27
|
const lmatch = match.exec(l);
|
|
28
28
|
const rmatch = match.exec(r);
|
|
29
|
-
if (
|
|
29
|
+
if (null == lmatch && null == rmatch) {
|
|
30
30
|
return sorterT(l, r);
|
|
31
31
|
}
|
|
32
|
-
if (
|
|
32
|
+
if (null == lmatch) {
|
|
33
33
|
return 1;
|
|
34
34
|
}
|
|
35
|
-
if (
|
|
35
|
+
if (null == rmatch) {
|
|
36
36
|
return -1;
|
|
37
37
|
}
|
|
38
38
|
return sorterT(parseInt(lmatch[1]), parseInt(rmatch[1]));
|
|
@@ -51,7 +51,5 @@ const renamer = (text) => {
|
|
|
51
51
|
}
|
|
52
52
|
return text;
|
|
53
53
|
};
|
|
54
|
-
export
|
|
55
|
-
return Object.entries(t).sort(([l], [r]) => order(l, r));
|
|
56
|
-
}
|
|
54
|
+
export const sort = (t, order) => Object.entries(t).sort(([l], [r]) => order(l, r));
|
|
57
55
|
export { sorter, renamer };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nil-/doc",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.33",
|
|
4
4
|
"author": {
|
|
5
5
|
"email": "njaldea@gmail.com",
|
|
6
6
|
"name": "Neil Aldea"
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
"@sveltejs/package": "^1.0.1",
|
|
13
13
|
"mdsvex": "^0.10.6",
|
|
14
14
|
"svelte-check": "^2.10.3",
|
|
15
|
-
"svelte-markdown": "^0.2.3",
|
|
16
15
|
"tslib": "^2.4.1",
|
|
17
16
|
"typescript": "^4.9.4",
|
|
18
17
|
"vite": "^4.0.3"
|
package/sveltekit/index.d.ts
CHANGED
|
@@ -20,5 +20,5 @@ type Routes = {
|
|
|
20
20
|
* @param prefix - only use when layout is not in the root route
|
|
21
21
|
* @returns Routes
|
|
22
22
|
*/
|
|
23
|
-
export declare
|
|
23
|
+
export declare const sveltekit: (detail: Record<string, unknown>, prefix?: string | null) => Routes;
|
|
24
24
|
export {};
|
package/sveltekit/index.js
CHANGED
|
@@ -1,47 +1,35 @@
|
|
|
1
1
|
import { derived } from "svelte/store";
|
|
2
2
|
import { page } from "$app/stores";
|
|
3
3
|
import { goto } from "$app/navigation";
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
}
|
|
4
|
+
const toRoute = (p) => p.substring(1, p.lastIndexOf("/"));
|
|
5
|
+
const routeHasLayoutGroup = /\(.*\)/;
|
|
6
|
+
const collapseLayout = (p) => p
|
|
7
|
+
.split("/")
|
|
8
|
+
.filter((p) => null == routeHasLayoutGroup.exec(p))
|
|
9
|
+
.join("/");
|
|
10
|
+
const isNotRoot = (p) => p !== "/";
|
|
11
|
+
const routeIsDynamic = /.*\[.*\].*/;
|
|
12
|
+
const isRouteDynamic = (p) => null == routeIsDynamic.exec(p);
|
|
23
13
|
/**
|
|
24
14
|
* Dedicated helper method to be used for sveltekit
|
|
25
15
|
* @param detail - vite's `import.meta.glob(..., { eager: true })`
|
|
26
16
|
* @param prefix - only use when layout is not in the root route
|
|
27
17
|
* @returns Routes
|
|
28
18
|
*/
|
|
29
|
-
export
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
return collapseLayout($page.route.id.substring(prefix.length));
|
|
40
|
-
}
|
|
41
|
-
return collapseLayout($page.route.id);
|
|
19
|
+
export const sveltekit = (detail, prefix = null) => ({
|
|
20
|
+
data: Object.keys(detail)
|
|
21
|
+
.map(toRoute)
|
|
22
|
+
.map(collapseLayout)
|
|
23
|
+
.filter(isNotRoot)
|
|
24
|
+
.filter(isRouteDynamic),
|
|
25
|
+
current: derived(page, ($page) => {
|
|
26
|
+
if ($page.route.id) {
|
|
27
|
+
if (prefix) {
|
|
28
|
+
return collapseLayout($page.route.id.substring(prefix.length));
|
|
42
29
|
}
|
|
43
|
-
return
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
}
|
|
30
|
+
return collapseLayout($page.route.id);
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}),
|
|
34
|
+
navigate: prefix ? (e) => goto(`${prefix}${e.detail}`) : (e) => goto(e.detail)
|
|
35
|
+
});
|