dothtml-interfaces 0.4.2 → 0.4.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dothtml-interfaces",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "description": "Dependency injection interfaces for DOTHtml.",
5
5
  "main": "src/index.d.ts",
6
6
  "types": "src/index.d.ts",
package/src/i-dot.d.ts CHANGED
@@ -2,14 +2,14 @@
2
2
  import IDotComponent from "./i-dot-component";
3
3
  import IDotCss from "./styles/i-dot-css";
4
4
  import IEventBus from "./i-event-bus";
5
- import {AnyReactive, IBoundReactive, IReactive} from "./i-reactive";
5
+ import {IReactive, IBinding, IWatcher} from "./i-reactive";
6
6
  import IDotcssProp from "./styles/i-css-prop";
7
7
 
8
8
  type DotContentPrimitive = string | number | boolean;
9
9
  type DotContentBasic = DotContentPrimitive | Node | Element | NodeList | IDotComponent | IDotDocument//typeof DotDocument;
10
- export type DotContent = DotContentBasic | Array<DotContent> | AnyReactive;//|(()=>DotContent);
10
+ export type DotContent = DotContentBasic | Array<DotContent> | IReactive;//|(()=>DotContent);
11
11
 
12
- type AttrVal<T = string | number | boolean> = T | AnyReactive;
12
+ type AttrVal<T = string | number | boolean> = T | IReactive;
13
13
 
14
14
  /**
15
15
  * Global interface containing elements.
@@ -25,7 +25,7 @@ export interface IDotDocument {
25
25
  /**
26
26
  * A conditional function, analogous to if. Renders the specified DOT if a condition is met. Dynamic binding is possible when condition and callback are functions.
27
27
  */
28
- when(condition: AnyReactive | boolean, DotContent): IDotConditionalDocument;
28
+ when(condition: IReactive | boolean, DotContent): IDotConditionalDocument;
29
29
 
30
30
  // Main functions.
31
31
  // TODO: please make this into a test case.
@@ -46,11 +46,11 @@ export interface IDotDocument {
46
46
  /**
47
47
  * Creates a generic HTML node that can render a string, HTML nodes, or dotHTML content.
48
48
  */
49
- html(content: string | number | boolean | AnyReactive): IDotDocument;
49
+ html(content: string | number | boolean | IReactive): IDotDocument;
50
50
  /**
51
51
  * Creates a text node that will render as a string, rather than being parsed as markup.
52
52
  */
53
- text(content: string | number | boolean | AnyReactive): IDotDocument;
53
+ text(content: string | number | boolean | IReactive): IDotDocument;
54
54
  /**
55
55
  * Mounts a component.
56
56
  * TODO: add second arg.
@@ -65,7 +65,12 @@ export interface IDotDocument {
65
65
  */
66
66
  iterate(n: number, callback: (i: number) => DotContent): IDotDocument;
67
67
  each<T>(a: Array<T> | { [key: string | number]: T }, callback: (x: T, i: number, k: string | number) => DotContent): IDotDocument;
68
- each<T>(a: IReactive<Array<T>>|IBoundReactive<any, Array<T> | { [key: string | number]: T }>, callback: (x: T, i: IBoundReactive<number>, k: string | number) => DotContent): IDotDocument;
68
+ each<T>(a:
69
+ IWatcher<Array<T>>
70
+ |IWatcher<Record<string|number, T>>
71
+ |IBinding<any, Array<T>>
72
+ |IBinding<any, IWatcher<Record<string|number, T>>>
73
+ , callback: (x: T, i: IBinding<number>, k: string | number) => DotContent): IDotDocument;
69
74
 
70
75
  /**
71
76
  * Removes the targeted document and everything in it.
@@ -372,7 +377,7 @@ export interface IDotCore extends IDotDocument {
372
377
  bus: IEventBus;
373
378
  window: IDotWindowBuilder;
374
379
 
375
- watch<Ti = AnyReactive | Array<any> | { [key: string | number]: any } | string | number | boolean>(initValue?: Ti, key?: (Ti extends Array<any> | { [key: string | number]: any } ? string : never)): IReactive<Ti>;
380
+ watch<Ti = IReactive | Array<any> | { [key: string | number]: any } | string | number | boolean>(initValue?: Ti, key?: (Ti extends Array<any> | { [key: string | number]: any } ? string : never)): IWatcher<Ti>;
376
381
 
377
382
  // Keep these around for a bit to show how it was done before in case I need to change anything prior to the v6 launch.
378
383
  // component<T extends IComponent>(Base: new (...args: Parameters<T['build']>) => T): new (...args: Parameters<T['build']>) => T;
@@ -407,7 +412,7 @@ export interface IDotConditionalDocument extends IDotDocument {
407
412
  * A conditional catch, analogous to else if. Can be used after a when function. Evaluates if the previous when's condition was false.
408
413
  * Renders the specified DOT if a condition is met. Dynamic binding is possible when condition and callback are functions.
409
414
  */
410
- otherwiseWhen(condition: AnyReactive | boolean, callback: DotContent): IDotConditionalDocument;
415
+ otherwiseWhen(condition: IReactive | boolean, callback: DotContent): IDotConditionalDocument;
411
416
  /**
412
417
  * A conditional final catch, analogous to else. Can be used after a when or otherwiseWhen function. Evaluates if the previous when/otherwiseWhen evaluated to false.
413
418
  * Renders the specified DOT if a condition is met. Dynamic binding is possible when callback is a function.
@@ -995,7 +1000,7 @@ interface IDotTrack extends IDotGlobalAttrs {
995
1000
 
996
1001
  interface IDotVideo extends IDotGlobalAttrs {
997
1002
  autoPlay?: AttrVal<boolean>;
998
- buffered?: AnyReactive; // Managed by browser not user. TODO: we can possibly use events to update observable objects.
1003
+ buffered?: IReactive; // Managed by browser not user. TODO: we can possibly use events to update observable objects.
999
1004
  controls?: AttrVal<boolean>;
1000
1005
  crossOrigin?: AttrVal<"anonymous"> | AttrVal<"use-credentials">;
1001
1006
  height?: AttrVal<number>;
@@ -1,5 +1,5 @@
1
1
 
2
- export interface IReactive<T = any>{
2
+ export interface IWatcher<T = any>{
3
3
  // Get the value.
4
4
  get value(): T;
5
5
  // Set the value.
@@ -14,7 +14,12 @@ export interface IReactive<T = any>{
14
14
  // subscribeCallback(callback: (value: T)=>void): number;
15
15
  // detachBinding(id: number);
16
16
 
17
- _subscribe(boundReactive: IBoundReactive, item: any);
17
+ /**
18
+ * Subscribe to changes in the reactive object.
19
+ */
20
+ subscribe(callback: Function): number;
21
+
22
+ _subscribe(boundReactive: IBinding, item: any);
18
23
  _detachBinding(id: number);
19
24
 
20
25
  /**
@@ -23,22 +28,27 @@ export interface IReactive<T = any>{
23
28
  */
24
29
  updateObservers(): void;
25
30
 
26
- bindAs<Td = string>(transform: {
31
+ bindAs<Td = string>(transform: (((v: T)=>Td)|({
27
32
  display?: (v: T)=>Td;
28
33
  read?: (v: string)=>T;
29
- }): IBoundReactive<T, Td>;
34
+ }))): IBinding<T, Td>;
30
35
 
31
- bind(): IBoundReactive<T>;
36
+ bind(): IBinding<T>;
32
37
  }
