@nil-/doc 0.2.47 → 0.2.48

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,11 @@
1
1
  # @nil-/doc
2
2
 
3
+ ## 0.2.48
4
+
5
+ ### Patch Changes
6
+
7
+ - [doc][fix] Fix type support ([#81](https://github.com/njaldea/mono/pull/81))
8
+
3
9
  ## 0.2.47
4
10
 
5
11
  ### Patch Changes
@@ -1,9 +1,9 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import type { Name, PropNumber, FlatPropNumber } from "../types";
2
+ import type { Unionized, PropType } from "../types";
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  value: number | undefined;
6
- info: (Name & PropNumber) | [string, ...FlatPropNumber];
6
+ info: Unionized<PropType<"number">>;
7
7
  depth: number;
8
8
  disabled?: boolean | undefined;
9
9
  visible?: boolean | undefined;
@@ -1,10 +1,10 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  import type { ValueType } from "../../types";
3
- import type { Name, PropObject, FlatPropObject } from "../types";
3
+ import type { Unionized, PropType } from "../types";
4
4
  declare const __propDef: {
5
5
  props: {
6
6
  value: Record<string, ValueType> | undefined;
7
- info: (Name & PropObject) | [string, ...FlatPropObject];
7
+ info: Unionized<PropType<"object">>;
8
8
  depth: number;
9
9
  disabled?: boolean | undefined;
10
10
  visible?: boolean | undefined;
@@ -2,7 +2,7 @@
2
2
  .input {
3
3
  width: 100%;
4
4
  display: grid;
5
- grid-template-columns: 40px 1fr;
5
+ grid-template-columns: 50px 1fr;
6
6
  gap: 5px;
7
7
  position: relative;
8
8
  }
@@ -11,7 +11,7 @@
11
11
  width: 100%;
12
12
  height: 100%;
13
13
  display: grid;
14
- text-align: right;
14
+ text-align: left;
15
15
  align-items: center;
16
16
  font-size: 0.8rem;
17
17
  user-select: none;
@@ -19,12 +19,14 @@
19
19
  }
20
20
 
21
21
  .tooltip {
22
- padding-right: 10px;
23
22
  width: 100%;
24
23
  height: 100%;
25
24
  left: -110%;
26
25
  position: absolute;
27
26
  visibility: hidden;
27
+ display: grid;
28
+ grid-template-columns: 85px 1fr;
29
+ padding: 0px 5px;
28
30
  }
29
31
 
30
32
  .input:hover > .tooltip:not(.disabled) {
@@ -44,31 +46,47 @@ let enabled = value !== void 0;
44
46
  $:
45
47
  value = enabled && !disabled ? ivalue : void 0;
46
48
  $:
47
- flag = !enabled || disabled;
48
- $:
49
- name = info instanceof Array ? info[0] : info.name;
50
- $:
51
- min = info instanceof Array ? info[2] : info.min;
52
- $:
53
- max = info instanceof Array ? info[3] : info.max;
54
- $:
55
- step = info instanceof Array ? info[4] : info.step;
49
+ i = info instanceof Array ? {
50
+ name: info[0],
51
+ min: info[2],
52
+ max: info[3],
53
+ step: info[4]
54
+ } : {
55
+ name: info.name,
56
+ min: info.min,
57
+ max: info.max,
58
+ step: info.step
59
+ };
60
+ const format = (v, base, digits) => {
61
+ const n = v.toExponential().split("e");
62
+ const ex = parseInt(n[1]);
63
+ const absex = Math.abs(ex);
64
+ const rest = base + (absex >= 10 ? 0 : 1) - (ex >= 0 ? 0 : 1);
65
+ return v.toLocaleString(void 0, {
66
+ signDisplay: "always",
67
+ useGrouping: false,
68
+ notation: absex > 2 + digits ? "scientific" : "standard",
69
+ maximumFractionDigits: rest,
70
+ minimumFractionDigits: rest
71
+ });
72
+ };
56
73
  </script>
57
74
  {#if visible}
58
75
  <div>
59
- <NameHeader {name} {depth} />
76
+ <NameHeader name={i.name} {depth} />
60
77
  <div class="input">
61
- <div class="tooltip" class:disabled={flag}>
62
- Current Value: {ivalue}
78
+ <div class="tooltip" class:disabled={!enabled || disabled}>
79
+ <div>Current Value:</div>
80
+ <div>{format(ivalue, 6, 3)}</div>
63
81
  </div>
64
- <div>{ivalue.toFixed(2)}</div>
82
+ <div>{format(ivalue, 1, 1)}</div>
65
83
  <input
66
84
  type="range"
67
85
  bind:value={ivalue}
68
- {min}
69
- {max}
70
- {step}
71
- disabled={flag}
86
+ min={i.min}
87
+ max={i.max}
88
+ step={i.step}
89
+ disabled={!enabled || disabled}
72
90
  />
73
91
  </div>
74
92
  <div><input type="checkbox" bind:checked={enabled} {disabled} /></div>
@@ -1,9 +1,9 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import type { Name, PropRange, FlatPropRange } from "../types";
2
+ import type { Unionized, PropType } from "../types";
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  value: number | undefined;
6
- info: (Name & PropRange) | [string, ...FlatPropRange];
6
+ info: Unionized<PropType<"range">>;
7
7
  depth: number;
8
8
  disabled?: boolean | undefined;
9
9
  visible?: boolean | undefined;
@@ -1,9 +1,9 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import type { Name, PropSelect, FlatPropSelect } from "../types";
2
+ import type { Unionized, PropType } from "../types";
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  value: string | undefined;
6
- info: (Name & PropSelect) | [string, ...FlatPropSelect];
6
+ info: Unionized<PropType<"select">>;
7
7
  depth: number;
8
8
  disabled?: boolean | undefined;
9
9
  visible?: boolean | undefined;
@@ -1,9 +1,9 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import type { Name, PropSwitch, FlatPropSwitch } from "../types";
2
+ import type { Unionized, PropType } from "../types";
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  value: boolean | undefined;
6
- info: (Name & PropSwitch) | [string, ...FlatPropSwitch];
6
+ info: Unionized<PropType<"switch">>;
7
7
  depth: number;
8
8
  disabled?: boolean | undefined;
9
9
  visible?: boolean | undefined;
@@ -1,9 +1,9 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import type { Name, PropText, FlatPropText } from "../types";
2
+ import type { Unionized, PropType } from "../types";
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  value: string | undefined;
6
- info: (Name & PropText) | [string, ...FlatPropText];
6
+ info: Unionized<PropType<"text">>;
7
7
  depth: number;
8
8
  disabled?: boolean | undefined;
9
9
  visible?: boolean | undefined;
@@ -1,10 +1,10 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  import type { ValueType } from "../../types";
3
- import type { Name, PropTuple, FlatPropTuple } from "../types";
3
+ import type { Unionized, PropType } from "../types";
4
4
  declare const __propDef: {
5
5
  props: {
6
6
  value: ValueType[] | undefined;
7
- info: (Name & PropTuple) | [string, ...FlatPropTuple];
7
+ info: Unionized<PropType<"tuple">>;
8
8
  depth: number;
9
9
  disabled?: boolean | undefined;
10
10
  visible?: boolean | undefined;
@@ -1,12 +1,10 @@
1
1
  import type { ValueType } from "../../../types";
2
- import type { Prop, Name } from "../../types";
3
- import type { PropNumber, PropRange, PropSelect, PropSwitch, PropText, PropTuple, PropObject } from "../../types";
4
- import type { FlatPropNumber, FlatPropRange, FlatPropSelect, FlatPropSwitch, FlatPropText, FlatPropTuple, FlatPropObject } from "../../types";
5
- export declare function getDefault(i: (Name & PropTuple) | [string, ...FlatPropTuple]): ValueType[];
6
- export declare function getDefault(i: (Name & PropObject) | [string, ...FlatPropObject]): Record<string, ValueType>;
7
- export declare function getDefault(i: (Name & PropNumber) | [string, ...FlatPropNumber]): number;
8
- export declare function getDefault(i: (Name & PropRange) | [string, ...FlatPropRange]): number;
9
- export declare function getDefault(i: (Name & PropSelect) | [string, ...FlatPropSelect]): string;
10
- export declare function getDefault(i: (Name & PropText) | [string, ...FlatPropText]): string;
11
- export declare function getDefault(i: (Name & PropSwitch) | [string, ...FlatPropSwitch]): boolean;
2
+ import type { Unionized, PropType, Prop } from "../../types";
3
+ export declare function getDefault(i: Unionized<PropType<"tuple">>): ValueType[];
4
+ export declare function getDefault(i: Unionized<PropType<"object">>): Record<string, ValueType>;
5
+ export declare function getDefault(i: Unionized<PropType<"number">>): number;
6
+ export declare function getDefault(i: Unionized<PropType<"range">>): number;
7
+ export declare function getDefault(i: Unionized<PropType<"select">>): string;
8
+ export declare function getDefault(i: Unionized<PropType<"text">>): string;
9
+ export declare function getDefault(i: Unionized<PropType<"switch">>): boolean;
12
10
  export declare function getDefault(i: Prop): ValueType;
@@ -59,13 +59,13 @@ const getObjectDefaults = (info) => {
59
59
  const getTupleDefaults = (info) => {
60
60
  const ret = [];
61
61
  const values = info instanceof Array ? info[2] : info.values;
62
- values.forEach((v, i) => {
62
+ for (const [i, v] of values.entries()) {
63
63
  if (v instanceof Array) {
64
64
  ret.push(getDefault([`${i}`, ...v]));
65
65
  }
66
66
  else {
67
67
  ret.push(getDefault({ name: `${i}`, ...v }));
68
68
  }
69
- });
69
+ }
70
70
  return ret;
71
71
  };
@@ -1,55 +1,79 @@
1
- // eslint-disable-next-line no-use-before-define
2
- export type FlatPropTuple = ["tuple", NonNamedProp[]];
3
- // eslint-disable-next-line no-use-before-define
4
- export type FlatPropObject = ["object", Prop[]];
5
- export type FlatPropText = ["text"];
6
- export type FlatPropNumber = ["number"];
7
- export type FlatPropRange = ["range", number, number, number];
8
- export type FlatPropSelect = ["select", string[]];
9
- export type FlatPropSwitch = ["switch"];
1
+ type Types = "text" | "number" | "select" | "range" | "switch" | "tuple" | "object";
10
2
 
11
- // eslint-disable-next-line no-use-before-define
12
- export type PropTuple = { type: "tuple" } & { values: NonNamedProp[] };
13
- // eslint-disable-next-line no-use-before-define
14
- export type PropObject = { type: "object" } & { values: Prop[] };
15
- export type PropText = { type: "text" };
16
- export type PropNumber = { type: "number" };
17
- export type PropSwitch = { type: "switch" };
18
- export type PropSelect = { type: "select" } & { values: string[] };
19
- export type PropRange = { type: "range" } & { min: number; max: number; step: number };
3
+ // prettier-ignore
4
+ export type PropType<T extends Types> =
5
+ T extends "text" ? [
6
+ [ name: string, type: T ],
7
+ { name: string; type: T; }
8
+ ]
9
+ : T extends "number" ? [
10
+ [ name: string, type: T ],
11
+ { name: string; type: T; }
12
+ ]
13
+ : T extends "switch" ? [
14
+ [ name: string, type: T ],
15
+ { name: string; type: T; }
16
+ ]
17
+ : T extends "select" ? [
18
+ [ name: string, type: T, values: string[] ],
19
+ { name: string; type: T; values: string[]; }
20
+ ]
21
+ : T extends "range" ? [
22
+ [ name: string, type: T, min: number, max: number, step: number ],
23
+ { name: string; type: T; min: number; max: number, step: number; }
24
+ ]
25
+ : T extends "tuple" ? [
26
+ // eslint-disable-next-line no-use-before-define
27
+ [ name: string, type: T, values: NonNamedProp[] ],
28
+ // eslint-disable-next-line no-use-before-define
29
+ { name: string; type: T; values: NonNamedProp[]; }
30
+ ]
31
+ : T extends "object" ? [
32
+ // eslint-disable-next-line no-use-before-define
33
+ [ name: string, type: T, values: Prop[] ],
34
+ // eslint-disable-next-line no-use-before-define
35
+ { name: string; type: T; values: Prop[]; }
36
+ ]
37
+ : never;
20
38
 
21
- export type Name = { name: string };
39
+ export type Flattened<T extends PropType> = T[0];
40
+ export type Detailed<T extends PropType> = T[1];
41
+ export type Unionized<T extends PropTyoe> = T[number];
22
42
 
43
+ // prettier-ignore
23
44
  export type Prop =
24
- | (Name & PropTuple)
25
- | (Name & PropObject)
26
- | (Name & PropText)
27
- | (Name & PropNumber)
28
- | (Name & PropSwitch)
29
- | (Name & PropSelect)
30
- | (Name & PropRange)
31
- | [string, ...FlatPropTuple]
32
- | [string, ...FlatPropObject]
33
- | [string, ...FlatPropText]
34
- | [string, ...FlatPropNumber]
35
- | [string, ...FlatPropSwitch]
36
- | [string, ...FlatPropSelect]
37
- | [string, ...FlatPropRange];
45
+ | [ name: string, type: "text" ]
46
+ | { name: string; type: "text"; }
47
+ | [ name: string, type: "number" ]
48
+ | { name: string; type: "number"; }
49
+ | [ name: string, type: "switch" ]
50
+ | { name: string; type: "switch"; }
51
+ | [ name: string, type: "select", values: string[] ]
52
+ | { name: string; type: "select"; values: string[]; }
53
+ | [ name: string, type: "range", min: number, max: number, step: number ]
54
+ | { name: string; type: "range"; min: number; max: number; step: number; }
55
+ // eslint-disable-next-line no-use-before-define
56
+ | [ name: string, type: "tuple", values: NonNamedProp[] ]
57
+ // eslint-disable-next-line no-use-before-define
58
+ | { name: string; type: "tuple"; values: NonNamedProp[]; }
59
+ | [ name: string, type: "object", values: Prop[] ]
60
+ | { name: string; type: "object"; values: Prop[]; };
38
61
 
62
+ // prettier-ignore
39
63
  type NonNamedProp =
40
- | PropTuple
41
- | PropObject
42
- | PropText
43
- | PropNumber
44
- | PropRange
45
- | PropSelect
46
- | PropSwitch
47
- | FlatPropTuple
48
- | FlatPropObject
49
- | FlatPropText
50
- | FlatPropNumber
51
- | FlatPropRange
52
- | FlatPropSelect
53
- | FlatPropSwitch;
64
+ | [ type: "text" ]
65
+ | { type: "text"; }
66
+ | [ type: "number" ]
67
+ | { type: "number"; }
68
+ | [ type: "switch" ]
69
+ | { type: "switch"; }
70
+ | [ type: "select", values: string[] ]
71
+ | { type: "select"; values: string[]; }
72
+ | [ type: "range", min: number, max: number, step: number ]
73
+ | { type: "range"; min: number; max: number; step: number; }
74
+ | [ type: "tuple", values: NonNamedProp[] ]
75
+ | { type: "tuple"; values: NonNamedProp[]; }
76
+ | [ type: "object", values: Prop[] ]
77
+ | { type: "object"; values: Prop[]; };
54
78
 
55
79
  export type Event = string;
package/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { renamer } from "./components/navigation/utils/renamer";
2
2
  export { sorter } from "./components/navigation/utils/sorter";
3
- export type { Prop, Event } from "./components/block/controls/types";
3
+ export type { Prop, Event, PropType, Detailed, Flattened, Unionized } from "./components/block/controls/types";
4
4
  export { default as Layout } from "./components/Layout.svelte";
5
5
  export { default as Instance } from "./components/block/Instance.svelte";
6
6
  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.47",
3
+ "version": "0.2.48",
4
4
  "author": {
5
5
  "email": "njaldea@gmail.com",
6
6
  "name": "Neil Aldea"