@twobirds/microcomponents 0.0.82 → 0.0.83

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 (233) hide show
  1. package/assets/documentation/MC.md +0 -1
  2. package/dist/MC.d.ts +3 -3
  3. package/dist/MC.d.ts.map +1 -1
  4. package/dist/MC.js +43 -74
  5. package/dist/MC.min.js +43 -74
  6. package/dist/MC.ts +67 -143
  7. package/dist/elements.d.ts +1 -1
  8. package/dist/elements.d.ts.map +1 -1
  9. package/dist/elements.js +16 -2
  10. package/dist/elements.min.js +1 -1
  11. package/dist/elements.ts +33 -3
  12. package/dist/formValues.min.js +1 -1
  13. package/dist/microcomponents.min.js +1 -1
  14. package/dist/observables.d.ts.map +1 -1
  15. package/dist/observables.js +40 -47
  16. package/dist/observables.min.js +1 -1
  17. package/dist/observables.ts +54 -59
  18. package/dist/selectors.d.ts +2 -4
  19. package/dist/selectors.d.ts.map +1 -1
  20. package/dist/selectors.js +2 -214
  21. package/dist/selectors.min.js +1 -1
  22. package/dist/selectors.ts +2 -367
  23. package/package.json +6 -5
  24. package/public/MC.d.ts +3 -3
  25. package/public/MC.d.ts.map +1 -1
  26. package/public/MC.js +43 -74
  27. package/public/MC.js.map +1 -1
  28. package/public/MC.min.js +43 -74
  29. package/public/MC.ts +67 -143
  30. package/public/documentation/MC.md +0 -1
  31. package/public/elements.d.ts +1 -1
  32. package/public/elements.d.ts.map +1 -1
  33. package/public/elements.js +16 -2
  34. package/public/elements.js.map +1 -1
  35. package/public/elements.min.js +1 -1
  36. package/public/elements.ts +33 -3
  37. package/public/formValues.min.js +1 -1
  38. package/public/microcomponents.min.js +1 -1
  39. package/public/observables.d.ts.map +1 -1
  40. package/public/observables.js +40 -47
  41. package/public/observables.js.map +1 -1
  42. package/public/observables.min.js +1 -1
  43. package/public/observables.ts +54 -59
  44. package/public/selectors.d.ts +2 -4
  45. package/public/selectors.d.ts.map +1 -1
  46. package/public/selectors.js +2 -214
  47. package/public/selectors.js.map +1 -1
  48. package/public/selectors.min.js +1 -1
  49. package/public/selectors.ts +2 -367
  50. package/public/src/MC.d.ts +36 -0
  51. package/public/src/MC.d.ts.map +1 -0
  52. package/public/src/MC.js +348 -0
  53. package/public/src/MC.js.map +1 -0
  54. package/public/src/MC.ts +67 -143
  55. package/public/src/McEvent.d.ts +15 -0
  56. package/public/src/McEvent.d.ts.map +1 -0
  57. package/public/src/McEvent.js +71 -0
  58. package/public/src/elements.d.ts +5 -0
  59. package/public/src/elements.d.ts.map +1 -0
  60. package/public/src/elements.js +62 -0
  61. package/public/src/elements.js.map +1 -0
  62. package/public/src/elements.ts +33 -3
  63. package/public/src/formValues.d.ts +3 -0
  64. package/public/src/formValues.d.ts.map +1 -0
  65. package/public/src/formValues.js +162 -0
  66. package/public/src/helpers.d.ts +14 -0
  67. package/public/src/helpers.d.ts.map +1 -0
  68. package/public/src/helpers.js +113 -0
  69. package/public/src/microcomponents.d.ts +7 -0
  70. package/public/src/microcomponents.d.ts.map +1 -0
  71. package/public/src/microcomponents.js +8 -0
  72. package/public/src/observables.d.ts +11 -0
  73. package/public/src/observables.d.ts.map +1 -0
  74. package/public/src/observables.js +242 -0
  75. package/public/src/observables.js.map +1 -0
  76. package/public/src/observables.ts +54 -59
  77. package/public/src/selectors.d.ts +106 -0
  78. package/public/src/selectors.d.ts.map +1 -0
  79. package/public/src/selectors.js +759 -0
  80. package/public/src/selectors.js.map +1 -0
  81. package/public/src/selectors.ts +2 -367
  82. package/public/src/test/grandparent.css +11 -0
  83. package/public/src/test/test/child.d.ts +2 -0
  84. package/public/src/test/test/child.d.ts.map +1 -0
  85. package/public/src/test/test/child.js +15 -0
  86. package/public/src/test/test/child.js.map +1 -0
  87. package/public/src/test/test/child.ts +21 -0
  88. package/public/src/test/test/grandchild.d.ts +2 -0
  89. package/public/src/test/test/grandchild.d.ts.map +1 -0
  90. package/public/src/test/test/grandchild.js +15 -0
  91. package/public/src/test/test/grandchild.js.map +1 -0
  92. package/public/src/test/test/grandchild.ts +21 -0
  93. package/public/src/test/test/grandparent.d.ts +2 -0
  94. package/public/src/test/test/grandparent.d.ts.map +1 -0
  95. package/public/src/test/test/grandparent.js +1 -0
  96. package/public/src/test/test/grandparent.js.map +1 -0
  97. package/public/src/test/test/grandparent.ts +21 -0
  98. package/public/src/test/test/greatgrandchild.d.ts +2 -0
  99. package/public/src/test/test/greatgrandchild.d.ts.map +1 -0
  100. package/public/src/test/test/greatgrandchild.js +29 -0
  101. package/public/src/test/test/greatgrandchild.js.map +1 -0
  102. package/public/src/test/test/greatgrandchild.ts +42 -0
  103. package/public/src/test/test/parent.d.ts +2 -0
  104. package/public/src/test/test/parent.d.ts.map +1 -0
  105. package/public/src/test/test/parent.js +15 -0
  106. package/public/src/test/test/parent.js.map +1 -0
  107. package/public/src/test/test/parent.ts +21 -0
  108. package/public/src/test/test/testform.d.ts +2 -0
  109. package/public/src/test/test/testform.d.ts.map +1 -0
  110. package/public/src/test/test/testform.js +1 -0
  111. package/public/src/test/test/testform.js.map +1 -0
  112. package/public/src/test/test/testform.ts +155 -0
  113. package/public/src/test/test/testfunction.d.ts +3 -0
  114. package/public/src/test/test/testfunction.d.ts.map +1 -0
  115. package/public/src/test/test/testfunction.js +7 -0
  116. package/public/src/test/test/testfunction.js.map +1 -0
  117. package/public/src/test/test/testfunction.ts +12 -0
  118. package/public/src/test/test/testmc.d.ts +3 -0
  119. package/public/src/test/test/testmc.d.ts.map +1 -0
  120. package/public/src/test/test/testmc.js +10 -0
  121. package/public/src/test/test/testmc.js.map +1 -0
  122. package/public/src/test/test/testmc.ts +16 -0
  123. package/public/src/test/test/testsimpleclass.d.ts +3 -0
  124. package/public/src/test/test/testsimpleclass.d.ts.map +1 -0
  125. package/public/src/test/test/testsimpleclass.js +9 -0
  126. package/public/src/test/test/testsimpleclass.js.map +1 -0
  127. package/public/src/test/test/testsimpleclass.ts +15 -0
  128. package/public/src/test/test.d.ts +2 -0
  129. package/public/src/test/test.d.ts.map +1 -0
  130. package/public/src/test/test.js +79 -0
  131. package/public/src/test/test.js.map +1 -0
  132. package/public/src/test/test.ts +188 -0
  133. package/public/src/test/testform.css +47 -0
  134. package/public/src/test/testform.html +56 -0
  135. package/public/src/test/testform.json +27 -0
  136. package/public/test/MC.d.ts +3 -3
  137. package/public/test/MC.d.ts.map +1 -1
  138. package/public/test/MC.js +43 -74
  139. package/public/test/MC.min.js +485 -0
  140. package/public/test/MC.ts +67 -143
  141. package/public/test/elements.d.ts +1 -1
  142. package/public/test/elements.d.ts.map +1 -1
  143. package/public/test/elements.js +16 -2
  144. package/public/test/elements.min.js +1 -0
  145. package/public/test/elements.ts +33 -3
  146. package/public/test/formValues.min.js +1 -0
  147. package/public/test/grandparent.css +1 -3
  148. package/public/test/microcomponents.min.js +1 -1
  149. package/public/test/observables.d.ts.map +1 -1
  150. package/public/test/observables.js +40 -47
  151. package/public/test/observables.min.js +1 -0
  152. package/public/test/observables.ts +54 -59
  153. package/public/test/selectors.d.ts +2 -4
  154. package/public/test/selectors.d.ts.map +1 -1
  155. package/public/test/selectors.js +2 -214
  156. package/public/test/selectors.min.js +1 -0
  157. package/public/test/selectors.ts +2 -367
  158. package/public/test/test/child.ts +21 -0
  159. package/public/test/test/grandchild.ts +21 -0
  160. package/public/test/test/grandparent.js +1 -1
  161. package/public/test/test/grandparent.ts +21 -0
  162. package/public/test/test/greatgrandchild.ts +42 -0
  163. package/public/test/test/parent.ts +21 -0
  164. package/public/test/test/testform.js +1 -1
  165. package/public/test/test/testform.js.map +1 -1
  166. package/public/test/test/testform.ts +155 -0
  167. package/public/test/test/testfunction.d.ts +3 -0
  168. package/public/test/test/testfunction.d.ts.map +1 -0
  169. package/public/test/test/testfunction.js +7 -0
  170. package/public/test/test/testfunction.js.map +1 -0
  171. package/public/test/test/testfunction.ts +12 -0
  172. package/public/test/test/testmc.d.ts +2 -5
  173. package/public/test/test/testmc.d.ts.map +1 -1
  174. package/public/test/test/testmc.js +4 -4
  175. package/public/test/test/testmc.js.map +1 -1
  176. package/public/test/test/testmc.ts +16 -0
  177. package/public/test/test/testsimpleclass.d.ts +3 -0
  178. package/public/test/test/testsimpleclass.d.ts.map +1 -0
  179. package/public/test/test/testsimpleclass.js +9 -0
  180. package/public/test/test/testsimpleclass.js.map +1 -0
  181. package/public/test/test/testsimpleclass.ts +15 -0
  182. package/public/test/test.js +0 -2
  183. package/public/test/test.js.map +1 -1
  184. package/public/test/test.ts +188 -0
  185. package/public/test/testform.css +47 -0
  186. package/public/test/testform.html +56 -0
  187. package/public/test/testform.json +3 -3
  188. package/public/typedoc/assets/navigation.js +1 -1
  189. package/public/typedoc/assets/search.js +1 -1
  190. package/public/typedoc/classes/MC.DC.html +5 -5
  191. package/public/typedoc/classes/MC.MC.html +5 -5
  192. package/public/typedoc/classes/MC.McBase.html +4 -3
  193. package/public/typedoc/classes/MC.McEvent.html +2 -2
  194. package/public/typedoc/functions/MC.addListener.html +1 -1
  195. package/public/typedoc/functions/MC.autoload.html +1 -1
  196. package/public/typedoc/functions/MC.removeListener.html +1 -1
  197. package/public/typedoc/functions/elements.defineCE.html +1 -1
  198. package/public/typedoc/functions/elements.getCE.html +1 -1
  199. package/public/typedoc/functions/formValues.formValues.html +1 -1
  200. package/public/typedoc/functions/observables.observe.html +1 -1
  201. package/public/typedoc/functions/selectors._d.html +1 -0
  202. package/public/typedoc/functions/selectors._t.html +1 -0
  203. package/public/typedoc/interfaces/MC.HTMLMcElement.html +2 -2
  204. package/public/typedoc/interfaces/selectors.DSelector.html +48 -0
  205. package/public/typedoc/interfaces/selectors.TSelector.html +34 -0
  206. package/public/typedoc/modules/MC.html +1 -1
  207. package/public/typedoc/modules/elements.html +1 -1
  208. package/public/typedoc/modules/formValues.html +1 -1
  209. package/public/typedoc/modules/observables.html +1 -1
  210. package/public/typedoc/modules/selectors.html +7 -0
  211. package/public/typedoc/modules.html +1 -0
  212. package/public/typedoc/types/observables.Observable.html +1 -1
  213. package/public/typedoc/types/selectors.selection.html +1 -0
  214. package/public/typedoc/types/selectors.singleSelector.html +1 -0
  215. package/src/MC.ts +67 -143
  216. package/src/elements.ts +33 -3
  217. package/src/observables.ts +54 -59
  218. package/src/selectors.ts +2 -367
  219. package/src/test/test/testform.ts +7 -3
  220. package/src/test/test/testfunction.ts +12 -0
  221. package/src/test/test/testmc.ts +13 -9
  222. package/src/test/test/testsimpleclass.ts +15 -0
  223. package/src/test/test.ts +0 -12
  224. package/tasks.md +36 -0
  225. package/typedoc.json +1 -1
  226. package/public/test/MC.js.map +0 -1
  227. package/public/test/elements.js.map +0 -1
  228. package/public/test/observables.js.map +0 -1
  229. package/public/test/selectors.js.map +0 -1
  230. /package/public/{test → src}/McEvent.js.map +0 -0
  231. /package/public/{test → src}/formValues.js.map +0 -0
  232. /package/public/{test → src}/helpers.js.map +0 -0
  233. /package/public/{test → src}/microcomponents.js.map +0 -0
