@twobirds/microcomponents 0.0.50 → 0.0.52

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 (44) hide show
  1. package/dist/formValues.d.ts.map +1 -1
  2. package/dist/formValues.ts +19 -47
  3. package/dist/formvValues.min.js +1 -1
  4. package/dist/microcomponents.min.js +1 -1
  5. package/package.json +1 -1
  6. package/public/assets/search.js +1 -1
  7. package/public/classes/MC.DC.html +13 -13
  8. package/public/classes/MC.MC.html +7 -7
  9. package/public/classes/MC.McBase.html +4 -4
  10. package/public/classes/MC.McEvent.html +13 -13
  11. package/public/classes/formValues.FormValues.html +86 -0
  12. package/public/formValues.js +16 -42
  13. package/public/formValues.js.map +1 -1
  14. package/public/formvValues.min.js +1 -1
  15. package/public/functions/MC.addListener.html +2 -1
  16. package/public/functions/{formValues.formValues.html → MC.autoload.html} +18 -17
  17. package/public/functions/MC.removeListener.html +2 -1
  18. package/public/functions/elements.defineCE.html +1 -1
  19. package/public/functions/elements.getCE.html +1 -1
  20. package/public/functions/observables.observe.html +3 -3
  21. package/public/functions/selectors._d.html +1 -1
  22. package/public/functions/selectors._t.html +1 -1
  23. package/public/interfaces/MC.HTMLMcElement.html +2 -2
  24. package/public/interfaces/selectors.DSelector.html +55 -55
  25. package/public/interfaces/selectors.TSelector.html +37 -37
  26. package/public/microcomponents.min.js +1 -1
  27. package/public/modules/MC.html +3 -1
  28. package/public/modules/elements.html +1 -1
  29. package/public/modules/formValues.html +4 -4
  30. package/public/modules/observables.html +1 -1
  31. package/public/modules/selectors.html +1 -1
  32. package/public/src/formValues.ts +19 -47
  33. package/public/test/Testform.js +1 -1
  34. package/public/types/observables.Observable.html +1 -1
  35. package/public/types/selectors.selection.html +1 -1
  36. package/public/types/selectors.singleSelector.html +1 -1
  37. package/src/formValues.ts +19 -47
  38. package/public/Grandparent.js +0 -338
  39. package/public/TestForm.css +0 -47
  40. package/public/TestForm.html +0 -56
  41. package/public/TestForm.js +0 -56
  42. package/public/TestForm.json +0 -27
  43. package/public/Testform.js +0 -149
  44. package/public/documentation/observe.md +0 -317
