@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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # @nil-/doc
2
2
 
3
+ ## 0.2.16
4
+
5
+ ### Patch Changes
6
+
7
+ - 650eb4b: [doc] revived proper ordering of params
8
+ [doc] each param now has its own defaults (which is resolved from template's default and pram's props)
9
+
3
10
  ## 0.2.15
4
11
 
5
12
  ### Patch Changes
@@ -1,9 +1,10 @@
1
- <script>import { initCurrent, initParams, initControls, initDefaults } from "./context";
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
- getControls().set(props);
4
+ export let expand = false;
5
+ const controls = getControls();
6
+ $controls = props;
7
+ const state = getControlsState();
8
+ $: $state.expand = expand;
5
9
  </script>
@@ -3,6 +3,7 @@ import type { Control } from "./controls/types";
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  props?: Control[] | undefined;
6
+ expand?: boolean | undefined;
6
7
  };
7
8
  events: {
8
9
  [evt: string]: CustomEvent<any>;
@@ -1,13 +1,26 @@
1
1
 
2
- <script>import { getParams, getDefaults } from "./context";
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
- function set(tag, props) {
8
- if ($defaults != null) {
9
- $params[tag] = { ...$defaults, ...props };
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 { beforeUpdate } from "svelte";
37
- import { getParams, getCurrent, getControls, getDefaults } from "./context";
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
- export let defaults;
44
- getDefaults().set(defaults);
45
- $: keys = Object.keys(defaults);
46
- function resolve(d, p) {
47
- if (d === undefined) {
48
- return {};
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 Object.keys($params) as tag (tag)}
70
+ {#each $params as param (param.id)}
76
71
  <div
77
72
  class="instance"
78
- on:click|stopPropagation={() => ($current = tag)}
79
- on:mouseenter={() => (hovered = tag)}
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, $params[tag])} />
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, $params[tag])} />
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 === tag || hovered === tag)}
95
- <div class="misc nil-doc-scrollable" transition:slide>
96
- <Controls infos={$controls} bind:values={$params[tag]} />
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: Args;
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: Args;
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 = Record<string, any>;
4
- export declare const initCurrent: () => Writable<string | null>, getCurrent: () => Writable<string | null>;
5
- export declare const initParams: () => Writable<Params>, getParams: () => Writable<Params>;
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<Params | null>, getDefaults: () => Writable<Params | null>;
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
+ }));
@@ -3,6 +3,7 @@
3
3
  import Header from "./misc/TopHeader.svelte";
4
4
  import Styler from "./misc/Styler.svelte";
5
5
  export let infos;
6
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
7
  export let values;
7
8
  </script>
8
9
  <Styler>
@@ -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: Params;
6
+ values: Record<string, any>;
8
7
  };
9
8
  events: {
10
9
  [evt: string]: CustomEvent<any>;
@@ -17,6 +17,10 @@
17
17
  background-color: hsl(205, 15%, 15%);
18
18
  }
19
19
 
20
+ div > :global(div:hover) {
21
+ background-color: rgba(2, 156, 253, 0.07);
22
+ }
23
+
20
24
  div > :global(div > div) {
21
25
  display: grid;
22
26
  align-items: center;
@@ -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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nil-/doc",
3
- "version": "0.2.15",
3
+ "version": "0.2.16",
4
4
  "author": {
5
5
  "email": "njaldea@gmail.com",
6
6
  "name": "Neil Aldea"