@nil-/doc 0.2.16 → 0.2.18

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.18
4
+
5
+ ### Patch Changes
6
+
7
+ - a63dd42: [doc][fix] added tooltip for range
8
+
9
+ ## 0.2.17
10
+
11
+ ### Patch Changes
12
+
13
+ - af86341: [doc] moved default mapping in a common lib
14
+ [doc] fix typing
15
+ [doc] if Param's tag is not provided, use stringified id
16
+
3
17
  ## 0.2.16
4
18
 
5
19
  ### Patch Changes
@@ -2,25 +2,21 @@
2
2
  <script>import { onMount } from "svelte";
3
3
  import { getParams, getDefaults } from "./context";
4
4
  import { resolve } from "./utils";
5
- export let tag;
5
+ export let tag = undefined;
6
6
  export let props = {};
7
7
  const defaults = getDefaults();
8
8
  const params = getParams();
9
9
  onMount(() => defaults.subscribe((d) => {
10
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
- });
11
+ params.update((p) => [
12
+ ...p,
13
+ {
14
+ id: p.length,
15
+ tag: tag ?? `${p.length}`,
16
+ values: resolve(d, props),
17
+ defaults: resolve(d, props)
18
+ }
19
+ ]);
24
20
  }
25
21
  }));
26
22
  </script>