@@ -1,338 +0,0 @@
1
- !(function (t, e) {
2
- 'object' == typeof exports && 'object' == typeof module
3
- ? (module.exports = e())
4
- : 'function' == typeof define && define.amd
5
- ? define([], e)
6
- : 'object' == typeof exports
7
- ? (exports.Grandparent = e())
8
- : (t.Grandparent = e());
9
- })(this, () =>
10
- (() => {
11
- 'use strict';
12
- var t = new Function('try {return this===window;}catch(e){ return false;}');
13
- let e = new Set();
14
- t() &&
15
- Object.keys(HTMLElement.prototype)
16
- .filter((t) => /^on/.test(t))
17
- .forEach((t) => e.add(t));
18
- class n {
19
- #t;
20
- #e = !1;
21
- #n = !1;
22
- constructor(t, e = {}, n = 'l') {
23
- (this.#t = t), (this.data = e), (this.bubble = n);
24
- }
25
- get type() {
26
- return this.#t;
27
- }
28
- get stopped() {
29
- return this.#e;
30
- }
31
- get immediateStopped() {
32
- return this.#n;
33
- }
34
- stopPropagation() {
35
- this.#e = !0;
36
- }
37
- stopImmediatePropagation() {
38
- this.stopPropagation(), (this.#n = !0);
39
- }
40
- }
41
- var r = new Function('try {return this===window;}catch(e){ return false;}');
42
- let o = new Set();
43
- function s(t, e) {
44
- let n = [];
45
- return (
46
- t.forEach((t) => {
47
- if (t && t instanceof HTMLElement) {
48
- const r = t?._mc;
49
- !e && r
50
- ? (n = n.concat(Object.values(t._mc)))
51
- : e && r && r[e] && n.push(r[e]);
52
- }
53
- }),
54
- n
55
- );
56
- }
57
- function c(t, e, n = !0) {
58
- let r = [];
59
- for (; t; ) {
60
- if (
61
- t._mc &&
62
- (e
63
- ? e && t._mc[e] && r.push(t._mc[e])
64
- : (r = r.concat(Object.values(t._mc))),
65
- n)
66
- )
67
- return r;
68
- t = t.parentNode;
69
- }
70
- return r;
71
- }
72
- function i(t) {
73
- return t && t instanceof HTMLElement;
74
- }
75
- function a(t, e, n = {}) {
76
- let r = t;
77
- if (!r._mc) {
78
- let e = f?.debug;
79
- (f.debug = !1), (r._mc = new f(t)), (f.debug = e), delete r._mc._mc;
80
- }
81
- const o = r._mc;
82
- return (
83
- e.length &&
84
- !o[e] &&
85
- ((o[e] = n), t instanceof HTMLElement && t.setAttribute('_mc', '')),
86
- n
87
- );
88
- }
89
- function u(t, e) {
90
- if (!e) return;
91
- const n = t?._mc || {};
92
- n && n[e] && delete n[e],
93
- !Object.keys(n).length &&
94
- t instanceof HTMLElement &&
95
- t.hasAttribute('_mc') &&
96
- t.removeAttribute('_mc');
97
- }
98
- function l(t, e, r = {}, o = 'l') {
99
- let s = t?._mc;
100
- if (!s) return;
101
- let c = e instanceof n ? new n(e.type, e.data, 'l') : new n(e, r, 'l'),
102
- i = 'string' != typeof e ? e : new n(e, r, o);
103
- [...Object.values(s)].forEach((t) => {
104
- t?.trigger && 'function' == typeof t?.trigger && t?.trigger(c);
105
- }),
106
- /[ud]/.test(i.bubble) && p(t, i);
107
- }
108
- function p(t, e) {
109
- /[ud]/.test(e.bubble) &&
110
- setTimeout(() => {
111
- if (
112
- (-1 === e.bubble.indexOf('l') && (e.bubble += 'l'),
113
- e.bubble.indexOf('u') > -1)
114
- ) {
115
- let n = c(t, '', !0)?.[0].target;
116
- n && f.trigger(n, e);
117
- }
118
- e.bubble.indexOf('d') > -1 &&
119
- new Set(t._mc.children().map((t) => t?.target)).forEach((t) => {
120
- t && f.trigger(t, e);
121
- });
122
- }, 0);
123
- }
124
- r() &&
125
- Object.keys(HTMLElement.prototype)
126
- .filter((t) => /^on/.test(t))
127
- .forEach((t) => o.add(t));
128
- class d {
129
- #r;
130
- constructor(t, e = !1) {
131
- var n;
132
- (this.#r = new WeakRef(t || {})),
133
- (n = this).constructor !== f &&
134
- setTimeout(() => {
135
- n.trigger('Init');
136
- }, 0),
137
- (function (t) {
138
- if (!r() || t.constructor === f) return;
139
- const e = t.target;
140
- if (e instanceof HTMLElement) {
141
- let n = t;
142
- Object.getOwnPropertyNames(n.constructor.prototype)
143
- .filter(
144
- (t) =>
145
- /^on[A-Z]|one[A-Z]/.test(t) &&
146
- 'function' == typeof n.constructor.prototype[t]
147
- )
148
- .forEach((r) => {
149
- let s = /^one/.test(r),
150
- c = r.replace(/^on[e]{0,1}/, ''),
151
- i = c.toLowerCase();
152
- s &&
153
- Object.defineProperty(t, 'on' + c, {
154
- configurable: !0,
155
- enumerable: !1,
156
- writable: !0,
157
- value: (t) => {
158
- n.constructor.prototype[r].bind(n)(t);
159
- },
160
- }),
161
- o.has('on' + i) &&
162
- (function (t, e, n, r = !1, o = !1) {
163
- let s = { once: !1 };
164
- r && (s.capture = r),
165
- o && (s.once = o),
166
- t.addEventListener(e, n, s);
167
- })(
168
- e,
169
- i,
170
- (t) => {
171
- n.trigger(c, t);
172
- },
173
- !1,
174
- s
175
- );
176
- });
177
- }
178
- })(this);
179
- }
180
- get target() {
181
- return this.#r.deref();
182
- }
183
- }
184
- class g extends d {
185
- _mc = {};
186
- constructor(t) {
187
- super(t);
188
- }
189
- static trigger = l;
190
- trigger(t, e = {}, r = 'l') {
191
- let o = this;
192
- if (o.constructor === g || o.constructor === f) {
193
- let s =
194
- t instanceof n ? new n(t.type, t.data, 'l') : new n(t, e, 'l'),
195
- c = 'string' != typeof t ? t : new n(t, e, r);
196
- return (
197
- [...Object.getOwnPropertyNames(o)].forEach((t) => {
198
- o[t]?.trigger &&
199
- 'function' == typeof o[t]?.trigger &&
200
- o[t]?.trigger(s);
201
- }),
202
- void (/[ud]/.test(c.bubble) && p(o.target, c))
203
- );
204
- }
205
- if (o instanceof g || o instanceof f) {
206
- const o = this,
207
- s = 'string' != typeof t ? t : new n(t, e, r),
208
- c = 'on' + s.type[0].toUpperCase() + s.type.slice(1);
209
- if (
210
- (s.bubble.indexOf('l') > -1 &&
211
- (s.immediateStopped ||
212
- 'function' != typeof o[c] ||
213
- (o[c](s), o.hasOwnProperty(c) && delete o[c])),
214
- s.stopped || 'l' === s.bubble)
215
- )
216
- return o;
217
- /[ud]/.test(s.bubble) && p(o.target, s);
218
- }
219
- }
220
- }
221
- class f extends d {
222
- _mc = {};
223
- constructor(t, e = !1) {
224
- super(t);
225
- }
226
- static add = a;
227
- static remove = u;
228
- static trigger = l;
229
- trigger(t, e = {}, n) {
230
- g.prototype.trigger.call(this, t, e, n);
231
- }
232
- parent(t = '') {
233
- let e = this.target;
234
- return i(e) ? c(e.parentNode, t, !0) : [];
235
- }
236
- ancestors(t = '') {
237
- let e = this?.target;
238
- return i(e) ? c(this.target.parentNode, t, !1) : [];
239
- }
240
- children(t = '') {
241
- let e = this?.target;
242
- if (!i(e)) return [];
243
- const n = Math.random().toString().replace('.', ''),
244
- r = '[_mc]:not([temp_id="' + n + '"] [_mc] [_mc])';
245
- e.setAttribute('temp_id', n);
246
- const o = s([...e.querySelectorAll(r)], t);
247
- return e.removeAttribute('temp_id'), o;
248
- }
249
- descendants(t = '') {
250
- let e = this?.target;
251
- return i(e) ? s([...e.querySelectorAll('*[_mc]')], t) : [];
252
- }
253
- }
254
- new Map();
255
- class m extends HTMLElement {
256
- constructor() {
257
- super();
258
- }
259
- connectedCallback() {
260
- f.trigger(this, 'Connected');
261
- }
262
- disconnectedCallback() {
263
- f.trigger(this, 'Disconnected');
264
- }
265
- adoptedCallback() {
266
- f.trigger(this, 'Adopted');
267
- }
268
- attributeChangedCallback(t, e, n) {
269
- f.trigger(this, 'AttributeChanged', {
270
- name: t,
271
- oldValue: e,
272
- newValue: n,
273
- });
274
- }
275
- }
276
- function b(t, e, n = []) {
277
- if (customElements.get(t))
278
- return void console.warn(
279
- `IGNORED: Custom element "${t}" is already defined!`
280
- );
281
- if (!t.includes('-'))
282
- throw new Error(
283
- 'createCustomElement: tagName must contain at least one hyphen ("-").'
284
- );
285
- let r = t
286
- .split('-')
287
- .map((t) => t.charAt(0).toUpperCase() + t.slice(1))
288
- .join('');
289
- customElements.define(
290
- t,
291
- (function (t, e) {
292
- return Object.defineProperty(e, 'name', { value: t });
293
- })(
294
- r,
295
- class extends m {
296
- instance;
297
- constructor(t) {
298
- super();
299
- let n = new e(this, t);
300
- f.add(this, r, n);
301
- }
302
- static get observedAttributes() {
303
- return n;
304
- }
305
- }
306
- )
307
- );
308
- }
309
- b(
310
- 'test-parent',
311
- class extends f {
312
- constructor(t) {
313
- super(t);
314
- }
315
- onConnected() {
316
- console.log('TestParent onConnect');
317
- }
318
- }
319
- );
320
- const h = customElements.get('test-parent');
321
- return (
322
- b(
323
- 'test-grandparent',
324
- class extends f {
325
- constructor(t) {
326
- super(t);
327
- }
328
- onConnected() {
329
- let t = this;
330
- for (let e = 0; e < 5; e++) t.target.append(new h());
331
- console.log('Grandparent onConnect');
332
- }
333
- }
334
- ),
335
- {}
336
- );
337
- })()
338
- );
@@ -1,47 +0,0 @@
1
- legend {
2
- display: inherit;
3
- margin: inherit;
4
- vertical-align: inherit;
5
- }
6
-
7
- label {
8
- display: inline;
9
- margin-top: 5px;
10
- margin-left: 5px;
11
- vertical-align: top;
12
- width: 10em;
13
- text-align: right;
14
- }
15
-
16
- label::before {
17
- content: ' ';
18
- display: block;
19
- }
20
-
21
- form input,
22
- form select,
23
- form textarea {
24
- margin-left: 5px;
25
- margin-top: 0px;
26
- display: inline;
27
- }
28
-
29
- form label + textarea {
30
- display: inline-block;
31
- margin-top: 3px;
32
- }
33
-
34
- form input + label {
35
- width: inherit;
36
- margin-top: 3px;
37
- text-align: left;
38
- }
39
-
40
- body > form {
41
- display: block;
42
- }
43
-
44
- form fieldset {
45
- border: 1px solid darkslategrey;
46
- border-radius: 3px;
47
- }
@@ -1,56 +0,0 @@
1
- <!-- test form -->
2
- <fieldset>
3
- <legend>Inputs</legend>
4
- <label>text</label><input type="text" name="textInput" value="" />&nbsp;<strong>2wB:&nbsp;</strong>{textInput}
5
- <label>color</label><input type="color" name="colorInput" value="" />
6
- <label>date</label><input type="date" name="dateInput" value="" />
7
- <label>datetime-local</label><input type="datetime-local" name="dtlInput" value="" />
8
- <label>email</label><input type="email" name="email" value="" />
9
- <label>file</label><input type="file" name="fileInput" value="" />
10
- <label>hidden</label><input type="hidden" name="hiddenInput" value="hiddenVal" />
11
- <label>month</label><input type="month" name="month" value="" />
12
- <label>number</label><input type="number" name="number" value="" />
13
- <label>password</label><input type="password" name="passInput" value="" />
14
- <label>range</label><input type="range" name="rangeInput" value="" />
15
- <label>search</label><input type="search" name="searchInput" value="" />
16
- <label>tel</label><input type="tel" name="telInput" value="" />
17
- <label>time</label><input type="time" name="timeInput" value="" />
18
- <label>url</label><input type="url" name="urlInput" value="" />
19
- <label>week</label><input type="week" name="weekInput" value="" />
20
- </fieldset>
21
- <fieldset>
22
- <legend>Selects</legend>
23
- <label>singleSelect</label>
24
- <select name="singleSelect">
25
- <option disabled selected value> -- select -- </option>
26
- <option value="1">Option 1</option>
27
- <option value="2">Option 2</option>
28
- <option value="3">Option 3</option>
29
- <option value="4">Option 4</option>
30
- </select>
31
- <label>multiSelect</label>
32
- <select name="multiSelect" multiple="multiple" type="select-multiple">
33
- <option value="1">Option 1</option>
34
- <option value="2" selected=true>Option 2</option>
35
- <option value="3">Option 3</option>
36
- <option value="4" selected=true>Option 4</option>
37
- </select>
38
- </fieldset>
39
- <fieldset>
40
- <legend>Radiobuttons&nbsp;<strong>2wB:&nbsp;</strong>{myRadio}</legend>
41
- <label>radio1</label><input type="radio" name="myRadio" value="radio1">
42
- <label>radio2</label><input type="radio" name="myRadio" value="radio2">
43
- <label>radio3</label><input type="radio" name="myRadio" value="radio3">
44
- </fieldset>
45
- <fieldset>
46
- <legend>Checkboxes</legend>
47
- <label>cb1</label><input type="checkbox" name="cb1">
48
- <label>cb2</label><input type="checkbox" name="cb2">
49
- <label>cb3</label><input type="checkbox" name="cb3">
50
- <label>cb4</label><input type="checkbox" name="cb4">
51
- <label>cb5</label><input type="checkbox" name="cb5">
52
- </fieldset>
53
- <fieldset>
54
- <legend>TextArea</legend>
55
- <label>textArea</label><textarea name="textArea"></textarea>
56
- </fieldset>
@@ -1,56 +0,0 @@
1
- test.TestForm = class extends Tb{
2
-
3
- constructor(){
4
- super();
5
-
6
- var that = this;
7
-
8
- // model to read data from
9
- that.crud = new tb.CRUD({
10
- 'read': {
11
- url: '/test/TestForm.json', // mock data
12
- method: 'GET',
13
- success: function( pResult ){
14
- var values = JSON.parse( pResult.text );
15
- $('form').values( values ); // set form input values
16
- that.formValues = values; // set values for two way binding
17
- },
18
- error: function( pResult ){
19
- console.log( 'an error occured', pResult );
20
- }
21
- }
22
- });
23
-
24
- tb.require([
25
- '/test/TestForm.html',
26
- '/test/TestForm.css'
27
- ]).then(
28
- that.render.bind(that)
29
- );
30
-
31
- }
32
-
33
- // methods
34
- render(){
35
-
36
- var that = this,
37
- fragment = $( tb.require.get('/test/TestForm.html') );
38
-
39
- // add fragment to DOM
40
- $( that.target )
41
- .append( fragment );
42
-
43
- // create formValues store
44
- that.formValues = {};
45
-
46
- // update DOM on formValues change
47
- that.formValues.bind( that.target );
48
-
49
- // update formValues store when form content is changed
50
- $('form').values().bind( that.formValues );
51
-
52
- // read data
53
- that.crud.read();
54
-
55
- }
56
- };
@@ -1,27 +0,0 @@
1
- {
2
- "textInput":"Hallo Welt",
3
- "colorInput":"#eaf8f8",
4
- "dateInput":"",
5
- "dtlInput":"",
6
- "email":"",
7
- "hiddenInput":"",
8
- "hiddenVal":"",
9
- "month":"",
10
- "number":"",
11
- "passInput":"",
12
- "rangeInput":"30",
13
- "searchInput":"",
14
- "telInput":"",
15
- "timeInput":"",
16
- "urlInput":"",
17
- "weekInput":"",
18
- "myRadio":"radio3",
19
- "cb1":true,
20
- "cb2":false,
21
- "cb3":true,
22
- "cb4":false,
23
- "cb5":false,
24
- "singleSelect":"",
25
- "multiSelect":["2","4"],
26
- "textArea":"This is some example\rtext..."
27
- }
@@ -1,149 +0,0 @@
1
-
2
- tb.createCustomElement(
3
-
4
- 'test-testform',
5
-
6
- class extends Tb{
7
-
8
- constructor( pConfig, pTarget ){
9
- super();
10
-
11
- let that = this;
12
-
13
- that.target = pTarget;
14
-
15
- that
16
- .one(
17
- 'connected',
18
- that.connected
19
- )
20
- .one(
21
- 'ready',
22
- that.ready
23
- );
24
-
25
- }
26
-
27
- connected(){
28
- let that = this;
29
-
30
- tb.require([
31
- '/test/TestForm.css'
32
- ]).then( (results) => {
33
- // add fragment to DOM
34
- $( that.target )
35
- .append( that.template );
36
- });
37
-
38
- }
39
-
40
- // methods
41
- ready(){
42
- let that = this;
43
-
44
- // create formValues store
45
- that
46
- .store('formValues')
47
- .bind( that.target );
48
-
49
- // update formValues store when form content is changed
50
- that.fields = $('form', that.target)
51
- .values()
52
- .observe( values => that.formValues = values );
53
-
54
- // read data
55
- that.formValues = that.data;
56
-
57
- tb.request({
58
- url: '/test/TestForm.json', // mock data
59
- method: 'GET',
60
- success: function( pResult ){
61
- var values = JSON.parse( pResult.text );
62
- $('form').values( values ); // set form input values
63
- //that.formValues = values; // set values for two way binding
64
- },
65
- error: function( pResult ){
66
- console.log( 'an error occured', pResult );
67
- }
68
- });
69
-
70
- }
71
-
72
- get template(){
73
- return `
74
- <form>
75
- <!-- sample form to start with -->
76
- <fieldset>
77
- <legend>Inputs</legend>
78
- <label>text</label><input type="text" name="textInput" value="Hallo" />&nbsp;<strong>2wB:&nbsp;</strong>{textInput}
79
- <label>color</label><input type="color" name="colorInput" value="" />
80
- <label>date</label><input type="date" name="dateInput" value="" />
81
- <label>datetime-local</label><input type="datetime-local" name="dtlInput" value="" />
82
- <label>email</label><input type="email" name="email" value="" />
83
- <label>file</label><input type="file" name="fileInput" value="" />
84
- <label>hidden</label><input type="hidden" name="hiddenInput" value="hiddenVal" />
85
- <label>month</label><input type="month" name="month" value="" />
86
- <label>number</label><input type="number" name="number" value="" />
87
- <label>password</label><input type="password" name="passInput" value="" />
88
- <label>range</label><input type="range" name="rangeInput" value="" />
89
- <label>search</label><input type="search" name="searchInput" value="" />
90
- <label>tel</label><input type="tel" name="telInput" value="" />
91
- <label>time</label><input type="time" name="timeInput" value="" />
92
- <label>url</label><input type="url" name="urlInput" value="" />
93
- <label>week</label><input type="week" name="weekInput" value="" />
94
- </fieldset>
95
-
96
- <fieldset>
97
- <legend>Selects</legend>
98
-
99
- <label>singleSelect</label>
100
- <select name="singleSelect">
101
- <option disabled selected value> -- select -- </option>
102
- <option value="1">Option 1</option>
103
- <option value="2">Option 2</option>
104
- <option value="3">Option 3</option>
105
- <option value="4">Option 4</option>
106
- </select>
107
-
108
- <label>multiSelect</label>
109
- <select name="multiSelect" multiple="multiple" type="select-multiple">
110
- <option value="1">Option 1</option>
111
- <option value="2" selected=true>Option 2</option>
112
- <option value="3">Option 3</option>
113
- <option value="4" selected=true>Option 4</option>
114
- </select>
115
-
116
- </fieldset>
117
-
118
- <fieldset>
119
- <legend>Radiobuttons&nbsp;<strong>2wB:&nbsp;</strong>{myRadio}</legend>
120
-
121
- <label>radio1</label><input type="radio" name="myRadio" value="radio1">
122
- <label>radio2</label><input type="radio" name="myRadio" value="radio2">
123
- <label>radio3</label><input type="radio" name="myRadio" value="radio3">
124
-
125
- </fieldset>
126
-
127
- <fieldset>
128
- <legend>Checkboxes</legend>
129
- <label>cb1</label><input type="checkbox" name="cb1">
130
- <label>cb2</label><input type="checkbox" name="cb2">
131
- <label>cb3</label><input type="checkbox" name="cb3">
132
- <label>cb4</label><input type="checkbox" name="cb4">
133
- <label>cb5</label><input type="checkbox" name="cb5">
134
-
135
- </fieldset>
136
-
137
- <fieldset>
138
- <legend>TextArea</legend>
139
-
140
- <label>textArea</label><textarea name="textArea"></textarea>
141
-
142
- </fieldset>
143
-
144
- </form>
145
- `;
146
- }
147
- }
148
-
149
- );