@xtia/jel 0.2.0 → 0.2.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.
Files changed (3) hide show
  1. package/index.d.ts +6 -4
  2. package/index.js +19 -25
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -11,6 +11,9 @@ type JelEntity<API, EventDataMap> = API & {
11
11
  on<E extends keyof EventDataMap>(eventId: E, handler: (this: JelEntity<API, EventDataMap>, data: EventDataMap[E]) => void): void;
12
12
  readonly [componentDataSymbol]: JelComponentData;
13
13
  };
14
+ type Styles = Partial<{
15
+ [key in keyof CSSStyleDeclaration]: string | number;
16
+ }> & Record<`--${string}`, string | number>;
14
17
  interface ElementDescriptor {
15
18
  classes?: ElementClassSpec;
16
19
  content?: DOMContent;
@@ -18,9 +21,7 @@ interface ElementDescriptor {
18
21
  on?: Partial<{
19
22
  [E in keyof HTMLElementEventMap]: (event: HTMLElementEventMap[E]) => void;
20
23
  }>;
21
- style?: Partial<{
22
- [key in keyof CSSStyleDeclaration]: string | number;
23
- }> & Record<string, string | number>;
24
+ style?: Styles;
24
25
  }
25
26
  type DomHelper = ((<T extends keyof HTMLElementTagNameMap>(tagName: T, descriptor: ElementDescriptor) => DomEntity<HTMLElementTagNameMap[T]>) & (<T extends keyof HTMLElementTagNameMap>(selector: `${T}#${string}`, content?: DOMContent) => DomEntity<HTMLElementTagNameMap[T]>) & (<T extends keyof HTMLElementTagNameMap>(selector: `${T}.${string}`, content?: DOMContent) => DomEntity<HTMLElementTagNameMap[T]>) & (<T extends keyof HTMLElementTagNameMap>(selector: T, content?: DOMContent) => DomEntity<HTMLElementTagNameMap[T]>) & (<T extends HTMLElement>(element: T) => DomEntity<T>) & {
26
27
  [T in keyof HTMLElementTagNameMap]: (descriptor: ElementDescriptor) => DomEntity<HTMLElementTagNameMap[T]>;
@@ -51,5 +52,6 @@ type Optionals<T> = {
51
52
  };
52
53
  export declare const $: DomHelper;
53
54
  declare const componentDataSymbol: unique symbol;
54
- export declare function definePart<Spec, API extends object | void = void, EventDataMap extends Record<string, any> = {}>(defaultOptions: Optionals<Spec>, init: (spec: Required<Spec>, append: (content: DOMContent) => void, trigger: <K extends keyof EventDataMap>(eventId: K, eventData: EventDataMap[K]) => void) => API): JelConstructor<Spec, API, EventDataMap>;
55
+ type Reserve<T> = Record<string, any> & Partial<Record<keyof T, never>>;
56
+ export declare function definePart<Spec extends Reserve<CommonOptions<any>>, API extends Reserve<JelEntity<void, any>> | void = void, EventDataMap extends Record<string, any> = {}>(defaultOptions: Optionals<Spec>, init: (spec: Required<Spec>, append: (content: DOMContent) => void, trigger: <K extends keyof EventDataMap>(eventId: K, eventData: EventDataMap[K]) => void) => API): JelConstructor<Spec, API, EventDataMap>;
55
57
  export {};
package/index.js CHANGED
@@ -42,14 +42,8 @@ function createElement(tag, descriptor) {
42
42
  ent.element.setAttribute(k, v === true ? k : v);
43
43
  });
44
44
  }
45
- var addContent = function (content) {
46
- if (Array.isArray(content))
47
- return content.forEach(function (c) { return addContent(c); });
48
- if (content)
49
- ent.append(content);
50
- };
51
- if (descriptor.content)
52
- addContent(descriptor.content);
45
+ if (descriptor.content !== undefined)
46
+ recursiveAppend(ent.element, descriptor.content);
53
47
  if (descriptor.style) {
54
48
  Object.entries(descriptor.style).forEach(function (_a) {
55
49
  var prop = _a[0], val = _a[1];
@@ -120,24 +114,24 @@ var attribsProxy = {
120
114
  return true;
121
115
  }
122
116
  };
117
+ var recursiveAppend = function (parent, c) {
118
+ if (c === null)
119
+ return;
120
+ if (Array.isArray(c)) {
121
+ c.forEach(function (item) { return recursiveAppend(parent, item); });
122
+ return;
123
+ }
124
+ if (isJelEntity(c)) {
125
+ recursiveAppend(parent, c[componentDataSymbol].dom);
126
+ return;
127
+ }
128
+ if (typeof c == "number")
129
+ c = c.toString();
130
+ parent.append(c);
131
+ };
123
132
  function getWrappedElement(element) {
124
133
  var _a;
125
134
  if (!elementWrapCache.has(element)) {
126
- var recursiveAppend_1 = function (c) {
127
- if (c === null)
128
- return;
129
- if (Array.isArray(c)) {
130
- c.forEach(function (item) { return recursiveAppend_1(item); });
131
- return;
132
- }
133
- if (isJelEntity(c)) {
134
- recursiveAppend_1(c[componentDataSymbol].dom);
135
- return;
136
- }
137
- if (typeof c == "number")
138
- c = c.toString();
139
- element.append(c);
140
- };
141
135
  var domEntity_1 = (_a = {},
142
136
  _a[componentDataSymbol] = {
143
137
  dom: element,
@@ -157,7 +151,7 @@ function getWrappedElement(element) {
157
151
  for (var _i = 0; _i < arguments.length; _i++) {
158
152
  content[_i] = arguments[_i];
159
153
  }
160
- recursiveAppend_1(content);
154
+ recursiveAppend(element, content);
161
155
  },
162
156
  _a.remove = function () {
163
157
  element.remove();
@@ -176,7 +170,7 @@ function getWrappedElement(element) {
176
170
  },
177
171
  set: function (v) {
178
172
  element.innerHTML = "";
179
- recursiveAppend_1(v);
173
+ recursiveAppend(element, v);
180
174
  },
181
175
  enumerable: false,
182
176
  configurable: true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xtia/jel",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "repository": {
5
5
  "url": "https://github.com/tiadrop/jel-ts",
6
6
  "type": "github"