@xtia/jel 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/README.md CHANGED
@@ -1,21 +1,19 @@
1
1
  # Jel
2
- ## Or, How I Learned To Stop Worrying And Love The DOM
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
- import { $ } from "jel-ts";
13
+ import { $ } from "@xtia/jel";
14
+
15
+ // wrap body
16
+ const body = $(document.body);
19
17
 
20
18
  body.append($.form([
21
19
  $.h2("Sign in"),
package/index.d.ts CHANGED
@@ -1,19 +1,18 @@
1
1
  export type ElementClassSpec = string | Record<string, boolean> | ElementClassSpec[];
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
- type Classes = string | Record<string, boolean> | Classes[];
5
- type PartFn<Spec, API extends {}, EventDataMap> = (spec?: Partial<Spec & CommonOptions<EventDataMap>>) => JelEntity<API, EventDataMap>;
4
+ type JelConstructor<Spec, API, EventDataMap> = (spec?: Partial<Spec & CommonOptions<EventDataMap>>) => JelEntity<API, EventDataMap>;
6
5
  type CommonOptions<EventDataMap> = {
7
6
  on?: Partial<{
8
7
  [EventID in keyof EventDataMap]: (data: EventDataMap[EventID]) => void;
9
8
  }>;
10
9
  };
11
- type JelEntity<API extends {}, EventDataMap> = API & {
10
+ type JelEntity<API, EventDataMap> = API & {
12
11
  on<E extends keyof EventDataMap>(eventId: E, handler: (this: JelEntity<API, EventDataMap>, data: EventDataMap[E]) => void): void;
13
12
  readonly [componentDataSymbol]: JelComponentData;
14
13
  };
15
14
  interface ElementDescriptor {
16
- classes?: Classes;
15
+ classes?: ElementClassSpec;
17
16
  content?: DOMContent;
18
17
  attribs?: Record<string, string | number | boolean>;
19
18
  on?: Partial<{
@@ -23,7 +22,8 @@ interface ElementDescriptor {
23
22
  [key in keyof CSSStyleDeclaration]: string | number;
24
23
  }> & Record<string, string | number>;
25
24
  }
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>) & {
25
+ type HelperSelectorString<T extends string> = T | `${T}${"#" | "."}${any}`;
26
+ type DomHelper = ((<T extends keyof HTMLElementTagNameMap>(tagName: T, descriptor: ElementDescriptor) => DomEntity<HTMLElementTagNameMap[T]>) & (<T extends keyof HTMLElementTagNameMap>(selector: HelperSelectorString<T>, content?: DOMContent) => 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 | void): PartFn<Spec, API, EventDataMap>;
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
- dom: content
147
+ dom: content,
145
148
  },
149
+ _b.on = addEventListener,
146
150
  _b);
147
151
  return entity;
148
152
  });
package/package.json CHANGED
@@ -1,6 +1,10 @@
1
1
  {
2
2
  "name": "@xtia/jel",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
+ "repository": {
5
+ "url": "https://github.com/tiadrop/jel-ts",
6
+ "type": "github"
7
+ },
4
8
  "description": "Lightweight DOM wrapper",
5
9
  "main": "index.js",
6
10
  "keywords": [