@xtia/jel 0.1.0 → 0.1.1
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/README.md +5 -7
- package/index.d.ts +5 -5
- package/index.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
# Jel
|
|
2
|
-
|
|
3
|
-
### TypeScript Edition
|
|
2
|
+
### Or, How I Learned To Stop Worrying And Love The DOM
|
|
4
3
|
|
|
5
4
|
Jel is a thin layer over the DOM to simplify element structure creation, manipulation and componentisation with 'vanilla' TS.
|
|
6
5
|
|
|
7
|
-
See [demo/index.ts](demo/index.ts) for example operation. Compare with [resulting page](https://aleta.codes/jel-ts-demo/).
|
|
6
|
+
See [demo/index.ts](https://github.com/tiadrop/jel-ts/blob/main/demo/index.ts) for example operation. Compare with [resulting page](https://aleta.codes/jel-ts-demo/).
|
|
8
7
|
|
|
9
8
|
## `$` basic use:
|
|
10
9
|
|
|
11
|
-
```bash
|
|
12
|
-
$ npm i @xtia/jel
|
|
13
|
-
```
|
|
14
|
-
|
|
15
10
|
`$.[tagname](details)` produces an element of `<tagname>`. `details` can be content of various types or a descriptor object.
|
|
16
11
|
|
|
17
12
|
```ts
|
|
18
13
|
import { $ } from "jel-ts";
|
|
19
14
|
|
|
15
|
+
// wrap body
|
|
16
|
+
const body = $(document.body);
|
|
17
|
+
|
|
20
18
|
body.append($.form([
|
|
21
19
|
$.h2("Sign in"),
|
|
22
20
|
$.label("Email"),
|
package/index.d.ts
CHANGED
|
@@ -2,13 +2,13 @@ export type ElementClassSpec = string | Record<string, boolean> | ElementClassSp
|
|
|
2
2
|
export type DOMContent = number | null | string | Element | JelEntity<object, any> | Text | DOMContent[];
|
|
3
3
|
export type DomEntity<T extends HTMLElement> = JelEntity<ElementAPI<T>, HTMLElementEventMap>;
|
|
4
4
|
type Classes = string | Record<string, boolean> | Classes[];
|
|
5
|
-
type
|
|
5
|
+
type JelConstructor<Spec, API, EventDataMap> = (spec?: Partial<Spec & CommonOptions<EventDataMap>>) => JelEntity<API, EventDataMap>;
|
|
6
6
|
type CommonOptions<EventDataMap> = {
|
|
7
7
|
on?: Partial<{
|
|
8
8
|
[EventID in keyof EventDataMap]: (data: EventDataMap[EventID]) => void;
|
|
9
9
|
}>;
|
|
10
10
|
};
|
|
11
|
-
type JelEntity<API
|
|
11
|
+
type JelEntity<API, EventDataMap> = API & {
|
|
12
12
|
on<E extends keyof EventDataMap>(eventId: E, handler: (this: JelEntity<API, EventDataMap>, data: EventDataMap[E]) => void): void;
|
|
13
13
|
readonly [componentDataSymbol]: JelComponentData;
|
|
14
14
|
};
|
|
@@ -23,7 +23,7 @@ interface ElementDescriptor {
|
|
|
23
23
|
[key in keyof CSSStyleDeclaration]: string | number;
|
|
24
24
|
}> & Record<string, string | number>;
|
|
25
25
|
}
|
|
26
|
-
type DomHelper = ((<T extends keyof HTMLElementTagNameMap>(tagName: T, descriptor: ElementDescriptor) => HTMLElementTagNameMap[T]) & ((selector: string, content?: DOMContent) => DomEntity<any>) & (<T extends HTMLElement>(element: T) => DomEntity<T>) & {
|
|
26
|
+
type DomHelper = ((<T extends keyof HTMLElementTagNameMap>(tagName: T, descriptor: ElementDescriptor) => DomEntity<HTMLElementTagNameMap[T]>) & ((selector: string, content?: DOMContent) => DomEntity<any>) & (<T extends HTMLElement>(element: T) => DomEntity<T>) & {
|
|
27
27
|
[T in keyof HTMLElementTagNameMap]: (descriptor: ElementDescriptor) => DomEntity<HTMLElementTagNameMap[T]>;
|
|
28
28
|
} & {
|
|
29
29
|
[T in keyof HTMLElementTagNameMap]: (content?: DOMContent) => DomEntity<HTMLElementTagNameMap[T]>;
|
|
@@ -34,7 +34,7 @@ type JelComponentData = {
|
|
|
34
34
|
export declare const $: DomHelper;
|
|
35
35
|
declare const componentDataSymbol: unique symbol;
|
|
36
36
|
type ElementAPI<T extends HTMLElement> = {
|
|
37
|
-
element: T;
|
|
37
|
+
readonly element: T;
|
|
38
38
|
content: DOMContent;
|
|
39
39
|
classes: DOMTokenList;
|
|
40
40
|
attribs: {
|
|
@@ -46,5 +46,5 @@ type ElementAPI<T extends HTMLElement> = {
|
|
|
46
46
|
append(...content: DOMContent[]): void;
|
|
47
47
|
remove(): void;
|
|
48
48
|
};
|
|
49
|
-
export declare function definePart<Spec, API extends object, EventDataMap extends Record<string, any> = {}>(defaultOptions: Spec, init: (spec: Spec, append: (content: DOMContent) => void, trigger: <K extends keyof EventDataMap>(eventId: K, eventData: EventDataMap[K]) => void) => API
|
|
49
|
+
export declare function definePart<Spec, API extends object | void, EventDataMap extends Record<string, any> = {}>(defaultOptions: Spec, init: (spec: Spec, append: (content: DOMContent) => void, trigger: <K extends keyof EventDataMap>(eventId: K, eventData: EventDataMap[K]) => void) => API): JelConstructor<Spec, API, EventDataMap>;
|
|
50
50
|
export {};
|
package/index.js
CHANGED
|
@@ -139,10 +139,14 @@ function definePart(defaultOptions, init) {
|
|
|
139
139
|
dom: content
|
|
140
140
|
}
|
|
141
141
|
},
|
|
142
|
+
_a.on = {
|
|
143
|
+
value: addEventListener,
|
|
144
|
+
},
|
|
142
145
|
_a)) : (_b = {},
|
|
143
146
|
_b[componentDataSymbol] = {
|
|
144
147
|
dom: content
|
|
145
148
|
},
|
|
149
|
+
_b.on = addEventListener,
|
|
146
150
|
_b);
|
|
147
151
|
return entity;
|
|
148
152
|
});
|