33
38
 
34
- export interface IReactiveWatcher<T = any>{
39
+ export interface IObserver<T = any>{
35
40
  observerUpdate(value: T, obsreverId: number): void;
36
41
  }
37
42
 
38
- export interface IBoundReactive<T = any, Td = T>{
39
- _source: IReactive<T>;
43
+ export interface IBinding<T = any, Td = T>{
44
+ _source: IWatcher<T>;
40
45
  _get: ()=>Td;
41
46
  _set: (v: string|number|boolean)=>void;
47
+
48
+ _transform: {
49
+ display?: (v: T)=>Td;
50
+ read?: (v: string)=>T;
51
+ }
42
52
  }
43
53
 
44
- export type AnyReactive = IBoundReactive|IReactive;
54
+ export type IReactive = IBinding|IWatcher;
package/src/index.d.ts CHANGED
@@ -8,5 +8,5 @@ export * from "./styles/i-dot-css";
8
8
 
9
9
  export { default as IDotComponent, FrameworkItems } from "./i-dot-component";
10
10
 
11
- export { IReactive, IReactiveWatcher, IBoundReactive } from "./i-reactive";
11
+ export { IWatcher, IObserver, IBinding, IReactive } from "./i-reactive";
12
12
  export { default as IEventBus } from "./i-event-bus";
@@ -1,11 +1,11 @@
1
- import { IBoundReactive, IReactive } from "../i-reactive";
1
+ import { IBinding, IWatcher } from "../i-reactive";
2
2
 
3
3
  // Global keyword values.
4
- export type GKV = IReactive<string>|IBoundReactive<any, string>|"inherit"|"initial"|"unset"|"revert"|"revert-layer";
4
+ export type GKV = IWatcher<string>|IBinding<any, string>|"inherit"|"initial"|"unset"|"revert"|"revert-layer";
5
5
 
6
6
  export type ComplexType = string;
7
7
 
8
- export type ValueOrReactive<T> = T|IBoundReactive<any, T>|IReactive<T>;
8
+ export type ValueOrReactive<T> = T|IBinding<any, T>|IWatcher<T>;
9
9
 
10
10
  // BASIC TYPES
11
11
  export type Str = `"${string|""}"`|`'${string|""}'`; // TODO: wherever str is required, we could just inject quotes...
@@ -5,7 +5,7 @@ import IShadowProp from "./complex-css-types/i-shadow-prop";
5
5
  import ITransformationProp from "./complex-css-types/i-transformation-prop";
6
6
  import ColorProp from "./mapped-types/color-props";
7
7
  import LengthProp from "./mapped-types/length-prop";
8
- import { IBoundReactive, IReactive } from "../i-reactive";
8
+ import { IBinding, IWatcher } from "../i-reactive";
9
9
 
10
10
  type BackgroundPositionShorthand2D = string;
11
11
  type BackgroundRepeatValues2d = "no-repeat"|"repeat"|"space"|"round";
@@ -93,7 +93,7 @@ export default interface IDotcssProp extends
93
93
 
94
94
  background?: GKV|string; // TODO: shorthand. Requires advanced typing.
95
95
  backgroundAttachment?: GKV|"scroll"|"fixed"|"local"; // ✔️
96
- backgroundBlendMode?: GKV|Array<IBoundReactive<any, string>|IReactive<string>|"darken"|"luminocity"|"normal">; // ✔️
96
+ backgroundBlendMode?: GKV|Array<IBinding<any, string>|IWatcher<string>|"darken"|"luminocity"|"normal">; // ✔️
97
97
  backgroundPosition?: GKV|BackgroundPositionShorthand2D;
98
98
  backgroundRepeat?: GKV|BackgroundRepeatValues2d;
99
99
  backgroundClip?: GKV|string;
@@ -1,6 +1,6 @@
1
- import { AnyReactive } from "../../i-reactive";
1
+ import { IReactive } from "../../i-reactive";
2
2
 
3
- type V = AnyReactive | number | string;
3
+ type V = IReactive | number | string;
4
4
 
5
5
  type AngleUnitSuffix = "" | "Deg" | "Grad" | "Rad" | "Turn";
6
6
 
@@ -1,6 +1,6 @@
1
- import { IBoundReactive, IReactive } from "../../i-reactive";
1
+ import { IBinding, IWatcher } from "../../i-reactive";
2
2
 
3
- type V = IBoundReactive<any, number|string>| IReactive<number|string> | number | string;
3
+ type V = IBinding<any, number|string>| IWatcher<number|string> | number | string;
4
4
 
5
5
  type ColorUnitSuffix = ""
6
6
  | "Rgb"
@@ -20,7 +20,7 @@ type SpecialColors = "currentcolor"|"transparent";
20
20
 
21
21
  type ColorProp<Prefix extends string> = {
22
22
  [Key in ColorUnitSuffix as `${Prefix}${Key}`]?: (
23
- (Key extends "" ? IBoundReactive<any, string> | IReactive<string> | NamedColor | SystemColor | SpecialColors | `#${string}` | `${"rgb"|"rgba"|"hsl"|"hsla"|"hwb"|"lab"|"lch"|"oklab"|"oklch"|"color"}(${string})` : void) |
23
+ (Key extends "" ? IBinding<any, string> | IWatcher<string> | NamedColor | SystemColor | SpecialColors | `#${string}` | `${"rgb"|"rgba"|"hsl"|"hsla"|"hwb"|"lab"|"lch"|"oklab"|"oklch"|"color"}(${string})` : void) |
24
24
  (Key extends "Rgb" | "Hsl" | "HslDeg" | "HslGrad" | "HslRad" | "HslTurn" | "Hwb" | "HwbDeg" | "HwbGrad" | "HwbRad" | "HwbTurn" | "Lab" | "Lch" | "LchDeg" | "LchGrad" | "LchRad" | "LchTurn" | "Oklch" | "OklchDeg" | "OklchGrad" | "OklchRad" | "OklchTurn" ? [V, V, V] | [V, V, V, V] : void) |
25
25
  (Key extends "Srgb" | "SrgbLinear" | "DisplayP3" | "A98Rgb" | "ProphotoRgb" | "Rec2020" | "Xyz" | "XyzD50" | "XyzD65" ? [V, V, V] : void)
26
26
  );
@@ -1,12 +1,12 @@
1
- import { AnyReactive, IBoundReactive } from "../../i-reactive";
1
+ import { IReactive, IBinding } from "../../i-reactive";
2
2
  import { GKV } from "../css-types";
3
3
  // import { NumericLength } from "./css-types";
4
4
 
5
5
  type LengthUnitSuffix = "" | "Cm" | "Ch" | "Em" | "Ex" | "In" | "Mm" | "P" | "Pc" | "Pt" | "Px" | "Rem" | "Vh" | "Vw" | "VMax" | "VMin";
6
6
 
7
- type V<S> = IBoundReactive<any> | number | S;
7
+ type V<S> = IBinding<any> | number | S;
8
8
 
9
- type LengthProp<Prefix extends string, Qty extends 1|2|3|4 = 1, S extends string|AnyReactive = GKV> = {
9
+ type LengthProp<Prefix extends string, Qty extends 1|2|3|4 = 1, S extends string|IReactive = GKV> = {
10
10
  [Key in LengthUnitSuffix as `${Prefix}${Key}`]?: (
11
11
  (Qty extends 1 ? V<S>|[V<S>] : void) |
12
12
  (Qty extends 2 ? [V<S>, V<S>] : void) |