@twobirds/microcomponents 0.0.21 → 0.0.22
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/.gitlab-ci.yml +1 -0
- package/README.md +31 -12
- package/assets/documentation/MicroComponents.md +228 -0
- package/assets/my-tag.css +4 -0
- package/assets/test.html +5 -1
- package/dist/MC.d.ts +32 -0
- package/dist/MC.d.ts.map +1 -0
- package/dist/MC.min.js +414 -0
- package/dist/MC.ts +350 -0
- package/dist/MCbundle.d.ts +8 -0
- package/dist/MCbundle.d.ts.map +1 -0
- package/dist/MCbundle.min.js +1 -0
- package/dist/MCbundle.ts +8 -0
- package/dist/McEvent.d.ts +15 -0
- package/dist/McEvent.d.ts.map +1 -0
- package/dist/McEvent.ts +96 -0
- package/dist/autoloader.d.ts +2 -0
- package/dist/autoloader.d.ts.map +1 -0
- package/dist/autoloader.ts +98 -0
- package/dist/customElements.d.ts +5 -0
- package/dist/customElements.d.ts.map +1 -0
- package/dist/customElements.min.js +1 -0
- package/dist/customElements.ts +67 -0
- package/dist/customObservables.d.ts +3 -0
- package/dist/customObservables.d.ts.map +1 -0
- package/dist/customObservables.min.js +1 -0
- package/dist/customObservables.ts +340 -0
- package/dist/customSelectors.d.ts +108 -0
- package/dist/customSelectors.d.ts.map +1 -0
- package/dist/customSelectors.min.js +1 -0
- package/dist/customSelectors.ts +1634 -0
- package/dist/formValues.d.ts +4 -0
- package/dist/formValues.d.ts.map +1 -0
- package/dist/formValues.ts +275 -0
- package/dist/formvValues.min.js +1 -0
- package/dist/helpers.d.ts +11 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.ts +173 -0
- package/dist/microcomponents.es3.d.ts +1 -20
- package/dist/microcomponents.es3.d.ts.map +1 -1
- package/dist/test.d.ts +2 -0
- package/dist/test.d.ts.map +1 -0
- package/package.json +11 -7
- package/public/MC.js +273 -0
- package/public/MC.min.js +414 -0
- package/public/MCbundle.js +8 -0
- package/public/MCbundle.min.js +1 -0
- package/public/McEvent.js +74 -0
- package/public/MicroComponents.svg +15 -0
- package/public/assets/search.js +1 -1
- package/public/autoloader.js +57 -0
- package/public/classes/MC.DC.html +247 -0
- package/public/classes/MC.MC.html +150 -0
- package/public/classes/MC.McBase.html +123 -0
- package/public/classes/MCbundle.McEvent.html +184 -0
- package/public/customElements.js +48 -0
- package/public/customElements.min.js +1 -0
- package/public/customObservables.js +255 -0
- package/public/customObservables.min.js +1 -0
- package/public/customSelectors.js +1088 -0
- package/public/customSelectors.min.js +1 -0
- package/public/documentation/MicroComponents.md +228 -0
- package/public/formValues.js +211 -0
- package/public/formvValues.min.js +1 -0
- package/public/functions/MC.addListener.html +73 -0
- package/public/functions/MC.removeListener.html +69 -0
- package/public/functions/MCbundle._d.html +85 -0
- package/public/functions/MCbundle._t.html +85 -0
- package/public/functions/MCbundle.debounce.html +85 -0
- package/public/functions/MCbundle.deepEqual.html +85 -0
- package/public/functions/MCbundle.defineCE.html +98 -0
- package/public/functions/MCbundle.formValues.html +89 -0
- package/public/functions/MCbundle.getCE.html +83 -0
- package/public/functions/MCbundle.htmlToElements.html +83 -0
- package/public/functions/MCbundle.isObject.html +83 -0
- package/public/functions/MCbundle.kebabToPascal.html +83 -0
- package/public/functions/MCbundle.makeCO.html +85 -0
- package/public/functions/MCbundle.nameSpace.html +89 -0
- package/public/functions/MCbundle.parse.html +85 -0
- package/public/helpers.js +128 -0
- package/public/index.html +22 -13
- package/public/interfaces/MC.HTMLMcElement.html +3605 -0
- package/public/interfaces/MCbundle.DSelector.html +1010 -0
- package/public/interfaces/MCbundle.LooseObject.html +80 -0
- package/public/interfaces/MCbundle.TSelector.html +709 -0
- package/public/microcomponents.es3.js +348 -0
- package/public/modules/MC.html +84 -0
- package/public/modules/MCbundle.html +133 -0
- package/public/modules.html +4 -4
- package/public/my-tag.css +4 -0
- package/public/test.html +5 -1
- package/public/test.js +100 -202
- package/public/types/MCbundle.selection.html +74 -0
- package/public/types/MCbundle.singleSelector.html +74 -0
- package/src/MC.ts +350 -0
- package/src/MCbundle.ts +8 -0
- package/src/McEvent.ts +96 -0
- package/src/autoloader.ts +98 -0
- package/src/customElements.ts +67 -0
- package/src/customObservables.ts +340 -0
- package/src/customSelectors.ts +1634 -0
- package/src/formValues.ts +275 -0
- package/src/helpers.ts +173 -0
- package/src/microcomponents.es3.js +353 -82
- package/src/test.js +137 -218
- package/tsconfig.json +2 -2
- package/typedoc.json +1 -1
- package/webpack.config.js +233 -0
- package/dist/microcomponents.d.ts +0 -26
- package/dist/microcomponents.d.ts.map +0 -1
- package/dist/microcomponents.es3.js +0 -96
- package/dist/microcomponents.es3.min.js +0 -15
- package/dist/microcomponents.js +0 -176
- package/dist/microcomponents.min.js +0 -38
- package/dist/microcomponents.ts +0 -216
- package/public/classes/microcomponents.MC.html +0 -313
- package/public/classes/microcomponents_es3.MC.html +0 -336
- package/public/functions/microcomponents_es3.__isEmpty.html +0 -60
- package/public/microcomponents.js +0 -176
- package/public/modules/microcomponents.html +0 -57
- package/public/modules/microcomponents_es3.html +0 -60
- package/src/microcomponents.ts +0 -216
|
@@ -0,0 +1,1088 @@
|
|
|
1
|
+
import { addListener, removeListener } from './MC.js';
|
|
2
|
+
/*
|
|
3
|
+
helpers
|
|
4
|
+
*/
|
|
5
|
+
const isObject = (value) => {
|
|
6
|
+
return value != null && typeof value === 'object';
|
|
7
|
+
};
|
|
8
|
+
const words = (classes) => {
|
|
9
|
+
let classSet = new Set();
|
|
10
|
+
// read classes into set
|
|
11
|
+
classes.forEach(c => {
|
|
12
|
+
c = c.trim();
|
|
13
|
+
c.split(' ').forEach(e => {
|
|
14
|
+
if (e !== '') {
|
|
15
|
+
classSet.add(e);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
// now we have a sanitized array
|
|
20
|
+
classes = Array.from(classSet);
|
|
21
|
+
return classes;
|
|
22
|
+
};
|
|
23
|
+
const getInputName = (e) => {
|
|
24
|
+
let ret = e instanceof HTMLInputElement
|
|
25
|
+
? 'input'
|
|
26
|
+
: e instanceof HTMLSelectElement
|
|
27
|
+
? 'select'
|
|
28
|
+
: e instanceof HTMLTextAreaElement
|
|
29
|
+
? 'textarea'
|
|
30
|
+
: '';
|
|
31
|
+
return ret;
|
|
32
|
+
};
|
|
33
|
+
const getInputHandlers = (e) => {
|
|
34
|
+
let
|
|
35
|
+
//inputList = ( Array.from( e.querySelectorAll('*') ) as HTMLElement[] ).filter( i => isInputElement(i) ),
|
|
36
|
+
inputList = $d('input,select,textarea', e).array, handlers = {};
|
|
37
|
+
inputList.forEach((i) => {
|
|
38
|
+
const name = i.getAttribute('name') || 'undefined';
|
|
39
|
+
if (name) {
|
|
40
|
+
let h;
|
|
41
|
+
switch (getInputName(i)) {
|
|
42
|
+
case 'input':
|
|
43
|
+
//console.log( i, 'is HTMLInputElement');
|
|
44
|
+
h = new InputHandler(i, e); // e = element to search radios in = radioBase
|
|
45
|
+
Object.defineProperty(handlers, name, {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
configurable: true,
|
|
48
|
+
get: () => { return h.val; },
|
|
49
|
+
set: (value) => { h.val = value; }
|
|
50
|
+
});
|
|
51
|
+
break;
|
|
52
|
+
case 'select':
|
|
53
|
+
//console.log( i, 'is HTMLSelectElement');
|
|
54
|
+
h = new SelectHandler(i);
|
|
55
|
+
Object.defineProperty(handlers, name, {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
configurable: true,
|
|
58
|
+
get: () => { return h.val; },
|
|
59
|
+
set: (value) => { h.val = value; }
|
|
60
|
+
});
|
|
61
|
+
break;
|
|
62
|
+
case 'textarea':
|
|
63
|
+
//console.log( i, 'is HTMLTextAreaElement');
|
|
64
|
+
h = new TextAreaHandler(i);
|
|
65
|
+
Object.defineProperty(handlers, name, {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
get: () => { return h.val; },
|
|
69
|
+
set: (value) => { h.val = value; }
|
|
70
|
+
});
|
|
71
|
+
break;
|
|
72
|
+
default:
|
|
73
|
+
console.warn('handler missing:', name, 'for', i);
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
return handlers;
|
|
79
|
+
};
|
|
80
|
+
class InputBase {
|
|
81
|
+
constructor(e) {
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
class InputHandler extends InputBase {
|
|
85
|
+
#e;
|
|
86
|
+
#type;
|
|
87
|
+
#radioBase;
|
|
88
|
+
constructor(e, radioBase) {
|
|
89
|
+
super(e);
|
|
90
|
+
this.#e = e;
|
|
91
|
+
this.#type = e.type;
|
|
92
|
+
this.#radioBase = radioBase;
|
|
93
|
+
}
|
|
94
|
+
get val() {
|
|
95
|
+
let that = this, type = that.#type, ret;
|
|
96
|
+
switch (type) {
|
|
97
|
+
case 'radio':
|
|
98
|
+
const check = $d(`input[type="radio"][name="${this.#e.getAttribute('name')}"]`, this.#radioBase)
|
|
99
|
+
.filter(e => e.checked);
|
|
100
|
+
if (!check.length)
|
|
101
|
+
return '';
|
|
102
|
+
ret = check.array[0];
|
|
103
|
+
return ret.value;
|
|
104
|
+
case 'checkbox':
|
|
105
|
+
return that.#e.checked;
|
|
106
|
+
default:
|
|
107
|
+
return that.#e.value;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
return '';
|
|
111
|
+
}
|
|
112
|
+
set val(value) {
|
|
113
|
+
let that = this, type = that.#type, ret;
|
|
114
|
+
switch (type) {
|
|
115
|
+
case 'radio':
|
|
116
|
+
const selection = `input[type="radio"][name="${this.#e.getAttribute('name')}"]`, radios = $d(selection, this.#radioBase);
|
|
117
|
+
// console.log('set radios', selection, this.#radioBase, radios.array );
|
|
118
|
+
if (!radios.length)
|
|
119
|
+
return;
|
|
120
|
+
if (value === '') { // uncheck all
|
|
121
|
+
radios.forEach(r => { if (r.checked)
|
|
122
|
+
r.checked = false; });
|
|
123
|
+
//console.log('unset all radios', radios.array );
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const setRadioElement = radios.filter(r => r.getAttribute('value') === value);
|
|
127
|
+
if (!setRadioElement.length)
|
|
128
|
+
return;
|
|
129
|
+
// console.log('set this radio', setRadioElement.array );
|
|
130
|
+
setRadioElement.array[0].checked = true;
|
|
131
|
+
// console.log('done', setRadioElement.array );
|
|
132
|
+
return;
|
|
133
|
+
break;
|
|
134
|
+
case 'checkbox':
|
|
135
|
+
that.#e.checked = value;
|
|
136
|
+
break;
|
|
137
|
+
default:
|
|
138
|
+
that.#e.value = value;
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
class SelectHandler extends InputBase {
|
|
145
|
+
#e;
|
|
146
|
+
#multi = false;
|
|
147
|
+
constructor(e) {
|
|
148
|
+
super(e);
|
|
149
|
+
this.#e = e;
|
|
150
|
+
this.#multi = e.type === 'select-multiple';
|
|
151
|
+
}
|
|
152
|
+
get val() {
|
|
153
|
+
const that = this, ret = [];
|
|
154
|
+
// get all options
|
|
155
|
+
const options = $d(that.#e.querySelectorAll('option'))
|
|
156
|
+
.filter(o => o.selected)
|
|
157
|
+
.forEach(o => { if (o.selected)
|
|
158
|
+
ret.push(o.value); });
|
|
159
|
+
if (this.#multi)
|
|
160
|
+
return ret;
|
|
161
|
+
return ret.length ? ret[0] : '';
|
|
162
|
+
}
|
|
163
|
+
set val(value) {
|
|
164
|
+
const that = this;
|
|
165
|
+
value = typeof value === 'string' ? [value] : value;
|
|
166
|
+
//console.log('set values', value );
|
|
167
|
+
// set all options
|
|
168
|
+
const options = $d(that.#e.querySelectorAll('option'))
|
|
169
|
+
.forEach(o => {
|
|
170
|
+
if (value.indexOf(o.value) > -1) {
|
|
171
|
+
o.setAttribute('selected', true);
|
|
172
|
+
o.selected = true;
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
o.removeAttribute('selected');
|
|
176
|
+
o.selected = false;
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
/*
|
|
180
|
+
if (pOption.selected) {
|
|
181
|
+
if (
|
|
182
|
+
!pOption.disabled &&
|
|
183
|
+
(!pOption.parentNode.disabled ||
|
|
184
|
+
pOption.parentNode.nodeName !==
|
|
185
|
+
'optgroup')
|
|
186
|
+
) {
|
|
187
|
+
var value = pOption.value;
|
|
188
|
+
|
|
189
|
+
ret.push(value);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
*/
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
class TextAreaHandler extends InputBase {
|
|
197
|
+
#e;
|
|
198
|
+
constructor(e) {
|
|
199
|
+
super(e);
|
|
200
|
+
this.#e = e;
|
|
201
|
+
}
|
|
202
|
+
get val() {
|
|
203
|
+
return this.#e.value;
|
|
204
|
+
}
|
|
205
|
+
set val(value) {
|
|
206
|
+
this.#e.value = value;
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/*
|
|
211
|
+
selector classes
|
|
212
|
+
*/
|
|
213
|
+
class DomSelector {
|
|
214
|
+
#set = new Set();
|
|
215
|
+
get set() {
|
|
216
|
+
return this.#set;
|
|
217
|
+
}
|
|
218
|
+
get array() {
|
|
219
|
+
return Array.from(this.#set);
|
|
220
|
+
}
|
|
221
|
+
set set(set) {
|
|
222
|
+
this.#set = set;
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
get length() {
|
|
226
|
+
return this.#set.size;
|
|
227
|
+
}
|
|
228
|
+
constructor(selection, element = document.body) {
|
|
229
|
+
let that = this, undefinedTags = new Set();
|
|
230
|
+
// // console.log('DomSelector constructor', ...arguments);
|
|
231
|
+
if (!selection) {
|
|
232
|
+
return that;
|
|
233
|
+
}
|
|
234
|
+
/* autoloading disabled !
|
|
235
|
+
if ( selection instanceof Array ){
|
|
236
|
+
selection.forEach( (select) => {
|
|
237
|
+
_getElementList( select, element ).forEach( (e) => {
|
|
238
|
+
if ( e.localName?.indexOf('-') !== -1 || e.getAttribute?.('is') ) _loadRequirements( e );
|
|
239
|
+
that.#set.add( e );
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
} else {
|
|
243
|
+
_getElementList( selection, element ).forEach( (e) => {
|
|
244
|
+
if ( e.localName?.indexOf('-') !== -1 || e.getAttribute?.('is') ) _loadRequirements( e );
|
|
245
|
+
that.#set.add( e );
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
*/
|
|
249
|
+
}
|
|
250
|
+
$t(nameSpace) {
|
|
251
|
+
let result = new TbSelector();
|
|
252
|
+
this.#set.forEach((e) => {
|
|
253
|
+
if (e._mc) {
|
|
254
|
+
Object.values(e._mc).forEach((mc) => {
|
|
255
|
+
result.set.add(mc);
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
if (nameSpace) {
|
|
260
|
+
result.filter(mc => mc.nameSpace === nameSpace);
|
|
261
|
+
}
|
|
262
|
+
return result;
|
|
263
|
+
}
|
|
264
|
+
add(selection, target) {
|
|
265
|
+
let that = this;
|
|
266
|
+
$d(selection, target).forEach(element => {
|
|
267
|
+
that.#set.add(element);
|
|
268
|
+
});
|
|
269
|
+
return that;
|
|
270
|
+
}
|
|
271
|
+
addClass(...classes) {
|
|
272
|
+
// sanitize classes
|
|
273
|
+
classes = words(classes);
|
|
274
|
+
// now set those classes
|
|
275
|
+
this.forEach(element => {
|
|
276
|
+
element.classList.add(...classes);
|
|
277
|
+
});
|
|
278
|
+
return this;
|
|
279
|
+
}
|
|
280
|
+
after(selection, target) {
|
|
281
|
+
let that = this, after = $d(selection, target);
|
|
282
|
+
;
|
|
283
|
+
if (!after.length)
|
|
284
|
+
return that;
|
|
285
|
+
after
|
|
286
|
+
.first()
|
|
287
|
+
.forEach(element => {
|
|
288
|
+
that.array.reverse().forEach((e) => {
|
|
289
|
+
e.after(element);
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
return that;
|
|
293
|
+
}
|
|
294
|
+
append(selection, target) {
|
|
295
|
+
let that = this, addTo = that.array['0'], append = $d(selection, target);
|
|
296
|
+
if (addTo) {
|
|
297
|
+
append.forEach((e) => {
|
|
298
|
+
addTo.append(e);
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
return that;
|
|
302
|
+
}
|
|
303
|
+
appendTo(selection, target) {
|
|
304
|
+
let that = this, appendTo = $d(selection, target).array['0'];
|
|
305
|
+
if (appendTo) {
|
|
306
|
+
that.forEach((e) => {
|
|
307
|
+
appendTo.append(e);
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
return that;
|
|
311
|
+
}
|
|
312
|
+
attr(first, second) {
|
|
313
|
+
let that = this, attributes = {};
|
|
314
|
+
// if no elements in set -> skip
|
|
315
|
+
if (!that.length)
|
|
316
|
+
return that;
|
|
317
|
+
// if no arguments, return attributes of first in list as hash object
|
|
318
|
+
if (!arguments.length) {
|
|
319
|
+
Array.from([...that.set][0].attributes).forEach((attribute) => {
|
|
320
|
+
attributes[attribute.name] = attribute.value;
|
|
321
|
+
});
|
|
322
|
+
return attributes;
|
|
323
|
+
}
|
|
324
|
+
// if first is a string
|
|
325
|
+
// if no value (second) is given -> return attribute value of first element in node selection
|
|
326
|
+
// if value (second) is null -> remove attribute and return this
|
|
327
|
+
// else set attribute values and return this
|
|
328
|
+
if (typeof first === 'string') {
|
|
329
|
+
// return attributes
|
|
330
|
+
if (second === undefined) {
|
|
331
|
+
return [...that.set][0].getAttribute(first);
|
|
332
|
+
}
|
|
333
|
+
// remove attribute
|
|
334
|
+
if (second === null) {
|
|
335
|
+
[...that.set].forEach((e) => {
|
|
336
|
+
e.removeAttribute(first);
|
|
337
|
+
});
|
|
338
|
+
return that;
|
|
339
|
+
}
|
|
340
|
+
// if attribute value is an object -> convert to json string
|
|
341
|
+
if (typeof second === 'object') {
|
|
342
|
+
second = JSON.stringify(second);
|
|
343
|
+
}
|
|
344
|
+
// set attribute
|
|
345
|
+
[...that.set].forEach((e) => {
|
|
346
|
+
e.setAttribute(first, second);
|
|
347
|
+
});
|
|
348
|
+
return that;
|
|
349
|
+
}
|
|
350
|
+
// if first is an object set attributes to all nodes
|
|
351
|
+
if (typeof first === 'object') {
|
|
352
|
+
[...that.set].forEach((e) => {
|
|
353
|
+
Object.keys(first).forEach((key) => {
|
|
354
|
+
$d(e).attr(key, first.key);
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
return that;
|
|
358
|
+
}
|
|
359
|
+
return that;
|
|
360
|
+
}
|
|
361
|
+
before(selection, target) {
|
|
362
|
+
let that = this, before = $d(selection, target);
|
|
363
|
+
;
|
|
364
|
+
if (!before.length)
|
|
365
|
+
return that;
|
|
366
|
+
before
|
|
367
|
+
.first()
|
|
368
|
+
.forEach(element => {
|
|
369
|
+
that.forEach((e) => {
|
|
370
|
+
e.before(element);
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
return that;
|
|
374
|
+
}
|
|
375
|
+
children(selection, rootNode) {
|
|
376
|
+
let that = this, set = new Set();
|
|
377
|
+
that.#set.forEach((e) => {
|
|
378
|
+
Array.from(e.children).forEach((c) => {
|
|
379
|
+
set.add(c);
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
that = $d([...set]);
|
|
383
|
+
if (selection) {
|
|
384
|
+
let compare = $d(selection, rootNode);
|
|
385
|
+
that.filter((e) => compare.has(e));
|
|
386
|
+
}
|
|
387
|
+
return that;
|
|
388
|
+
}
|
|
389
|
+
descendants(selection, rootNode) {
|
|
390
|
+
let that = this, set = new Set();
|
|
391
|
+
that.#set.forEach((e) => {
|
|
392
|
+
e.querySelectorAll('*').forEach((h) => {
|
|
393
|
+
set.add(h);
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
that = $d([...set]);
|
|
397
|
+
if (selection) {
|
|
398
|
+
let compare = $d(selection, rootNode);
|
|
399
|
+
that.filter((e) => compare.has(e));
|
|
400
|
+
}
|
|
401
|
+
return that;
|
|
402
|
+
}
|
|
403
|
+
empty() {
|
|
404
|
+
return this.filter((e) => false);
|
|
405
|
+
}
|
|
406
|
+
first(selection, rootNode) {
|
|
407
|
+
let that = this, set = new Set(), compare = false;
|
|
408
|
+
;
|
|
409
|
+
// get compare selection if specified
|
|
410
|
+
if (selection) {
|
|
411
|
+
compare = $d(selection, rootNode);
|
|
412
|
+
}
|
|
413
|
+
// get compare selection if specified
|
|
414
|
+
that.#set.forEach((e) => {
|
|
415
|
+
if (e.parentNode) {
|
|
416
|
+
set.add(e.parentNode.children[0]);
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
// make result
|
|
420
|
+
that = $d([...set]);
|
|
421
|
+
// compare if necessay
|
|
422
|
+
if (selection) {
|
|
423
|
+
that.filter((e) => compare.has(e));
|
|
424
|
+
}
|
|
425
|
+
return that;
|
|
426
|
+
}
|
|
427
|
+
has(element) {
|
|
428
|
+
return this.#set.has(element);
|
|
429
|
+
}
|
|
430
|
+
hasClass(...classes) {
|
|
431
|
+
// sanitize classes
|
|
432
|
+
classes = words(classes);
|
|
433
|
+
// now test those classes
|
|
434
|
+
return this.every(e => {
|
|
435
|
+
return Array.from(e.classList).every(c => e.contains(c));
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
html(html) {
|
|
439
|
+
let that = this;
|
|
440
|
+
if (html) {
|
|
441
|
+
that.forEach((e) => {
|
|
442
|
+
!e.parentNode
|
|
443
|
+
? (() => {
|
|
444
|
+
console.warn('Cannot access the .innerHTML of a HTMLElement that hasnt been inserted yet', e);
|
|
445
|
+
console.trace(e, this);
|
|
446
|
+
console.info('If you called this from inside a Web Component constructor, consider using the %c[connected] event callback!', 'color: blue;');
|
|
447
|
+
})()
|
|
448
|
+
: e.innerHTML = html;
|
|
449
|
+
});
|
|
450
|
+
return that;
|
|
451
|
+
}
|
|
452
|
+
return that.array[0].innerHTML;
|
|
453
|
+
}
|
|
454
|
+
last(selection, rootNode) {
|
|
455
|
+
let that = this, set = new Set();
|
|
456
|
+
that.#set.forEach((e) => {
|
|
457
|
+
let siblings = e.parentNode?.children;
|
|
458
|
+
if (siblings) {
|
|
459
|
+
set.add(Array.from(siblings).at(-1));
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
that = $d([...set]);
|
|
463
|
+
if (selection) {
|
|
464
|
+
let compare = $d(selection, rootNode);
|
|
465
|
+
that.filter((e) => compare.has(e));
|
|
466
|
+
}
|
|
467
|
+
return that;
|
|
468
|
+
}
|
|
469
|
+
/*
|
|
470
|
+
load(): DSelector{
|
|
471
|
+
let that = this;
|
|
472
|
+
|
|
473
|
+
if( !that.length ){
|
|
474
|
+
that.add( document.body );
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
that.forEach( e => _loadRequirements( e ) );
|
|
478
|
+
|
|
479
|
+
return that;
|
|
480
|
+
}
|
|
481
|
+
*/
|
|
482
|
+
next(selection, rootNode) {
|
|
483
|
+
let that = this, set = new Set();
|
|
484
|
+
that.#set.forEach((e) => {
|
|
485
|
+
let siblings = e.parentNode?.children;
|
|
486
|
+
if (siblings) {
|
|
487
|
+
let arr = Array.from(siblings), pos = arr.indexOf(e) + 1;
|
|
488
|
+
if (pos < arr.length) {
|
|
489
|
+
set.add(arr.at(pos));
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
that = $d([...set]);
|
|
494
|
+
if (selection) {
|
|
495
|
+
let compare = $d(selection, rootNode);
|
|
496
|
+
that.filter((e) => compare.has(e));
|
|
497
|
+
}
|
|
498
|
+
return that;
|
|
499
|
+
}
|
|
500
|
+
normalize() {
|
|
501
|
+
let that = this;
|
|
502
|
+
that.#set.forEach((e) => { e.normalize(); });
|
|
503
|
+
return that;
|
|
504
|
+
}
|
|
505
|
+
off(eventName, cb) {
|
|
506
|
+
let that = this, eventNames = eventName.indexOf(' ') > -1
|
|
507
|
+
? eventName.split(' ')
|
|
508
|
+
: [eventName];
|
|
509
|
+
// remove handler
|
|
510
|
+
that.array.forEach((e) => {
|
|
511
|
+
eventNames.forEach(function (n) {
|
|
512
|
+
removeListener(e, n, cb);
|
|
513
|
+
});
|
|
514
|
+
});
|
|
515
|
+
return that;
|
|
516
|
+
}
|
|
517
|
+
on(eventName, cb, capture = false, once = false) {
|
|
518
|
+
let that = this, eventNames = eventName.indexOf(' ') > -1
|
|
519
|
+
? eventName.split(' ').filter((s) => s !== '')
|
|
520
|
+
: [eventName];
|
|
521
|
+
function wrapper() { wrapper.cb.apply(that, Array.from(arguments)); }
|
|
522
|
+
;
|
|
523
|
+
wrapper.cb = cb;
|
|
524
|
+
// attach handler
|
|
525
|
+
that.forEach((e) => {
|
|
526
|
+
eventNames.forEach(function (n) {
|
|
527
|
+
addListener(e, n, wrapper, capture, once);
|
|
528
|
+
});
|
|
529
|
+
});
|
|
530
|
+
return wrapper;
|
|
531
|
+
}
|
|
532
|
+
one(eventName, cb, capture = false) {
|
|
533
|
+
let that = this, eventNames = eventName.indexOf(' ') > -1
|
|
534
|
+
? eventName.split(' ').filter((s) => s !== '')
|
|
535
|
+
: [eventName];
|
|
536
|
+
function wrapper() { wrapper.cb.apply(that, Array.from(arguments)); }
|
|
537
|
+
;
|
|
538
|
+
wrapper.cb = cb;
|
|
539
|
+
// attach handler
|
|
540
|
+
that.forEach((e) => {
|
|
541
|
+
eventNames.forEach(function (n) {
|
|
542
|
+
addListener(e, n, wrapper, capture, true);
|
|
543
|
+
});
|
|
544
|
+
});
|
|
545
|
+
return wrapper;
|
|
546
|
+
}
|
|
547
|
+
parent(selection, rootNode) {
|
|
548
|
+
let that = this, set = new Set();
|
|
549
|
+
that.#set.forEach((e) => {
|
|
550
|
+
if (e.parentNode && e.parentNode.tagName !== 'HTML') {
|
|
551
|
+
set.add(e.parentNode);
|
|
552
|
+
}
|
|
553
|
+
});
|
|
554
|
+
that = $d([...set]);
|
|
555
|
+
if (selection) {
|
|
556
|
+
let compare = $d(selection, rootNode);
|
|
557
|
+
that.filter((e) => compare.has(e));
|
|
558
|
+
}
|
|
559
|
+
return that;
|
|
560
|
+
}
|
|
561
|
+
parents(selection, rootNode) {
|
|
562
|
+
let that = this, set = new Set();
|
|
563
|
+
that.#set.forEach((e) => {
|
|
564
|
+
let current = e;
|
|
565
|
+
while (current.parentNode && current.parentNode.tagName !== 'HTML') {
|
|
566
|
+
current = current.parentNode;
|
|
567
|
+
set.add(current);
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
that = $d([...set]);
|
|
571
|
+
if (selection) {
|
|
572
|
+
let compare = $d(selection, rootNode);
|
|
573
|
+
that.filter((e) => compare.has(e));
|
|
574
|
+
}
|
|
575
|
+
return that;
|
|
576
|
+
}
|
|
577
|
+
prepend(selection, target) {
|
|
578
|
+
let that = this, addTo = that.array['0'], prepend = $d(selection, target);
|
|
579
|
+
if (addTo) {
|
|
580
|
+
prepend.forEach((e) => {
|
|
581
|
+
addTo.prepend(e);
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
return that;
|
|
585
|
+
}
|
|
586
|
+
prev(selection, rootNode) {
|
|
587
|
+
let that = this, set = new Set();
|
|
588
|
+
that.#set.forEach((e) => {
|
|
589
|
+
let siblings = e.parentNode?.children;
|
|
590
|
+
if (siblings) {
|
|
591
|
+
let arr = Array.from(siblings), pos = arr.indexOf(e) - 1;
|
|
592
|
+
if (pos > -1) {
|
|
593
|
+
set.add(arr.at(pos));
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
that = $d([...set]);
|
|
598
|
+
if (selection) {
|
|
599
|
+
let compare = $d(selection, rootNode);
|
|
600
|
+
that.filter((e) => compare.has(e));
|
|
601
|
+
}
|
|
602
|
+
return that;
|
|
603
|
+
}
|
|
604
|
+
removeClass(...classes) {
|
|
605
|
+
// sanitize classes
|
|
606
|
+
classes = words(classes);
|
|
607
|
+
// now set those classes
|
|
608
|
+
this.forEach(element => {
|
|
609
|
+
element.classList.remove(...classes);
|
|
610
|
+
});
|
|
611
|
+
return this;
|
|
612
|
+
}
|
|
613
|
+
text(text) {
|
|
614
|
+
let that = this;
|
|
615
|
+
if (text) {
|
|
616
|
+
that.forEach((e) => {
|
|
617
|
+
!e.parentNode
|
|
618
|
+
? (() => {
|
|
619
|
+
console.warn('Cannot access the .textContent of a HTMLElement that hasnt been inserted yet', e);
|
|
620
|
+
console.trace(e, this);
|
|
621
|
+
console.info('If you called this from inside a Web Component constructor, consider using the %c[connected] event callback!', 'color: blue;');
|
|
622
|
+
})()
|
|
623
|
+
: e.innerText = text;
|
|
624
|
+
});
|
|
625
|
+
return that;
|
|
626
|
+
}
|
|
627
|
+
let t = that.array[0].innerText;
|
|
628
|
+
return t ?? '';
|
|
629
|
+
}
|
|
630
|
+
toggleClass(...classes) {
|
|
631
|
+
// sanitize classes
|
|
632
|
+
classes = words(classes);
|
|
633
|
+
// now set those classes
|
|
634
|
+
this.forEach(element => {
|
|
635
|
+
element.classList.toggle(...classes);
|
|
636
|
+
});
|
|
637
|
+
return this;
|
|
638
|
+
}
|
|
639
|
+
trigger(eventName, data = {}, bubbles = false, cancelable = false, composed = false) {
|
|
640
|
+
let that = this, ev, options = { bubbles, cancelable, composed }, eventNames = eventName.indexOf(' ') > -1
|
|
641
|
+
? eventName.split(' ')
|
|
642
|
+
: [eventName];
|
|
643
|
+
that.#set.forEach((e) => {
|
|
644
|
+
eventNames.forEach(function (n) {
|
|
645
|
+
// console.log()
|
|
646
|
+
ev = new Event(n, options);
|
|
647
|
+
ev.data = data;
|
|
648
|
+
e.dispatchEvent(ev);
|
|
649
|
+
});
|
|
650
|
+
});
|
|
651
|
+
return that;
|
|
652
|
+
}
|
|
653
|
+
// INFO:
|
|
654
|
+
// val(): LooseObject; // no param: get all as LooseObject
|
|
655
|
+
// val( p1: string ): Array<string> | number | string; // get from input name
|
|
656
|
+
// val( p1: object ): DomSelector; // set from object
|
|
657
|
+
// val( p1: string, p2: any ): DomSelector; // set from name and value
|
|
658
|
+
val(p1, p2) {
|
|
659
|
+
if (!this.length)
|
|
660
|
+
return this;
|
|
661
|
+
const that = this;
|
|
662
|
+
let result, handlers = getInputHandlers(that.array[0]);
|
|
663
|
+
// work with it
|
|
664
|
+
if (!p1) { // get all inputs as LooseObject
|
|
665
|
+
result = Object.assign({}, handlers);
|
|
666
|
+
// Object.keys( handlers ).forEach( ( key ) => result[key] = handlers.hasOwnProperty(key) ? handlers[key].val : undefined );
|
|
667
|
+
}
|
|
668
|
+
else {
|
|
669
|
+
if (isObject(p1)) { // set inputs from Object
|
|
670
|
+
Object.assign(handlers, p1);
|
|
671
|
+
// Object.keys( p1 ).forEach( ( key ) => !!handlers[key] ? handlers[key].val = p1[key] : false );
|
|
672
|
+
result = that;
|
|
673
|
+
}
|
|
674
|
+
else if (typeof p1 === 'string') {
|
|
675
|
+
if (p2 === undefined) { // get a single input
|
|
676
|
+
result = handlers[p1];
|
|
677
|
+
}
|
|
678
|
+
else { // set a single input
|
|
679
|
+
handlers[p1] = p2;
|
|
680
|
+
result = that;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
return result;
|
|
685
|
+
}
|
|
686
|
+
values(values) {
|
|
687
|
+
const that = this, holder = {};
|
|
688
|
+
let data = {};
|
|
689
|
+
//console.log( '$d().values()', values );
|
|
690
|
+
if (!that.length) {
|
|
691
|
+
console.warn('no dom selection to search inputs in');
|
|
692
|
+
return {};
|
|
693
|
+
}
|
|
694
|
+
let handlers = getInputHandlers(that.array[0]);
|
|
695
|
+
//console.log( 'handlers', Object.keys(handlers), handlers['cb1'] );
|
|
696
|
+
// let values = that.val();
|
|
697
|
+
// console.log( 'values', values );
|
|
698
|
+
Object.keys(handlers).forEach((key) => {
|
|
699
|
+
//console.log(key);
|
|
700
|
+
data[key] = handlers[key];
|
|
701
|
+
});
|
|
702
|
+
// data = Object.assign( {}, that.val() )
|
|
703
|
+
//console.log( 'data', that.array[0], data, Object.keys( data ) );
|
|
704
|
+
if (Object.keys(data).length === 0) {
|
|
705
|
+
console.warn('no inputs in this dom selection', that.array[0], data);
|
|
706
|
+
}
|
|
707
|
+
//console.log( '$d val()', data );
|
|
708
|
+
if (values) {
|
|
709
|
+
Object
|
|
710
|
+
.keys(values)
|
|
711
|
+
.forEach(key => {
|
|
712
|
+
if (handlers.hasOwnProperty(key)) {
|
|
713
|
+
console.log('key found', key);
|
|
714
|
+
handlers[key] = values[key];
|
|
715
|
+
}
|
|
716
|
+
});
|
|
717
|
+
// .forEach( key => handlers[key] = values[key] )
|
|
718
|
+
}
|
|
719
|
+
return structuredClone(Object.assign(handlers));
|
|
720
|
+
}
|
|
721
|
+
/*
|
|
722
|
+
array method mapping
|
|
723
|
+
*/
|
|
724
|
+
at(index) {
|
|
725
|
+
return $d(this.array.at(index));
|
|
726
|
+
}
|
|
727
|
+
concat(items) {
|
|
728
|
+
let that = this, arr = items instanceof DomSelector
|
|
729
|
+
? items.array
|
|
730
|
+
: items;
|
|
731
|
+
arr.forEach((e) => {
|
|
732
|
+
that.#set.add(e);
|
|
733
|
+
});
|
|
734
|
+
return that;
|
|
735
|
+
}
|
|
736
|
+
entries() {
|
|
737
|
+
return this.array.entries();
|
|
738
|
+
}
|
|
739
|
+
every(predicate, thisArg) {
|
|
740
|
+
return this.array.every(predicate, thisArg);
|
|
741
|
+
}
|
|
742
|
+
filter(predicate, thisArg) {
|
|
743
|
+
this.#set = new Set(this.array.filter(predicate, thisArg));
|
|
744
|
+
return this;
|
|
745
|
+
}
|
|
746
|
+
forEach(predicate, thisArg) {
|
|
747
|
+
this.array.forEach(predicate, thisArg);
|
|
748
|
+
return this;
|
|
749
|
+
}
|
|
750
|
+
includes(item) {
|
|
751
|
+
return this.array.indexOf(item, 0) !== -1;
|
|
752
|
+
}
|
|
753
|
+
indexOf(item, start) {
|
|
754
|
+
return this.array.indexOf(item, start);
|
|
755
|
+
}
|
|
756
|
+
map(predicate, thisArg) {
|
|
757
|
+
return this.array.map(predicate, thisArg);
|
|
758
|
+
}
|
|
759
|
+
pop() {
|
|
760
|
+
return this.array.pop();
|
|
761
|
+
}
|
|
762
|
+
push(...items) {
|
|
763
|
+
items.forEach((item) => {
|
|
764
|
+
this.#set.add(item);
|
|
765
|
+
});
|
|
766
|
+
return this;
|
|
767
|
+
}
|
|
768
|
+
shift() {
|
|
769
|
+
let that = this, element = that.#set.size ? that.array[0] : undefined;
|
|
770
|
+
if (element) {
|
|
771
|
+
that.#set.delete(element);
|
|
772
|
+
}
|
|
773
|
+
return element;
|
|
774
|
+
}
|
|
775
|
+
slice(start, end) {
|
|
776
|
+
return $d(this.array.slice(start, end));
|
|
777
|
+
}
|
|
778
|
+
some(predicate, thisArg) {
|
|
779
|
+
return this.array.some(predicate, thisArg);
|
|
780
|
+
}
|
|
781
|
+
splice(start, deleteCount, ...items) {
|
|
782
|
+
let that = this, arr = that.array;
|
|
783
|
+
arr.splice(start, deleteCount, ...items);
|
|
784
|
+
return $d(arr);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
;
|
|
788
|
+
class TbSelector {
|
|
789
|
+
#set = new Set();
|
|
790
|
+
get set() {
|
|
791
|
+
return this.#set;
|
|
792
|
+
}
|
|
793
|
+
get array() {
|
|
794
|
+
return Array.from(this.#set);
|
|
795
|
+
}
|
|
796
|
+
set set(set) {
|
|
797
|
+
this.#set = set;
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
get length() {
|
|
801
|
+
return this.#set.size;
|
|
802
|
+
}
|
|
803
|
+
set length(value) {
|
|
804
|
+
//ignore
|
|
805
|
+
}
|
|
806
|
+
constructor(selection, element = document.body) {
|
|
807
|
+
if (!selection) {
|
|
808
|
+
return this;
|
|
809
|
+
}
|
|
810
|
+
$d(selection, element).forEach((e) => {
|
|
811
|
+
$t(e).forEach((t) => {
|
|
812
|
+
this.#set.add(t);
|
|
813
|
+
});
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
$d(selection, element = document.body) {
|
|
817
|
+
let result = new DomSelector(), set = new Set(), compare = !!selection || false, compareSelection = new Set();
|
|
818
|
+
if (compare) {
|
|
819
|
+
compareSelection = $d(selection, element).set;
|
|
820
|
+
}
|
|
821
|
+
this.#set.forEach((e) => {
|
|
822
|
+
if (!compare || compareSelection.has(e._tg)) {
|
|
823
|
+
set.add(e._tg);
|
|
824
|
+
}
|
|
825
|
+
});
|
|
826
|
+
result.set = set;
|
|
827
|
+
return result;
|
|
828
|
+
}
|
|
829
|
+
children(nameSpace) {
|
|
830
|
+
let that = this, set = new Set();
|
|
831
|
+
that.#set.forEach((e) => {
|
|
832
|
+
e.children(nameSpace).forEach((tb) => {
|
|
833
|
+
set.add(tb);
|
|
834
|
+
});
|
|
835
|
+
});
|
|
836
|
+
that.#set = set;
|
|
837
|
+
return that;
|
|
838
|
+
}
|
|
839
|
+
descendants(nameSpace) {
|
|
840
|
+
let that = this, set = new Set();
|
|
841
|
+
that.#set.forEach((e) => {
|
|
842
|
+
e.descendants(nameSpace).forEach((tb) => {
|
|
843
|
+
set.add(tb);
|
|
844
|
+
});
|
|
845
|
+
});
|
|
846
|
+
that.#set = set;
|
|
847
|
+
return that;
|
|
848
|
+
}
|
|
849
|
+
first(nameSpace) {
|
|
850
|
+
let that = this, set = new Set();
|
|
851
|
+
that.#set.forEach((e) => {
|
|
852
|
+
e
|
|
853
|
+
.parent()
|
|
854
|
+
.children()
|
|
855
|
+
.$d()
|
|
856
|
+
.first()
|
|
857
|
+
.$t()
|
|
858
|
+
.forEach((tb) => {
|
|
859
|
+
set.add(tb);
|
|
860
|
+
});
|
|
861
|
+
});
|
|
862
|
+
that.#set = set;
|
|
863
|
+
if (nameSpace) {
|
|
864
|
+
that.filter((tb) => tb.nameSpace = nameSpace);
|
|
865
|
+
}
|
|
866
|
+
return that;
|
|
867
|
+
}
|
|
868
|
+
has(element) {
|
|
869
|
+
return this.#set.has(element);
|
|
870
|
+
}
|
|
871
|
+
last(nameSpace) {
|
|
872
|
+
let that = this, set = new Set();
|
|
873
|
+
that.#set.forEach((e) => {
|
|
874
|
+
e
|
|
875
|
+
.parent()
|
|
876
|
+
.children()
|
|
877
|
+
.$d()
|
|
878
|
+
.last()
|
|
879
|
+
.$t()
|
|
880
|
+
.forEach((tb) => {
|
|
881
|
+
set.add(tb);
|
|
882
|
+
});
|
|
883
|
+
});
|
|
884
|
+
that.#set = set;
|
|
885
|
+
if (nameSpace) {
|
|
886
|
+
that.filter((e) => e.nameSpace = nameSpace);
|
|
887
|
+
}
|
|
888
|
+
return that;
|
|
889
|
+
}
|
|
890
|
+
next(nameSpace) {
|
|
891
|
+
let that = this, set = new Set();
|
|
892
|
+
that.#set.forEach((e) => {
|
|
893
|
+
let elements = new Set(), element;
|
|
894
|
+
element = e._tg;
|
|
895
|
+
while (element.nextElementSibling !== null) {
|
|
896
|
+
element = element.nextElementSibling;
|
|
897
|
+
elements.add(element);
|
|
898
|
+
}
|
|
899
|
+
$t([...elements])
|
|
900
|
+
.$d()
|
|
901
|
+
.first()
|
|
902
|
+
.$t()
|
|
903
|
+
.forEach((tb) => {
|
|
904
|
+
set.add(tb);
|
|
905
|
+
});
|
|
906
|
+
});
|
|
907
|
+
that.#set = set;
|
|
908
|
+
if (nameSpace) {
|
|
909
|
+
that.filter((e) => e.nameSpace = nameSpace);
|
|
910
|
+
}
|
|
911
|
+
return that;
|
|
912
|
+
}
|
|
913
|
+
ns(nameSpace) {
|
|
914
|
+
return this.filter((tb) => tb.nameSpace === nameSpace);
|
|
915
|
+
}
|
|
916
|
+
off(name, cb) {
|
|
917
|
+
let that = this, eventNames = name.indexOf(' ') > -1
|
|
918
|
+
? name.split(' ').filter((s) => s !== '')
|
|
919
|
+
: [name];
|
|
920
|
+
// remove handlers
|
|
921
|
+
that.$d().array.forEach((e) => {
|
|
922
|
+
eventNames.forEach(function (n) {
|
|
923
|
+
// console.log('Tb Selector remove event', `[TB]${n}`, e, cb );
|
|
924
|
+
removeListener(e, `[TB]${n}`, cb);
|
|
925
|
+
});
|
|
926
|
+
});
|
|
927
|
+
return that;
|
|
928
|
+
}
|
|
929
|
+
on(name, cb, once = false) {
|
|
930
|
+
let that = this, eventNames = name.indexOf(' ') > -1
|
|
931
|
+
? name.split(' ').filter((s) => s !== '')
|
|
932
|
+
: [name];
|
|
933
|
+
function wrapper() { wrapper.cb.apply(that, Array.from(arguments)); }
|
|
934
|
+
;
|
|
935
|
+
wrapper.cb = cb;
|
|
936
|
+
// attach handler
|
|
937
|
+
that.forEach((tb) => {
|
|
938
|
+
eventNames.forEach(function (n) {
|
|
939
|
+
addListener(tb._tg, `[TB]${n}`, wrapper, false, once);
|
|
940
|
+
});
|
|
941
|
+
});
|
|
942
|
+
return wrapper;
|
|
943
|
+
}
|
|
944
|
+
one(name, cb) {
|
|
945
|
+
let that = this, eventNames = name.indexOf(' ') > -1
|
|
946
|
+
? name.split(' ').filter((s) => s !== '')
|
|
947
|
+
: [name];
|
|
948
|
+
function wrapper() { wrapper.cb.apply(that, Array.from(arguments)); }
|
|
949
|
+
;
|
|
950
|
+
wrapper.cb = cb;
|
|
951
|
+
// attach handler
|
|
952
|
+
that.forEach((tb) => {
|
|
953
|
+
eventNames.forEach(function (n) {
|
|
954
|
+
addListener(tb._tg, `[TB]${n}`, wrapper, false, true);
|
|
955
|
+
});
|
|
956
|
+
});
|
|
957
|
+
return wrapper;
|
|
958
|
+
}
|
|
959
|
+
parent(nameSpace) {
|
|
960
|
+
let that = this, set = new Set();
|
|
961
|
+
that.#set.forEach((e) => {
|
|
962
|
+
e.parent(nameSpace).forEach((tb) => {
|
|
963
|
+
set.add(tb);
|
|
964
|
+
});
|
|
965
|
+
});
|
|
966
|
+
that.#set = set;
|
|
967
|
+
return that;
|
|
968
|
+
}
|
|
969
|
+
parents(nameSpace) {
|
|
970
|
+
let that = this, set = new Set();
|
|
971
|
+
that.#set.forEach((e) => {
|
|
972
|
+
e.parents(nameSpace).forEach((tb) => {
|
|
973
|
+
set.add(tb);
|
|
974
|
+
});
|
|
975
|
+
});
|
|
976
|
+
that.#set = set;
|
|
977
|
+
return that;
|
|
978
|
+
}
|
|
979
|
+
prev(nameSpace) {
|
|
980
|
+
let that = this, set = new Set();
|
|
981
|
+
that.#set.forEach((e) => {
|
|
982
|
+
let elements = new Set(), element;
|
|
983
|
+
element = e._tg;
|
|
984
|
+
while (element.previousElementSibling !== null) {
|
|
985
|
+
element = element.previousElementSibling;
|
|
986
|
+
elements.add(element);
|
|
987
|
+
}
|
|
988
|
+
$t([...elements])
|
|
989
|
+
.$d()
|
|
990
|
+
.last()
|
|
991
|
+
.$t()
|
|
992
|
+
.forEach((tb) => {
|
|
993
|
+
set.add(tb);
|
|
994
|
+
});
|
|
995
|
+
});
|
|
996
|
+
that.#set = set;
|
|
997
|
+
if (nameSpace) {
|
|
998
|
+
that.filter((e) => e.nameSpace = nameSpace);
|
|
999
|
+
}
|
|
1000
|
+
return that;
|
|
1001
|
+
}
|
|
1002
|
+
trigger(ev, data = {}, bubble = 'l') {
|
|
1003
|
+
let that = this;
|
|
1004
|
+
that.forEach((tb) => {
|
|
1005
|
+
tb.trigger(ev, data, bubble);
|
|
1006
|
+
});
|
|
1007
|
+
return that;
|
|
1008
|
+
}
|
|
1009
|
+
/*
|
|
1010
|
+
array method mapping
|
|
1011
|
+
*/
|
|
1012
|
+
at(index) {
|
|
1013
|
+
return $t(this.array.at(index));
|
|
1014
|
+
}
|
|
1015
|
+
concat(items) {
|
|
1016
|
+
let that = this;
|
|
1017
|
+
items.forEach((tb) => {
|
|
1018
|
+
that.#set.add(tb);
|
|
1019
|
+
});
|
|
1020
|
+
return that;
|
|
1021
|
+
}
|
|
1022
|
+
entries() {
|
|
1023
|
+
return this.array.entries();
|
|
1024
|
+
}
|
|
1025
|
+
every(predicate, thisArg) {
|
|
1026
|
+
return this.array.every(predicate, thisArg);
|
|
1027
|
+
}
|
|
1028
|
+
filter(predicate, thisArg) {
|
|
1029
|
+
return $t(this.array.filter(predicate, thisArg));
|
|
1030
|
+
}
|
|
1031
|
+
forEach(predicate, thisArg) {
|
|
1032
|
+
let that = this;
|
|
1033
|
+
that.array.forEach(predicate, thisArg);
|
|
1034
|
+
return that;
|
|
1035
|
+
}
|
|
1036
|
+
includes(item) {
|
|
1037
|
+
return this.array.indexOf(item) !== -1;
|
|
1038
|
+
}
|
|
1039
|
+
indexOf(item, start) {
|
|
1040
|
+
return this.array.indexOf(item, start);
|
|
1041
|
+
}
|
|
1042
|
+
map(predicate, thisArg) {
|
|
1043
|
+
return this.array.map(predicate, thisArg);
|
|
1044
|
+
}
|
|
1045
|
+
pop() {
|
|
1046
|
+
let that = this, arr = that.array, result = arr.pop();
|
|
1047
|
+
that.#set = new Set(arr);
|
|
1048
|
+
return result;
|
|
1049
|
+
}
|
|
1050
|
+
push(item) {
|
|
1051
|
+
let that = this;
|
|
1052
|
+
that.#set.add(item);
|
|
1053
|
+
return that;
|
|
1054
|
+
}
|
|
1055
|
+
shift() {
|
|
1056
|
+
let that = this, first = this.array.shift();
|
|
1057
|
+
that.#set.delete(first);
|
|
1058
|
+
return first;
|
|
1059
|
+
}
|
|
1060
|
+
slice(start, end) {
|
|
1061
|
+
return $t(this.array.slice(start, end));
|
|
1062
|
+
}
|
|
1063
|
+
some(predicate, thisArg) {
|
|
1064
|
+
return this.array.some(predicate, thisArg);
|
|
1065
|
+
}
|
|
1066
|
+
splice(start, deleteCount, ...items) {
|
|
1067
|
+
let that = this, arr = that.array, result = arr.splice(start, deleteCount, ...items);
|
|
1068
|
+
return $t(result);
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
;
|
|
1072
|
+
export const $d = (selection, element = document) => {
|
|
1073
|
+
let set = new Set();
|
|
1074
|
+
if (selection instanceof Array) {
|
|
1075
|
+
selection.forEach(value => {
|
|
1076
|
+
$d(value, element).forEach(n => {
|
|
1077
|
+
set.add(n);
|
|
1078
|
+
});
|
|
1079
|
+
});
|
|
1080
|
+
return new DomSelector([...set]);
|
|
1081
|
+
}
|
|
1082
|
+
else {
|
|
1083
|
+
return new DomSelector(selection, element);
|
|
1084
|
+
}
|
|
1085
|
+
};
|
|
1086
|
+
export const $t = (selection, element = document) => {
|
|
1087
|
+
return $d(selection, element).$t();
|
|
1088
|
+
};
|