dothtml-interfaces 0.2.6 → 0.2.8

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/src/i-dot.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  import IComponent, { FrameworkItems } from "./i-component";
3
3
  import IDotCss, { IDotcssProp } from "./i-dot-css";
4
4
  import IEventBus from "./i-event-bus";
5
- import IReactive from "./i-reactive";
5
+ import {IReactive} from "./i-reactive";
6
6
 
7
7
  type DotContentPrimitive = string | number | boolean;
8
8
  type DotContentBasic = DotContentPrimitive | Node | Element | NodeList | IComponent | IDotDocument//typeof DotDocument;
@@ -335,16 +335,27 @@ export interface IDotDocument {
335
335
  }
336
336
 
337
337
  type Styles = string | IDotcssProp;
338
- interface IComponentFactory {
339
- <TProps extends Array<string>, TEvents extends Array<string>, T extends IComponent<TProps, TEvents>>(
340
- Base: new () => T, styles?: Styles | Styles[]
341
- ): new () => T;
342
- useStyles<T extends IComponent>(styles: Styles | Styles[]): (Base: new () => T) => new () => T;
343
- }
338
+ // interface IComponentFactory {
339
+ // <TProps extends string[], TEvents extends string[], T extends IComponent<TProps, TEvents>>(
340
+ // Base: new () => T, styles?: Styles | Styles[]
341
+ // ): new (attrs?: ComponentArgs<TProps, TEvents>) => T & { new (attrs?: ComponentArgs<TProps, TEvents>): IComponent<TProps, TEvents> };
342
+ // }
344
343
 
344
+ // interface IComponentFactory {
345
+ // <TProps extends string[], TEvents extends string[], T extends IComponent<TProps, TEvents>>(
346
+ // Base: new () => T, styles?: Styles | Styles[]
347
+ // ): new (attrs?: ComponentArgs<TProps, TEvents>) => T & IComponent<TProps, TEvents>;
348
+ // }
349
+
350
+ // useStyles<T extends IComponent>(styles: Styles | Styles[]): (Base: new () => T) => new () => T;
345
351
  // hasEvents<T extends IComponent>(styles: Styles | Styles[]): (Base: new () => T) => new () => T;
346
352
  // prop(target: any, propertyKey: string): void;
347
353
 
354
+ export type ComponentArgs<TProps extends Array<string> = [], TEvents extends Array<string> = []> = {
355
+ [key in TProps[number]]?: any;
356
+ } & Partial<{
357
+ [key in TEvents[number]]?: (...args: any[]) => void;
358
+ }>;
348
359
 
349
360
  /**
350
361
  * Interface for the dot object.
@@ -366,7 +377,13 @@ export interface IDotCore extends IDotDocument {
366
377
  // component<T extends IComponent>(Base: new (...args: Parameters<T['build']>) => T): new (...args: Parameters<T['build']>) => T;
367
378
  // useStyles<T extends IComponent>(styles: string|((css: IDotCss)=>IDotcssProp|string)): ((Base: new (...args: Parameters<T['build']>) => T) => new (...args: Parameters<T['build']>) => T);
368
379
 
369
- component: IComponentFactory;
380
+ // component: IComponentFactory;
381
+ // Works but doesn't infer types from the component.
382
+ // There's room for improvement here but it's not clear to me how to do it.
383
+ // What I'd like to do is have the types tied to the IComponent interface rather than the component factory function.
384
+ component<TProps extends string[] = [], TEvents extends string[] = []>(Base: new () => IComponent)
385
+ : new (attrs?: ComponentArgs<TProps, TEvents>) => IComponent & { new (attrs?: ComponentArgs<TProps, TEvents>): IComponent };
386
+
370
387
  useStyles(document: Document, styles: Styles): HTMLStyleElement;
371
388
  }
372
389
 
@@ -424,7 +441,7 @@ export interface IDotGlobalAttrs {
424
441
  areaChecked?: AttrVal<string>;
425
442
  areaSelected?: AttrVal<boolean>;
426
443
  accessKey?: AttrVal<string>; // This could potentially be enumerated. But care should be taken as these types are already quite complex.
427
- class?: AttrVal<string> | Array<AttrVal<string>> | AttrVal<Array<string>> | Record<string, AttrVal<string>>; // Space-separated. TODO: need tests.
444
+ class?: AttrVal<string> | Array<AttrVal<string>> | AttrVal<Array<string>> | Record<string, AttrVal<boolean>>; // Space-separated. TODO: need tests.
428
445
  contentEditable?: AttrVal<"true"> | AttrVal<"false"> | AttrVal<"plaintext-only">;
429
446
  contextMenu?: AttrVal<string>;
430
447
  dir?: AttrVal<string>;
@@ -1,5 +1,5 @@
1
1
 
2
- export default interface IReactive<Ti = any, To = Ti>{
2
+ export interface IReactive<Ti = any, To = Ti>{
3
3
  // The untransformed value.
4
4
  _value: Ti;
5
5
  // Get the value.
@@ -12,10 +12,14 @@ export default interface IReactive<Ti = any, To = Ti>{
12
12
  // If a key is not provided, identification is done automatically by the framework by comparing object references.
13
13
  key: string;
14
14
  // Optional transformer that can transform the input.
15
- transformer?: (input: Ti)=>To;
15
+ transform?: (input: Ti)=>To;
16
16
  // subscribeNode(node: Node): number;
17
17
  // subscribeAttr(node: HTMLElement, attributeName: string): number;
18
18
  subscribeCallback(callback: (value: To)=>void): number;
19
19
  detachBinding(id: number);
20
20
  updateObservers(): void;
21
+ }
22
+
23
+ export interface IReactiveWatcher<T = any>{
24
+ observerUpdate(value: T, obsreverId: number): void;
21
25
  }
package/src/index.d.ts CHANGED
@@ -8,11 +8,5 @@ export * from "./i-dot-css";
8
8
 
9
9
  export { default as IComponent, FrameworkItems } from "./i-component";
10
10
 
11
- export { default as IReactive } from "./i-reactive";
12
- export { default as IEventBus } from "./i-event-bus";
13
-
14
- declare global {
15
- interface Window {
16
- dot: IDotCore;
17
- }
18
- }
11
+ export { IReactive, IReactiveWatcher } from "./i-reactive";
12
+ export { default as IEventBus } from "./i-event-bus";