@lordfokas/yrframe 0.1.0 → 0.1.2
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/dist/Component.d.ts +30 -0
- package/dist/ComponentEvents.d.ts +51 -0
- package/dist/ComponentFactory.d.ts +27 -0
- package/dist/Facade.d.ts +23 -0
- package/dist/utils.d.ts +11 -0
- package/dist/yrframe.d.ts +5 -0
- package/dist/yrframe.js +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ComponentEvents } from "./ComponentEvents.js";
|
|
2
|
+
import { Attributes } from "./utils.js";
|
|
3
|
+
declare const evt: unique symbol;
|
|
4
|
+
export declare class Component<A extends Attributes> extends HTMLElement {
|
|
5
|
+
/** Attribute Event Qualifier chars. Attributes starting with this are special. */
|
|
6
|
+
static readonly AEQ = "yr:";
|
|
7
|
+
readonly [evt]: ComponentEvents;
|
|
8
|
+
protected events(): ComponentEvents;
|
|
9
|
+
constructor(props: Partial<A>, defaults?: Partial<A>);
|
|
10
|
+
/** Remove all children nodes. */
|
|
11
|
+
clearChildren(): void;
|
|
12
|
+
isDisabled(): boolean;
|
|
13
|
+
/** HTML5 Custom Element lifecycle callback (remove from page) */
|
|
14
|
+
disconnectedCallback(): void;
|
|
15
|
+
/** HTML5 Custom Element lifecycle callback (add to page) */
|
|
16
|
+
connectedCallback(): void;
|
|
17
|
+
/** Draw this component's internals. Should return only children nodes. */
|
|
18
|
+
render(): HTMLElement | HTMLElement[] | string | null;
|
|
19
|
+
/** Redraw this component. Works by deleting all children, calling render() and appending the results. */
|
|
20
|
+
redraw(): void;
|
|
21
|
+
/** Called after redraw() to do special manipulation of children nodes. */
|
|
22
|
+
inject(): void;
|
|
23
|
+
/** Get this component's real width in pixels. */
|
|
24
|
+
width(): number;
|
|
25
|
+
/** Get this component's real height in pixels. */
|
|
26
|
+
height(): number;
|
|
27
|
+
/** Shortcut to register this component with a given tag name */
|
|
28
|
+
static register(tag: string): void;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Event } from '@lordfokas/event-bus';
|
|
2
|
+
import { Component } from './Component.js';
|
|
3
|
+
import { EventTarget, Source } from './utils.js';
|
|
4
|
+
type Value = object | string | number | boolean;
|
|
5
|
+
type Callback<T extends Event> = (this: Component<any>, value: T | Value | Value[], evt: T) => void;
|
|
6
|
+
type Optional = "optional";
|
|
7
|
+
/**
|
|
8
|
+
* Event manager for component special functions.
|
|
9
|
+
* A developer isn't meant to directly interface with this class,
|
|
10
|
+
* except by calling Component.events()
|
|
11
|
+
*/
|
|
12
|
+
export declare class ComponentEvents {
|
|
13
|
+
private listeners;
|
|
14
|
+
private sources;
|
|
15
|
+
private triggers;
|
|
16
|
+
private readonly component;
|
|
17
|
+
private readonly owner;
|
|
18
|
+
constructor(component: HTMLElement);
|
|
19
|
+
/** Called by the component when entering DOM */
|
|
20
|
+
connect(): void;
|
|
21
|
+
/** Called by the component when leaving DOM */
|
|
22
|
+
disconnect(): void;
|
|
23
|
+
/** Set up and attach a listener, given a configuration */
|
|
24
|
+
private createListener;
|
|
25
|
+
/** Enforce mandatory targets and skip missing optional ones. */
|
|
26
|
+
private skip;
|
|
27
|
+
/** Attach a generic listener for an event. */
|
|
28
|
+
private attachListener;
|
|
29
|
+
attachGeneric<T extends Event, K1 extends keyof T>(target: EventTarget<T, K1> | undefined, handler: Callback<T>, name: string, optional?: Optional): void;
|
|
30
|
+
attachConsumer<T extends Event, K1 extends keyof T>(target: EventTarget<T, K1> | undefined, handler: Callback<T>, name: string, optional?: Optional): void;
|
|
31
|
+
/** Attach a listener that enriches the target event with data from this component. */
|
|
32
|
+
attachSupplier<T extends Event, K1 extends keyof T>(target: EventTarget<T, K1> | undefined, source: Source<any>, name: string, optional?: Optional): void;
|
|
33
|
+
/**
|
|
34
|
+
* Attach a listener that removes data from an event if a predicate passes.
|
|
35
|
+
* If the target configuration has no path, the whole event is stopped instead.
|
|
36
|
+
*/
|
|
37
|
+
attachRemover<T extends Event, K1 extends keyof T>(target: EventTarget<T, K1> | undefined, predicate: Source<boolean>, name: string, optional?: Optional): void;
|
|
38
|
+
/** Attach a listener that disables a component based on a boolean event field. */
|
|
39
|
+
attachDisabler<T extends Event, K1 extends keyof T>(target: EventTarget<T, K1> | undefined, source: Source<HTMLElement>, name: string, optional?: Optional): void;
|
|
40
|
+
/** Create a function that will fire an event and process data from it. */
|
|
41
|
+
attachSource<T extends Event, K1 extends keyof T>(target: EventTarget<T, K1> | undefined, name: string, optional?: Optional): void;
|
|
42
|
+
/** Create a fake source function that supplies a static or local value. */
|
|
43
|
+
attachStatic(value: any, source: Source<any>, name: string, optional?: Optional): void;
|
|
44
|
+
/** Fire a source function and process the returned data. */
|
|
45
|
+
seek<T extends Event>(name: string, callback: Callback<T>): void;
|
|
46
|
+
/** Create a function that will fire an event to export data. */
|
|
47
|
+
attachTrigger<T extends Event, K1 extends keyof T>(target: EventTarget<T, K1> | undefined, name: string, optional?: Optional): void;
|
|
48
|
+
/** Fire a trigger function with the given data. */
|
|
49
|
+
fire(name: string, data?: any, parent?: Event): void;
|
|
50
|
+
}
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Component } from "./Component.js";
|
|
2
|
+
import { Attributes, Class } from "./utils.js";
|
|
3
|
+
/**
|
|
4
|
+
* JSX / TSX component factory.
|
|
5
|
+
* Should not be invoked manually, is used by TSC when building the project.
|
|
6
|
+
*/
|
|
7
|
+
export declare class ComponentFactory {
|
|
8
|
+
static make(tag: string, props: object, ...children: any[]): HTMLElement;
|
|
9
|
+
static make<A extends Attributes>(tag: Class<Component<A>>, props: A, ...children: any[]): HTMLElement;
|
|
10
|
+
/** Apply vanilla HTML attributes and event callback functions. There is no component level logic here. */
|
|
11
|
+
static setAttributesAndEvents(element: HTMLElement, props: any): void;
|
|
12
|
+
/** Logic for appending children to a parent element according to the possible returns of render() */
|
|
13
|
+
static appendChildren(element: HTMLElement, children: HTMLElement[]): void;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* ## Here be Shenanigans
|
|
17
|
+
* In the event your TSC refuses to find ComponentFactory.make
|
|
18
|
+
* and insists on using React.createElement, fear not:
|
|
19
|
+
*
|
|
20
|
+
* Just `import { FakeReact as React }` and call it a day.
|
|
21
|
+
*
|
|
22
|
+
* At least until you can be arsed to figure it out...
|
|
23
|
+
* `¯\_(ツ)_/¯`
|
|
24
|
+
*/
|
|
25
|
+
export declare class FakeReact {
|
|
26
|
+
static createElement: typeof ComponentFactory.make;
|
|
27
|
+
}
|
package/dist/Facade.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ComponentEvents } from "./ComponentEvents.js";
|
|
2
|
+
import { Attributes, Source } from "./utils.js";
|
|
3
|
+
declare const evt: unique symbol;
|
|
4
|
+
interface EventHost {
|
|
5
|
+
[evt]: ComponentEvents;
|
|
6
|
+
}
|
|
7
|
+
type FacadeElement = HTMLElement & EventHost & {
|
|
8
|
+
connectedCallback: Source<void>;
|
|
9
|
+
disconnectedCallback: Source<void>;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Fake component that constructs and returns another component instead.
|
|
13
|
+
* Used for aliasing and adapting components from other libraries.
|
|
14
|
+
*/
|
|
15
|
+
export declare class Facade<A extends Attributes> {
|
|
16
|
+
static readonly AEQ = "yr:";
|
|
17
|
+
protected readonly node: FacadeElement;
|
|
18
|
+
protected readonly isCustom: boolean;
|
|
19
|
+
protected events(): ComponentEvents;
|
|
20
|
+
constructor(tag: string, props: Partial<A>, defaults?: Partial<A>);
|
|
21
|
+
content(): FacadeElement;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Event } from "@lordfokas/event-bus";
|
|
2
|
+
export type Class<X> = {
|
|
3
|
+
new (...$: any[]): X;
|
|
4
|
+
};
|
|
5
|
+
export type EventTarget<T extends Event, K1 extends keyof T> = [Class<T> & typeof Event, [] | [K1] | [K1, keyof T[K1]], number];
|
|
6
|
+
export type Attributes = {
|
|
7
|
+
[key: string]: EventTarget<any, any> | string | Function | undefined;
|
|
8
|
+
};
|
|
9
|
+
export type Consumer<T> = (t: T) => void;
|
|
10
|
+
export type Source<T> = () => T;
|
|
11
|
+
export declare function has($: any): boolean;
|
package/dist/yrframe.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lordfokas/yrframe",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "A Typescript class-based WebComponents library using Material Design.",
|
|
5
5
|
"main": "dist/yrframe.js",
|
|
6
6
|
"scripts": {
|
|
@@ -20,6 +20,6 @@
|
|
|
20
20
|
"typescript": "^5.3.3"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@lordfokas/event-bus": "^1.0.
|
|
23
|
+
"@lordfokas/event-bus": "^1.0.4"
|
|
24
24
|
}
|
|
25
25
|
}
|