@@ -21,12 +21,11 @@ function getPlaceholders(target: HTMLElement): string[] {
21
21
  regEx = /\{[^\{\}]*\}/g;
22
22
 
23
23
  // scan attributes
24
- target
25
- .getAttributeNames()
24
+ ( !!target.getAttributeNames ? target.getAttributeNames() : [] )
26
25
  .filter((attr) => target.getAttribute(attr)?.match(regEx)) // extract placeholder(s)
27
26
  .forEach((attr) => {
28
- let phs: Set<string> = new Set(target.getAttribute(attr)?.match(regEx));
29
- phs.forEach((placeholder) =>
27
+ let placeholders: Set<string> = new Set(target.getAttribute(attr)?.match(regEx));
28
+ placeholders.forEach((placeholder) =>
30
29
  placeholders.add(placeholder.replace(/[\{\}]/g, ''))
31
30
  );
32
31
  });
@@ -62,35 +61,31 @@ class Placeholders extends DC {
62
61
 
63
62
  constructor(target: HTMLElement) {
64
63
  super(target);
65
- let that = this;
66
- getPlaceholders(target).forEach((property) => (that.data[property] = ''));
67
- observe(that);
68
- that.#attachCallbacks();
69
- delete that._mc; // cleanup, not needed
64
+ getPlaceholders(target).forEach((property) => (this.data[property] = ''));
65
+ observe(this);
66
+ this.#attachCallbacks();
70
67
  }
71
68
 
72
69
  #attachCallbacks() {
73
- let that = this,
74
- target = that.target,
70
+ let target = this.target,
75
71
  hide: boolean = false;
76
72
 
77
- //console.log('attachCallbacks', that.target);
73
+ //console.log('attachCallbacks', this.target);
78
74
 
79
75
  // scan attributes
80
- target
81
- .getAttributeNames()
76
+ ( !!target.getAttributeNames ? target.getAttributeNames() : [] )
82
77
  .filter((attr: string) =>
83
78
  target.getAttribute(attr)?.match(/\{[^\{\}]*\}/g)
84
79
  ) // extract placeholder(s)
85
80
  .forEach((attr: string) => {
86
- let phs: Set<string> = new Set(
81
+ let placeholders: Set<string> = new Set(
87
82
  target.getAttribute(attr)?.match(/\{[^\{\}]*\}/g)
88
83
  );
89
84
  // attach callback
90
- that.data.observe(
85
+ this.data.observe(
91
86
  ((template: string) => (data: LooseObject) => {
92
87
  let result: string = template;
93
- phs.forEach((placeholder) => {
88
+ placeholders.forEach((placeholder) => {
94
89
  result = result.replace(
95
90
  placeholder,
96
91
  data[placeholder.replace(/[\{\}]/g, '')]
@@ -108,44 +103,48 @@ class Placeholders extends DC {
108
103
  return (
109
104
  // is text node and has placeholders
110
105
  childNode.nodeType === 3 &&
111
- ((childNode as any).nodeValue || '').match(/\{[^\{\}]*\}/g)
106
+ ((childNode as Node).nodeValue || '').match(/\{[^\{\}]*\}/g)
112
107
  );
113
108
  })
114
109
  .forEach((childNode) => {
115
110
  hide = true;
116
- let phs: Set<string> = new Set(
111
+ let placeholders: Set<string> = new Set(
117
112
  childNode.nodeValue.match(/\{[^\{\}]*\}/g)
118
113
  );
119
114
 
120
115
  // attach callback
121
- that.data.observe(
116
+ this.data.observe(
122
117
  ((template: string) => (data: LooseObject) => {
123
118
  let result: string = template;
124
- //console.log('text node "', template, '" callbach data:', data);
125
- phs.forEach((placeholder) => {
119
+ //console.log('text node "', template, '" callback data:', data);
120
+ placeholders.forEach((placeholder) => {
126
121
  result = result.replace(
127
122
  placeholder,
128
123
  data[placeholder.replace(/[\{\}]/g, '')]
129
124
  );
130
125
  });
131
- if (
132
- Object.keys(data).some((key) => {
133
- return !!data[key];
134
- })
135
- ) {
136
- if (!!that.oldDisplay) {
137
- target.style = that.oldDisplay;
126
+ // TODO: find out why this doesnt work correctly ... maybe completely overhaul the whole thing
127
+ // TODO: check overlap with inner web components, possibly firewall them
128
+ // TODO: maybe include convention for plain DOM / ShadowDom handling
129
+
130
+ // if (
131
+ // Object.keys(data).some((key) => {
132
+ // return !!data[key];
133
+ // })
134
+ // ) {
135
+ if (!!this.oldDisplay) {
136
+ target.style = this.oldDisplay;
138
137
  } else {
139
138
  target.removeAttribute('style');
140
139
  }
141
- delete that.oldDisplay;
142
- }
140
+ delete this.oldDisplay;
141
+ // }
143
142
  childNode.nodeValue = result;
144
143
  })(childNode.nodeValue)
145
144
  );
146
145
 
147
146
  // hide for now
148
- that.oldDisplay = target.getAttribute('style)') || '';
147
+ this.oldDisplay = target.getAttribute('style)') || '';
149
148
  if (
150
149
  hide &&
151
150
  !inputs.includes((target as any).constructor) &&
@@ -157,26 +156,24 @@ class Placeholders extends DC {
157
156
  }
158
157
 
159
158
  onData(ev: McEvent) {
160
- let that = this,
161
- data: LooseObject = {};
159
+ let data: LooseObject = {};
162
160
  Object.keys(ev.data).forEach((key) => {
163
- if (that.data.hasOwnProperty(key)) data[key] = ev.data[key];
161
+ if (this.data.hasOwnProperty(key)) data[key] = ev.data[key];
164
162
  });
165
- //console.log('onData()', ev, data, that.data);
166
- if (JSON.stringify(data) !== JSON.stringify(that.data))
167
- Object.assign(that.data, data); // will trigger callbacks
163
+ //console.log('onData()', ev, data, this.data);
164
+ if (JSON.stringify(data) !== JSON.stringify(this.data))
165
+ Object.assign(this.data, data); // will trigger callbacks
168
166
  }
169
167
  }
170
168
 
171
169
  function getPlaceholderElements(
172
170
  target: HTMLElement | DocumentFragment | ShadowRoot
173
171
  ): HTMLElement[] {
174
- let elements: Array<HTMLElement> = (
175
- target instanceof HTMLElement ? [target] : []
176
- )
172
+ let elements: Array<Node> = [target]
177
173
  .concat([...(target.querySelectorAll('*') as unknown as HTMLElement[])])
178
174
  .filter((e) => !!getPlaceholders(e as HTMLElement).length)
179
- .filter((e) => e.tagName !== 'STYLE');
175
+ .filter((e) => (e as HTMLElement)?.tagName !== 'STYLE')
176
+ .reverse(); // to start with inner elements
180
177
  //console.log('getPlaceholderElements', elements);
181
178
  return elements as HTMLElement[];
182
179
  }
@@ -239,14 +236,13 @@ function makeObservable(val: any): Class<typeof val>{
239
236
  }
240
237
 
241
238
  bind(target: HTMLElement | DocumentFragment | ShadowRoot) {
242
- const that = this,
243
- iso = isObservableObject(that.valueOf());
239
+ const iso = isObservableObject(this.valueOf());
244
240
  //console.log('bind', iso, target);
245
241
 
246
242
  if (iso) {
247
243
  makePlaceholders(target);
248
244
  const placeholders: unknown = [
249
- ...target.querySelectorAll('[_mc]'),
245
+ target, ...target.querySelectorAll('[_mc]'),
250
246
  ].filter((e) => !!(e as LooseObject)?._mc?._placeholders);
251
247
  //console.log('placeholders:', target, placeholders);
252
248
  const func = function callback(data: LooseObject) {
@@ -259,13 +255,13 @@ function makeObservable(val: any): Class<typeof val>{
259
255
  (e as any)._mc.trigger('data', d);
260
256
  });
261
257
  };
262
- (that as any).#callbacks.push(func);
263
- that.notify();
258
+ (this as any).#callbacks.push(func);
259
+ this.notify();
264
260
  } else {
265
261
  console.warn(
266
262
  'IGNORED - cannot bind a non-Object to the dom, IS:',
267
- typeof that.valueOf(),
268
- that
263
+ typeof this.valueOf(),
264
+ this
269
265
  );
270
266
  }
271
267
 
@@ -273,20 +269,19 @@ function makeObservable(val: any): Class<typeof val>{
273
269
  }
274
270
 
275
271
  notify(notify?: boolean) {
276
- let that = this,
277
- data =
278
- isObservableObject(that.valueOf()) &&
279
- that.valueOf() instanceof Array === false
280
- ? structuredClone(Object.assign({}, that))
281
- : that.valueOf();
272
+ let data =
273
+ isObservableObject(this.valueOf()) &&
274
+ this.valueOf() instanceof Array === false
275
+ ? structuredClone(Object.assign({}, this))
276
+ : this.valueOf();
282
277
 
283
278
  if (notify !== undefined) {
284
- that.#notify = notify;
279
+ this.#notify = notify;
285
280
  // return;
286
281
  }
287
282
 
288
- //if (that.#notify) console.log('notify', this, data);
289
- (that as any).#callbacks.forEach((f: Function) => {
283
+ //if (this.#notify) console.log('notify', this, data);
284
+ (this as any).#callbacks.forEach((f: Function) => {
290
285
  // console.log(
291
286
  // (this.constructor as any).callbacks,
292
287
  // 'notify: exec callback',
@@ -296,7 +291,7 @@ function makeObservable(val: any): Class<typeof val>{
296
291
  f(data);
297
292
  });
298
293
 
299
- return that;
294
+ return this;
300
295
  }
301
296
  };
302
297
 
package/src/selectors.ts CHANGED
@@ -29,249 +29,6 @@ const words = ( classes: Array<string> ): Array<string> => {
29
29
  return classes;
30
30
  }
31
31
 
32
- type inputTypes = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
33
-
34
- const getInputName = ( e: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement ): string => {
35
-
36
- let ret = e instanceof HTMLInputElement
37
- ? 'input'
38
- : e instanceof HTMLSelectElement
39
- ? 'select'
40
- : e instanceof HTMLTextAreaElement
41
- ? 'textarea'
42
- : ''
43
- ;
44
-
45
- return ret;
46
- }
47
-
48
-
49
- const getInputHandlers = ( e: HTMLElement | ShadowRoot ): LooseObject => {
50
-
51
- let
52
- //inputList = ( Array.from( e.querySelectorAll('*') ) as HTMLElement[] ).filter( i => isInputElement(i) ),
53
- inputList = $d('input,select,textarea', e).array,
54
- handlers: LooseObject = {};
55
-
56
- inputList.forEach( (i) => {
57
- const
58
- name: string = ( i as inputTypes ).getAttribute('name') || 'undefined';
59
-
60
- if ( name ){
61
- let h: InputBase;
62
- switch ( getInputName( i as inputTypes ) ){
63
- case 'input':
64
- //console.log( i, 'is HTMLInputElement');
65
- h = new InputHandler( i as HTMLInputElement, e ); // e = element to search radios in = radioBase
66
- Object.defineProperty( handlers, name, {
67
- enumerable: true,
68
- configurable: true,
69
- get: (): any => { return h.val },
70
- set: ( value: any ) => { h.val = value }
71
- });
72
- break;
73
- case 'select':
74
- //console.log( i, 'is HTMLSelectElement');
75
- h = new SelectHandler( i as HTMLSelectElement );
76
- Object.defineProperty( handlers, name, {
77
- enumerable: true,
78
- configurable: true,
79
- get: (): any => { return h.val },
80
- set: ( value: any ) => { h.val = value }
81
- });
82
- break;
83
- case 'textarea':
84
- //console.log( i, 'is HTMLTextAreaElement');
85
- h = new TextAreaHandler( i as HTMLTextAreaElement );
86
- Object.defineProperty( handlers, name, {
87
- enumerable: true,
88
- configurable: true,
89
- get: (): any => { return h.val },
90
- set: ( value: any ) => { h.val = value }
91
- });
92
- break;
93
- default:
94
- console.warn('handler missing:', name, 'for', i);
95
- break;
96
- }
97
- }
98
- });
99
-
100
- return handlers;
101
- }
102
-
103
- abstract class InputBase{
104
- constructor( e: any ){
105
- }
106
-
107
- abstract get val(): any;
108
-
109
- abstract set val( value: any );
110
-
111
- }
112
-
113
- class InputHandler extends InputBase {
114
-
115
- #e: HTMLInputElement;
116
- #type: string;
117
- #radioBase: any;
118
-
119
- constructor( e: HTMLInputElement, radioBase?: HTMLElement | ShadowRoot ){
120
- super( e );
121
- this.#e = e;
122
- this.#type = e.type;
123
- this.#radioBase = radioBase;
124
- }
125
-
126
- get val(): any{
127
- let that = this,
128
- type = that.#type,
129
- ret: any;
130
-
131
- switch (type){
132
- case 'radio':
133
- const check = $d( `input[type="radio"][name="${ this.#e.getAttribute('name') }"]`, this.#radioBase )
134
- .filter( e => e.checked );
135
- if ( !check.length ) return '';
136
- ret = check.array[0];
137
- return ret.value;
138
- case 'checkbox':
139
- return that.#e.checked;
140
- default:
141
- return that.#e.value;
142
- break;
143
- }
144
-
145
- return '';
146
- }
147
-
148
- set val( value: any ){
149
- let that = this,
150
- type = that.#type,
151
- ret: any;
152
-
153
- switch (type){
154
- case 'radio':
155
- const
156
- selection = `input[type="radio"][name="${ this.#e.getAttribute('name') }"]`,
157
- radios = $d( selection, this.#radioBase );
158
-
159
- // console.log('set radios', selection, this.#radioBase, radios.array );
160
-
161
- if ( !radios.length ) return;
162
-
163
- if ( value === '' ){ // uncheck all
164
- radios.forEach( r => { if (r.checked) r.checked = false } );
165
- //console.log('unset all radios', radios.array );
166
- return;
167
- }
168
-
169
- const setRadioElement = radios.filter( r => r.getAttribute('value') === value );
170
-
171
- if ( !setRadioElement.length ) return;
172
-
173
- // console.log('set this radio', setRadioElement.array );
174
-
175
- (setRadioElement.array[0] as HTMLInputElement).checked = true;
176
-
177
- // console.log('done', setRadioElement.array );
178
- return;
179
- break;
180
- case 'checkbox':
181
- that.#e.checked = value;
182
- break;
183
- default:
184
- that.#e.value = value;
185
- break;
186
- }
187
-
188
- return;
189
- }
190
-
191
- }
192
-
193
- class SelectHandler extends InputBase {
194
-
195
- #e: HTMLSelectElement;
196
- #multi: boolean = false;
197
-
198
- constructor( e: HTMLSelectElement ){
199
- super( e );
200
- this.#e = e;
201
- this.#multi = e.type === 'select-multiple';
202
- }
203
-
204
- get val(): string[] | string{
205
- const
206
- that = this,
207
- ret: string[] = [];
208
-
209
- // get all options
210
- const options = $d( that.#e.querySelectorAll('option') )
211
- .filter( o => o.selected )
212
- .forEach( o => { if ( o.selected ) ret.push( o.value ) } );
213
-
214
- if ( this.#multi ) return ret;
215
- return ret.length ? ret[0] : '';
216
- }
217
-
218
- set val( value: string[] | string ){
219
- const
220
- that = this;
221
-
222
- value = typeof value === 'string' ? [ value ] : value;
223
-
224
- //console.log('set values', value );
225
-
226
- // set all options
227
- const options = $d( that.#e.querySelectorAll('option') )
228
- .forEach( o => {
229
- if ( value.indexOf( o.value ) > -1 ) {
230
- o.setAttribute( 'selected', true )
231
- o.selected = true;
232
- } else {
233
- o.removeAttribute( 'selected' )
234
- o.selected = false;
235
- }
236
- });
237
-
238
- /*
239
- if (pOption.selected) {
240
- if (
241
- !pOption.disabled &&
242
- (!pOption.parentNode.disabled ||
243
- pOption.parentNode.nodeName !==
244
- 'optgroup')
245
- ) {
246
- var value = pOption.value;
247
-
248
- ret.push(value);
249
- }
250
- }
251
- */
252
- return;
253
- }
254
-
255
- }
256
-
257
- class TextAreaHandler extends InputBase {
258
- #e: HTMLTextAreaElement
259
- constructor( e: HTMLTextAreaElement ){
260
- super(e);
261
- this.#e = e;
262
- }
263
-
264
- get val(): string{
265
- return this.#e.value;
266
- }
267
-
268
- set val( value: string ){
269
- this.#e.value = value;
270
- return;
271
- }
272
-
273
- }
274
-
275
32
  /*
276
33
  selector classes
277
34
  */
@@ -303,28 +60,9 @@ class DomSelector{
303
60
  that = this,
304
61
  undefinedTags: Set<any> = new Set();
305
62
 
306
- // // console.log('DomSelector constructor', ...arguments);
307
-
308
63
  if ( !selection ) {
309
64
  return that;
310
65
  }
311
-
312
- /* autoloading disabled !
313
- if ( selection instanceof Array ){
314
- selection.forEach( (select) => {
315
- _getElementList( select, element ).forEach( (e) => {
316
- if ( e.localName?.indexOf('-') !== -1 || e.getAttribute?.('is') ) _loadRequirements( e );
317
- that.#set.add( e );
318
- });
319
- });
320
- } else {
321
- _getElementList( selection, element ).forEach( (e) => {
322
- if ( e.localName?.indexOf('-') !== -1 || e.getAttribute?.('is') ) _loadRequirements( e );
323
- that.#set.add( e );
324
- });
325
- }
326
- */
327
-
328
66
  }
329
67
 
330
68
  $t( nameSpace?: string ): TSelector {
@@ -652,20 +390,6 @@ class DomSelector{
652
390
  return that;
653
391
  }
654
392
 
655
- /*
656
- load(): DSelector{
657
- let that = this;
658
-
659
- if( !that.length ){
660
- that.add( document.body );
661
- }
662
-
663
- that.forEach( e => _loadRequirements( e ) );
664
-
665
- return that;
666
- }
667
- */
668
-
669
393
  next( selection?: selection, rootNode?: HTMLElement ): DSelector{
670
394
  let
671
395
  that: DomSelector = this,
@@ -805,7 +529,7 @@ class DomSelector{
805
529
  return that;
806
530
  }
807
531
 
808
- parents( selection?: selection, rootNode?: HTMLElement ): DSelector {
532
+ ancestors( selection?: selection, rootNode?: HTMLElement ): DSelector {
809
533
  let
810
534
  that: DomSelector = this,
811
535
  set: Set<HTMLElement> = new Set()
@@ -948,95 +672,6 @@ class DomSelector{
948
672
  return that;
949
673
  }
950
674
 
951
- // INFO:
952
- // val(): LooseObject; // no param: get all as LooseObject
953
- // val( p1: string ): Array<string> | number | string; // get from input name
954
- // val( p1: object ): DomSelector; // set from object
955
- // val( p1: string, p2: any ): DomSelector; // set from name and value
956
- val( p1?: any, p2?: any ): any {
957
-
958
- if ( !this.length ) return this;
959
-
960
- const
961
- that = this
962
- ;
963
-
964
- let result: any,
965
- handlers: LooseObject = getInputHandlers( that.array[0] );
966
-
967
- // work with it
968
- if ( !p1 ){ // get all inputs as LooseObject
969
- result = Object.assign( {}, handlers );
970
- // Object.keys( handlers ).forEach( ( key ) => result[key] = handlers.hasOwnProperty(key) ? handlers[key].val : undefined );
971
- } else {
972
- if ( isObject(p1) ){ // set inputs from Object
973
- Object.assign( handlers, p1 );
974
- // Object.keys( p1 ).forEach( ( key ) => !!handlers[key] ? handlers[key].val = p1[key] : false );
975
- result = that;
976
- } else if ( typeof p1 === 'string' ){
977
- if ( p2 === undefined ){ // get a single input
978
- result = handlers[p1];
979
- } else { // set a single input
980
- handlers[p1] = p2;
981
- result = that;
982
- }
983
- }
984
- }
985
-
986
- return result;
987
- }
988
-
989
- values( values?: LooseObject ): LooseObject {
990
- const
991
- that = this,
992
- holder: LooseObject = {};
993
-
994
- let
995
- data: LooseObject = {};
996
-
997
- //console.log( '$d().values()', values );
998
-
999
- if ( !that.length ) {
1000
- console.warn('no dom selection to search inputs in');
1001
- return {};
1002
- }
1003
-
1004
- let handlers = getInputHandlers( that.array[0] );
1005
-
1006
- //console.log( 'handlers', Object.keys(handlers), handlers['cb1'] );
1007
-
1008
- // let values = that.val();
1009
-
1010
- // console.log( 'values', values );
1011
-
1012
- Object.keys( handlers ).forEach( (key: string) => {
1013
- //console.log(key);
1014
- data[key] = handlers[key];
1015
- });
1016
-
1017
- // data = Object.assign( {}, that.val() )
1018
- //console.log( 'data', that.array[0], data, Object.keys( data ) );
1019
-
1020
- if ( Object.keys( data ).length === 0 ) {
1021
- console.warn('no inputs in this dom selection', that.array[0], data );
1022
- }
1023
-
1024
- //console.log( '$d val()', data );
1025
- if (values) {
1026
- Object
1027
- .keys( values )
1028
- .forEach( key => {
1029
- if ( handlers.hasOwnProperty(key) ) {
1030
- console.log( 'key found', key );
1031
- handlers[key] = values[key];
1032
- }
1033
- });
1034
- // .forEach( key => handlers[key] = values[key] )
1035
- }
1036
-
1037
- return structuredClone( Object.assign( handlers ) );
1038
- }
1039
-
1040
675
  /*
1041
676
  array method mapping
1042
677
  */
@@ -1434,7 +1069,7 @@ class TbSelector{
1434
1069
  return that;
1435
1070
  }
1436
1071
 
1437
- parents( nameSpace?: string ): TSelector {
1072
+ ancestors( nameSpace?: string ): TSelector {
1438
1073
 
1439
1074
  let
1440
1075
  that: TbSelector = this,
@@ -1,5 +1,11 @@
1
1
  'use strict';
2
- import { DC, defineCE, Observable, formValues, LooseObject } from './../../microcomponents.js';
2
+ import {
3
+ DC,
4
+ defineCE,
5
+ Observable,
6
+ formValues,
7
+ LooseObject
8
+ } from '../../microcomponents.js';
3
9
 
4
10
  defineCE(
5
11
  'test-testform',
@@ -12,8 +18,6 @@ defineCE(
12
18
 
13
19
  const that = this;
14
20
 
15
- delete that._mc; // not needed
16
-
17
21
  let shadow = (that as DC).target.attachShadow({ mode: 'open' });
18
22
  shadow.innerHTML = `<style>${that.css}</style>${that.template}`;
19
23
 
@@ -0,0 +1,12 @@
1
+ import { defineCE, getCE } from '../../microcomponents.js';
2
+
3
+ console.log( 'testfunction.ts' );
4
+
5
+ defineCE(
6
+ 'test-testfunction',
7
+ function testfunction( a: number, b:number ){
8
+ return a + b;
9
+ }
10
+ );
11
+
12
+ export default getCE( 'test-testfunction' );
@@ -1,12 +1,16 @@
1
- import { DC } from './../../microcomponents.js';
1
+ import { defineCE, getCE, DC } from '../../microcomponents.js';
2
2
 
3
- export default class testmc extends DC {
4
- constructor(target: HTMLElement) {
5
- super(target);
6
- delete this._mc; // not needed
7
- }
3
+ defineCE(
4
+ 'test-testmc',
5
+ class TestMc extends DC {
6
+ constructor(target: HTMLElement) {
7
+ super(target);
8
+ }
8
9
 
9
- oneInit() {
10
- // console.log('testmc connected to DOM');
10
+ oneInit() {
11
+ // console.log('testmc connected to DOM');
12
+ }
11
13
  }
12
- }
14
+ );
15
+
16
+ export default getCE( 'test-testmc' );