@nil-/doc 0.2.15 → 0.2.16
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 +7 -0
- package/components/block/Block.svelte +3 -2
- package/components/block/Controls.svelte +6 -2
- package/components/block/Controls.svelte.d.ts +1 -0
- package/components/block/Params.svelte +19 -6
- package/components/block/Template.svelte +20 -25
- package/components/block/Template.svelte.d.ts +3 -3
- package/components/block/context.d.ts +13 -4
- package/components/block/context.js +4 -1
- package/components/block/controls/Controls.svelte +1 -0
- package/components/block/controls/Controls.svelte.d.ts +1 -2
- package/components/block/controls/misc/Styler.svelte +4 -0
- package/components/block/utils.d.ts +1 -0
- package/components/block/utils.js +40 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
<script>import { initCurrent,
|
|
1
|
+
<script>import { initParams, initCurrent, initDefaults, initControls, initControlsState } from "./context";
|
|
2
2
|
import { inRoot } from "../context";
|
|
3
3
|
initParams();
|
|
4
4
|
initCurrent();
|
|
5
|
-
initControls();
|
|
6
5
|
initDefaults();
|
|
6
|
+
initControls();
|
|
7
|
+
initControlsState();
|
|
7
8
|
const r = inRoot();
|
|
8
9
|
</script>
|
|
9
10
|
<style>
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
|
|
2
|
-
<script>import { getControls } from "./context";
|
|
2
|
+
<script>import { getControls, getControlsState } from "./context";
|
|
3
3
|
export let props = [];
|
|
4
|
-
|
|
4
|
+
export let expand = false;
|
|
5
|
+
const controls = getControls();
|
|
6
|
+
$controls = props;
|
|
7
|
+
const state = getControlsState();
|
|
8
|
+
$: $state.expand = expand;
|
|
5
9
|
</script>
|
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
|
|
2
|
-
<script>import {
|
|
2
|
+
<script>import { onMount } from "svelte";
|
|
3
|
+
import { getParams, getDefaults } from "./context";
|
|
4
|
+
import { resolve } from "./utils";
|
|
3
5
|
export let tag;
|
|
4
6
|
export let props = {};
|
|
5
7
|
const defaults = getDefaults();
|
|
6
8
|
const params = getParams();
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
|
|
9
|
+
onMount(() => defaults.subscribe((d) => {
|
|
10
|
+
if (d != null) {
|
|
11
|
+
params.update((p) => {
|
|
12
|
+
const v = [
|
|
13
|
+
...p,
|
|
14
|
+
{
|
|
15
|
+
id: p.length,
|
|
16
|
+
tag,
|
|
17
|
+
values: resolve(d, props),
|
|
18
|
+
defaults: resolve(d, props)
|
|
19
|
+
}
|
|
20
|
+
];
|
|
21
|
+
console.log(v);
|
|
22
|
+
return v;
|
|
23
|
+
});
|
|
10
24
|
}
|
|
11
|
-
}
|
|
12
|
-
$: set(tag, props);
|
|
25
|
+
}));
|
|
13
26
|
</script>
|
|
@@ -33,30 +33,25 @@
|
|
|
33
33
|
</style>
|
|
34
34
|
<svelte:window on:click={() => ($current = null)} />
|
|
35
35
|
|
|
36
|
-
<script>import {
|
|
37
|
-
import {
|
|
36
|
+
<script>import { getParams, getCurrent, getDefaults } from "./context";
|
|
37
|
+
import { getControls, getControlsState } from "./context";
|
|
38
|
+
import { resolve } from "./utils";
|
|
38
39
|
import Controls from "./controls/Controls.svelte";
|
|
40
|
+
import { beforeUpdate } from "svelte";
|
|
39
41
|
import { slide } from "svelte/transition";
|
|
40
42
|
const params = getParams();
|
|
41
43
|
const current = getCurrent();
|
|
42
44
|
const controls = getControls();
|
|
43
|
-
|
|
44
|
-
getDefaults()
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const temporary = { ...d };
|
|
51
|
-
for (const key of keys) {
|
|
52
|
-
if (key in p && p[key] !== undefined) {
|
|
53
|
-
temporary[key] = p[key];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return temporary;
|
|
45
|
+
const controlsState = getControlsState();
|
|
46
|
+
const defaultsStore = getDefaults();
|
|
47
|
+
export let defaults = undefined;
|
|
48
|
+
export let noreset = false;
|
|
49
|
+
function reset() {
|
|
50
|
+
$params = [];
|
|
51
|
+
$defaultsStore = defaults;
|
|
57
52
|
}
|
|
53
|
+
$: $defaultsStore, reset();
|
|
58
54
|
let hovered = null;
|
|
59
|
-
export let noreset = false;
|
|
60
55
|
/**
|
|
61
56
|
* This flag is to rerender the whole slot component.
|
|
62
57
|
* If the control is disabled, we use the default value provided from the defaults field.
|
|
@@ -72,28 +67,28 @@ let key = false;
|
|
|
72
67
|
beforeUpdate(() => (key = !key));
|
|
73
68
|
</script>
|
|
74
69
|
<div class="template">
|
|
75
|
-
{#each
|
|
70
|
+
{#each $params as param (param.id)}
|
|
76
71
|
<div
|
|
77
72
|
class="instance"
|
|
78
|
-
on:click|stopPropagation={() => ($current =
|
|
79
|
-
on:mouseenter={() => (hovered =
|
|
73
|
+
on:click|stopPropagation={() => ($current = param.id)}
|
|
74
|
+
on:mouseenter={() => (hovered = param.id)}
|
|
80
75
|
on:mouseleave={() => (hovered = null)}
|
|
81
76
|
on:keypress={null}
|
|
82
77
|
>
|
|
83
78
|
{#if noreset}
|
|
84
79
|
<div class="content nil-doc-scrollable">
|
|
85
|
-
<slot {tag} props={resolve(defaults,
|
|
80
|
+
<slot tag={param.tag} props={resolve(param.defaults, param.values)} />
|
|
86
81
|
</div>
|
|
87
82
|
{:else}
|
|
88
83
|
{#key key}
|
|
89
84
|
<div class="content nil-doc-scrollable">
|
|
90
|
-
<slot {tag} props={resolve(defaults,
|
|
85
|
+
<slot tag={param.tag} props={resolve(param.defaults, param.values)} />
|
|
91
86
|
</div>
|
|
92
87
|
{/key}
|
|
93
88
|
{/if}
|
|
94
|
-
{#if $controls.length > 0 && ($current ===
|
|
95
|
-
<div class="misc nil-doc-scrollable" transition:slide>
|
|
96
|
-
<Controls infos={$controls} bind:values={
|
|
89
|
+
{#if $controls.length > 0 && ($controlsState.expand || $current === param.id || hovered === param.id)}
|
|
90
|
+
<div class="misc nil-doc-scrollable" transition:slide|local>
|
|
91
|
+
<Controls infos={$controls} bind:values={param.values} />
|
|
97
92
|
</div>
|
|
98
93
|
{/if}
|
|
99
94
|
</div>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
2
|
declare class __sveltets_Render<Args> {
|
|
3
3
|
props(): {
|
|
4
|
-
defaults
|
|
4
|
+
defaults?: Args | undefined;
|
|
5
5
|
noreset?: boolean | undefined;
|
|
6
6
|
};
|
|
7
7
|
events(): {} & {
|
|
@@ -9,8 +9,8 @@ declare class __sveltets_Render<Args> {
|
|
|
9
9
|
};
|
|
10
10
|
slots(): {
|
|
11
11
|
default: {
|
|
12
|
-
tag: string;
|
|
13
|
-
props:
|
|
12
|
+
tag: string | undefined;
|
|
13
|
+
props: Record<string, any>;
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
16
|
}
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import type { Control } from "./controls/types";
|
|
2
2
|
import type { Writable } from "svelte/store";
|
|
3
|
-
export type Params =
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export type Params = {
|
|
4
|
+
id: number;
|
|
5
|
+
tag?: string;
|
|
6
|
+
values: Record<string, any>;
|
|
7
|
+
defaults: Record<string, any>;
|
|
8
|
+
};
|
|
9
|
+
export type ControlState = {
|
|
10
|
+
expand: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare const initCurrent: () => Writable<number | null>, getCurrent: () => Writable<number | null>;
|
|
13
|
+
export declare const initParams: () => Writable<Params[]>, getParams: () => Writable<Params[]>;
|
|
6
14
|
export declare const initControls: () => Writable<Control[]>, getControls: () => Writable<Control[]>;
|
|
7
|
-
export declare const initDefaults: () => Writable<
|
|
15
|
+
export declare const initDefaults: () => Writable<Record<string, any> | null>, getDefaults: () => Writable<Record<string, any> | null>;
|
|
16
|
+
export declare const initControlsState: () => Writable<ControlState>, getControlsState: () => Writable<ControlState>;
|
|
@@ -8,6 +8,9 @@ function create(defaulter) {
|
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
export const { init: initCurrent, get: getCurrent } = create(() => null);
|
|
11
|
-
export const { init: initParams, get: getParams } = create(() =>
|
|
11
|
+
export const { init: initParams, get: getParams } = create(() => []);
|
|
12
12
|
export const { init: initControls, get: getControls } = create(() => []);
|
|
13
13
|
export const { init: initDefaults, get: getDefaults } = create(() => null);
|
|
14
|
+
export const { init: initControlsState, get: getControlsState } = create(() => ({
|
|
15
|
+
expand: false
|
|
16
|
+
}));
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
2
|
import type { Control } from "./types";
|
|
3
|
-
import type { Params } from "../context";
|
|
4
3
|
declare const __propDef: {
|
|
5
4
|
props: {
|
|
6
5
|
infos: Control[];
|
|
7
|
-
values:
|
|
6
|
+
values: Record<string, any>;
|
|
8
7
|
};
|
|
9
8
|
events: {
|
|
10
9
|
[evt: string]: CustomEvent<any>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function resolve<Args>(d: Args | undefined, p: Record<string, any>): Args;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
function resolveArray(d, p) {
|
|
3
|
+
if (d === undefined) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
const ret = [];
|
|
7
|
+
for (const i in d) {
|
|
8
|
+
if (d[i] instanceof Array) {
|
|
9
|
+
ret.push(resolveArray(d[i], p[i] ?? []));
|
|
10
|
+
}
|
|
11
|
+
else if (d[i] instanceof Object) {
|
|
12
|
+
ret.push(resolveObject(d[i], p[i] ?? {}));
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
ret.push(p[i] ?? d[i]);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return ret;
|
|
19
|
+
}
|
|
20
|
+
function resolveObject(d, p) {
|
|
21
|
+
if (d === undefined) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
const ret = {};
|
|
25
|
+
for (const [key, value] of Object.entries(d)) {
|
|
26
|
+
if (value instanceof Array) {
|
|
27
|
+
ret[key] = resolveArray(value, p[key] ?? []);
|
|
28
|
+
}
|
|
29
|
+
else if (value instanceof Object) {
|
|
30
|
+
ret[key] = resolveObject(value, p[key] ?? {});
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
ret[key] = p[key] ?? value;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return ret;
|
|
37
|
+
}
|
|
38
|
+
export function resolve(d, p) {
|
|
39
|
+
return resolveObject(d ?? {}, p);
|
|
40
|
+
}
|