@@ -1,8 +1,9 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
+ import { type ValueType } from "./context";
2
3
  declare const __propDef: {
3
4
  props: {
4
- tag: string;
5
- props?: Record<string, unknown> | undefined;
5
+ tag?: string | undefined;
6
+ props?: Record<string, ValueType> | undefined;
6
7
  };
7
8
  events: {
8
9
  [evt: string]: CustomEvent<any>;
@@ -65,6 +65,7 @@ let hovered = null;
65
65
  */
66
66
  let key = false;
67
67
  beforeUpdate(() => (key = !key));
68
+ const resolveArgs = (resolve);
68
69
  </script>
69
70
  <div class="template">
70
71
  {#each $params as param (param.id)}
@@ -77,12 +78,20 @@ beforeUpdate(() => (key = !key));
77
78
  >
78
79
  {#if noreset}
79
80
  <div class="content nil-doc-scrollable">
80
- <slot tag={param.tag} props={resolve(param.defaults, param.values)} />
81
+ <slot
82
+ id={param.id}
83
+ tag={param.tag}
84
+ props={resolveArgs(param.defaults, param.values)}
85
+ />
81
86
  </div>
82
87
  {:else}
83
88
  {#key key}
84
89
  <div class="content nil-doc-scrollable">
85
- <slot tag={param.tag} props={resolve(param.defaults, param.values)} />
90
+ <slot
91
+ id={param.id}
92
+ tag={param.tag}
93
+ props={resolveArgs(param.defaults, param.values)}
94
+ />
86
95
  </div>
87
96
  {/key}
88
97
  {/if}
@@ -9,8 +9,9 @@ declare class __sveltets_Render<Args> {
9
9
  };
10
10
  slots(): {
11
11
  default: {
12
- tag: string | undefined;
13
- props: Record<string, any>;
12
+ id: number;
13
+ tag: string;
14
+ props: Args;
14
15
  };
15
16
  };
16
17
  }
@@ -1,10 +1,13 @@
1
1
  import type { Control } from "./controls/types";
2
2
  import type { Writable } from "svelte/store";
3
+ export type ValueType = undefined | boolean | number | string | ValueType[] | {
4
+ [key: string]: ValueType;
5
+ };
3
6
  export type Params = {
4
7
  id: number;
5
- tag?: string;
6
- values: Record<string, any>;
7
- defaults: Record<string, any>;
8
+ tag: string;
9
+ values: Record<string, ValueType>;
10
+ defaults: Record<string, ValueType>;
8
11
  };
9
12
  export type ControlState = {
10
13
  expand: boolean;
@@ -12,5 +15,5 @@ export type ControlState = {
12
15
  export declare const initCurrent: () => Writable<number | null>, getCurrent: () => Writable<number | null>;
13
16
  export declare const initParams: () => Writable<Params[]>, getParams: () => Writable<Params[]>;
14
17
  export declare const initControls: () => Writable<Control[]>, getControls: () => Writable<Control[]>;
15
- export declare const initDefaults: () => Writable<Record<string, any> | null>, getDefaults: () => Writable<Record<string, any> | null>;
18
+ export declare const initDefaults: () => Writable<Record<string, ValueType> | null>, getDefaults: () => Writable<Record<string, ValueType> | null>;
16
19
  export declare const initControlsState: () => Writable<ControlState>, getControlsState: () => Writable<ControlState>;
@@ -6,10 +6,12 @@ import Switch from "./Switch.svelte";
6
6
  import Select from "./Select.svelte";
7
7
  import Tuple from "./Tuple.svelte";
8
8
  import Object from "./Object.svelte";
9
- export let info;
9
+ // by use, info type is mapped to the value type
10
+ // unfortunately i can't use typescript in the markup part of svelte
10
11
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
12
  export let value;
12
- export let depth = 10;
13
+ export let info;
14
+ export let depth;
13
15
  export let disabled = false;
14
16
  </script>
15
17
  {#if info.type === "object"}
@@ -2,9 +2,9 @@ import { SvelteComponentTyped } from "svelte";
2
2
  import type { Control } from "./types";
3
3
  declare const __propDef: {
4
4
  props: {
5
- info: Control;
6
5
  value: any;
7
- depth?: number | undefined;
6
+ info: Control;
7
+ depth: number;
8
8
  disabled?: boolean | undefined;
9
9
  };
10
10
  events: {
@@ -3,12 +3,11 @@
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
7
6
  export let values;
8
7
  </script>
9
8
  <Styler>
10
9
  <Header />
11
10
  {#each infos as info}
12
- <Component {info} bind:value={values[info.name]} />
11
+ <Component {info} bind:value={values[info.name]} depth={10} disabled={false} />
13
12
  {/each}
14
13
  </Styler>
@@ -1,9 +1,10 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  import type { Control } from "./types";
3
+ import type { ValueType } from "../context";
3
4
  declare const __propDef: {
4
5
  props: {
5
6
  infos: Control[];
6
- values: Record<string, any>;
7
+ values: Record<string, ValueType>;
7
8
  };
8
9
  events: {
9
10
  [evt: string]: CustomEvent<any>;
@@ -1,9 +1,10 @@
1
1
 
2
- <script>export let value;
2
+ <script>import { getDefault } from "./misc/defaulter";
3
+ export let value;
3
4
  export let info;
4
5
  export let depth;
5
6
  export let disabled = false;
6
- let ivalue = value ?? 0;
7
+ let ivalue = value ?? getDefault(info);
7
8
  let enabled = value !== undefined;
8
9
  $: value = enabled && !disabled ? ivalue : undefined;
9
10
  </script>
@@ -2,7 +2,6 @@
2
2
  <script>import Component from "./Component.svelte";
3
3
  import Header from "./misc/GroupHeader.svelte";
4
4
  import { getObjectDefaults } from "./misc/defaulter";
5
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
5
  export let value;
7
6
  export let info;
8
7
  export let depth;
@@ -1,8 +1,9 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  import type { ControlObject } from "./types";
3
+ import type { ValueType } from "../context";
3
4
  declare const __propDef: {
4
5
  props: {
5
- value: Record<string, any> | undefined;
6
+ value: Record<string, ValueType> | undefined;
6
7
  info: ControlObject;
7
8
  depth: number;
8
9
  disabled?: boolean | undefined;
@@ -3,31 +3,51 @@
3
3
  width: 100%;
4
4
  display: grid;
5
5
  grid-template-columns: 40px 1fr;
6
+ gap: 5px;
7
+ position: relative;
6
8
  }
7
9
 
8
10
  .input > div {
9
11
  width: 100%;
10
12
  height: 100%;
11
13
  display: grid;
12
- text-align: center;
14
+ text-align: right;
13
15
  align-items: center;
14
16
  font-size: 0.8rem;
17
+ user-select: none;
15
18
  margin: auto;
16
19
  }
20
+
21
+ .tooltip {
22
+ width: 100%;
23
+ height: 100%;
24
+ /* top: -100%; */
25
+ left: -100%;
26
+ position: absolute;
27
+ visibility: hidden;
28
+ }
29
+
30
+ .input:hover > .tooltip {
31
+ visibility: visible;
32
+ }
17
33
  </style>
18
34
 
19
- <script>export let value;
35
+ <script>import { getDefault } from "./misc/defaulter";
36
+ export let value;
20
37
  export let info;
21
38
  export let depth;
22
39
  export let disabled = false;
23
- let ivalue = value ?? info.min;
40
+ let ivalue = value ?? getDefault(info);
24
41
  let enabled = value !== undefined;
25
42
  $: value = enabled && !disabled ? ivalue : undefined;
26
43
  </script>
27
44
  <div>
28
45
  <div style:padding-left={`${depth}px`}>- {info.name}</div>
29
46
  <div class="input">
30
- <div>{ivalue}</div>
47
+ <div class="tooltip">
48
+ Current Value: {ivalue}
49
+ </div>
50
+ <div>{ivalue.toFixed(2)}</div>
31
51
  <input
32
52
  type="range"
33
53
  bind:value={ivalue}
@@ -1,9 +1,10 @@
1
1
 
2
- <script>export let value;
2
+ <script>import { getDefault } from "./misc/defaulter";
3
+ export let value;
3
4
  export let info;
4
5
  export let depth;
5
6
  export let disabled = false;
6
- let ivalue = value ?? (info.values.length > 0 ? info.values[0] : undefined);
7
+ let ivalue = value ?? getDefault(info);
7
8
  let enabled = value !== undefined;
8
9
  $: value = enabled && !disabled ? ivalue : undefined;
9
10
  </script>
@@ -1,9 +1,10 @@
1
1
 
2
- <script>export let value;
2
+ <script>import { getDefault } from "./misc/defaulter";
3
+ export let value;
3
4
  export let info;
4
5
  export let depth;
5
6
  export let disabled = false;
6
- let ivalue = value ?? false;
7
+ let ivalue = value ?? getDefault(info);
7
8
  let enabled = value !== undefined;
8
9
  $: value = enabled && !disabled ? ivalue : undefined;
9
10
  </script>
@@ -1,9 +1,10 @@
1
1
 
2
- <script>export let value;
2
+ <script>import { getDefault } from "./misc/defaulter";
3
+ export let value;
3
4
  export let info;
4
5
  export let depth;
5
6
  export let disabled = false;
6
- let ivalue = value ?? "";
7
+ let ivalue = value ?? getDefault(info);
7
8
  let ienabled = value !== undefined;
8
9
  $: value = ienabled && !disabled ? ivalue : undefined;
9
10
  </script>
@@ -2,7 +2,6 @@
2
2
  <script>import Component from "./Component.svelte";
3
3
  import Header from "./misc/GroupHeader.svelte";
4
4
  import { getTupleDefaults } from "./misc/defaulter";
5
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
5
  export let value;
7
6
  export let info;
8
7
  export let depth;
@@ -1,8 +1,9 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  import type { ControlTuple } from "./types";
3
+ import type { ValueType } from "../context";
3
4
  declare const __propDef: {
4
5
  props: {
5
- value: any[] | undefined;
6
+ value: ValueType[] | undefined;
6
7
  info: ControlTuple;
7
8
  depth: number;
8
9
  disabled?: boolean | undefined;
@@ -1,4 +1,5 @@
1
+ import type { ValueType } from "../../context";
1
2
  import type { Control, ControlTuple, ControlObject } from "../types";
2
- export declare function getObjectDefaults(info: ControlObject): Record<string, any>;
3
- export declare function getTupleDefaults(i: ControlTuple): any[];
4
- export declare function getDefault(i: Control): any;
3
+ export declare function getObjectDefaults(info: ControlObject): Record<string, ValueType>;
4
+ export declare function getTupleDefaults(i: ControlTuple): ValueType[];
5
+ export declare function getDefault(i: Control): ValueType;
@@ -1,5 +1,4 @@
1
1
  export function getObjectDefaults(info) {
2
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
2
  const ret = {};
4
3
  for (const i of info.values) {
5
4
  ret[i.name] = getDefault(i);
@@ -13,16 +12,21 @@ export function getTupleDefaults(i) {
13
12
  }
14
13
  return ret;
15
14
  }
16
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
15
  export function getDefault(i) {
16
+ if (i.type === "switch") {
17
+ return false;
18
+ }
18
19
  if (i.type === "number") {
19
20
  return 0;
20
21
  }
21
22
  if (i.type === "range") {
22
23
  return i.min;
23
24
  }
24
- if (i.type === "switch") {
25
- return false;
25
+ if (i.type === "text") {
26
+ return "";
27
+ }
28
+ if (i.type === "select") {
29
+ return i.values.length > 0 ? i.values[0] : "";
26
30
  }
27
31
  if (i.type === "tuple") {
28
32
  return [...getTupleDefaults(i)];
@@ -30,6 +34,5 @@ export function getDefault(i) {
30
34
  if (i.type === "object") {
31
35
  return getObjectDefaults(i);
32
36
  }
33
- // "select" | "text"
34
- return "";
37
+ return undefined;
35
38
  }
@@ -1 +1,6 @@
1
- export declare function resolve<Args>(d: Args | undefined, p: Record<string, any>): Args;
1
+ import type { ValueType } from "./context";
2
+ type VTObject = {
3
+ [key: string]: ValueType;
4
+ };
5
+ export declare function resolve<Args>(d: VTObject | undefined, p: VTObject): Args;
6
+ export {};
@@ -1,4 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
1
  function resolveArray(d, p) {
3
2
  if (d === undefined) {
4
3
  return undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nil-/doc",
3
- "version": "0.2.16",
3
+ "version": "0.2.18",
4
4
  "author": {
5
5
  "email": "njaldea@gmail.com",
6
6
  "name": "Neil Aldea"