@twobirds/microcomponents 0.0.46 → 0.0.50
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/assets/Grandparent.css +13 -0
- package/assets/documentation/MC.md +380 -166
- package/assets/test.html +5 -1
- package/dist/MC.d.ts +1 -0
- package/dist/MC.d.ts.map +1 -1
- package/dist/MC.min.js +44 -0
- package/dist/MC.ts +65 -0
- package/dist/elements.min.js +1 -1
- package/dist/elements.ts +10 -10
- package/dist/formValues.d.ts +3 -2
- package/dist/formValues.d.ts.map +1 -1
- package/dist/formValues.ts +206 -203
- package/dist/formvValues.min.js +1 -1
- package/dist/helpers.d.ts +1 -0
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.ts +9 -0
- package/dist/microcomponents.min.js +1 -1
- package/dist/observables.d.ts +1 -1
- package/dist/observables.d.ts.map +1 -1
- package/dist/observables.min.js +1 -1
- package/dist/observables.ts +72 -33
- package/dist/selectors.min.js +1 -1
- package/dist/test.ts +14 -14
- package/package.json +1 -1
- package/public/Grandparent.css +13 -0
- package/public/Grandparent.js +338 -0
- package/public/MC.js +43 -0
- package/public/MC.js.map +1 -1
- package/public/MC.min.js +44 -0
- package/public/TestForm.css +47 -0
- package/public/TestForm.html +56 -0
- package/public/TestForm.js +56 -0
- package/public/TestForm.json +27 -0
- package/public/Testform.js +149 -0
- package/public/classes/MC.DC.html +13 -13
- package/public/classes/MC.MC.html +7 -7
- package/public/classes/MC.McBase.html +4 -4
- package/public/classes/MC.McEvent.html +13 -13
- package/public/documentation/MC.md +380 -166
- package/public/documentation/observe.md +317 -0
- package/public/elements.js +9 -9
- package/public/elements.js.map +1 -1
- package/public/elements.min.js +1 -1
- package/public/formValues.js +142 -133
- package/public/formValues.js.map +1 -1
- package/public/formvValues.min.js +1 -1
- package/public/functions/MC.addListener.html +1 -1
- package/public/functions/MC.removeListener.html +1 -1
- package/public/functions/elements.defineCE.html +1 -1
- package/public/functions/elements.getCE.html +1 -1
- package/public/functions/formValues.formValues.html +1 -1
- package/public/functions/observables.observe.html +1 -1
- package/public/functions/selectors._d.html +1 -1
- package/public/functions/selectors._t.html +1 -1
- package/public/helpers.js +8 -0
- package/public/helpers.js.map +1 -1
- package/public/interfaces/MC.HTMLMcElement.html +2 -2
- package/public/interfaces/selectors.DSelector.html +55 -55
- package/public/interfaces/selectors.TSelector.html +37 -37
- package/public/microcomponents.min.js +1 -1
- package/public/modules/MC.html +1 -1
- package/public/modules/elements.html +1 -1
- package/public/modules/formValues.html +1 -1
- package/public/modules/observables.html +1 -1
- package/public/modules/selectors.html +1 -1
- package/public/observables.js +39 -21
- package/public/observables.js.map +1 -1
- package/public/observables.min.js +1 -1
- package/public/selectors.min.js +1 -1
- package/public/src/MC.ts +65 -0
- package/public/src/elements.ts +10 -10
- package/public/src/formValues.ts +206 -203
- package/public/src/helpers.ts +9 -0
- package/public/src/observables.ts +72 -33
- package/public/src/test.ts +14 -14
- package/public/test/Grandparent.js +1 -0
- package/public/test/Testform.js +1 -0
- package/public/test.html +5 -1
- package/public/test.js +9 -11
- package/public/test.js.map +1 -1
- package/public/types/observables.Observable.html +1 -1
- package/public/types/selectors.selection.html +1 -1
- package/public/types/selectors.singleSelector.html +1 -1
- package/src/MC.ts +65 -0
- package/src/elements.ts +10 -10
- package/src/formValues.ts +206 -203
- package/src/helpers.ts +9 -0
- package/src/observables.ts +72 -33
- package/src/test/Child.ts +21 -0
- package/src/test/Grandchild.ts +21 -0
- package/src/test/Grandparent.css +11 -0
- package/src/test/Grandparent.ts +21 -0
- package/src/test/Greatgrandchild.ts +42 -0
- package/src/test/Parent.ts +21 -0
- package/src/test/Testform.css +47 -0
- package/src/test/Testform.html +56 -0
- package/src/test/Testform.json +27 -0
- package/src/test/Testform.ts +159 -0
- package/src/test.ts +14 -14
- package/webpack.config.js +135 -61
package/src/observables.ts
CHANGED
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
LooseObject,
|
|
5
|
-
parse,
|
|
6
5
|
debounce,
|
|
7
6
|
deepEqual,
|
|
8
|
-
nameSpace,
|
|
9
7
|
flattenObject,
|
|
8
|
+
copyGettersSetters,
|
|
10
9
|
} from './helpers.js';
|
|
11
10
|
|
|
12
11
|
import { DC, HTMLMcElement, McEvent } from './MC.js';
|
|
@@ -76,9 +75,10 @@ class Placeholders extends DC {
|
|
|
76
75
|
|
|
77
76
|
#attachCallbacks() {
|
|
78
77
|
let that = this,
|
|
79
|
-
target = that.target
|
|
78
|
+
target = that.target,
|
|
79
|
+
hide: boolean = false;
|
|
80
80
|
|
|
81
|
-
//
|
|
81
|
+
//console.log('attachCallbacks', that.target);
|
|
82
82
|
|
|
83
83
|
// scan attributes
|
|
84
84
|
target
|
|
@@ -116,6 +116,7 @@ class Placeholders extends DC {
|
|
|
116
116
|
);
|
|
117
117
|
})
|
|
118
118
|
.forEach((childNode) => {
|
|
119
|
+
hide = true;
|
|
119
120
|
let phs: Set<string> = new Set(
|
|
120
121
|
childNode.nodeValue.match(/\{[^\{\}]*\}/g)
|
|
121
122
|
);
|
|
@@ -124,6 +125,7 @@ class Placeholders extends DC {
|
|
|
124
125
|
that.data.observe(
|
|
125
126
|
((template: string) => (data: LooseObject) => {
|
|
126
127
|
let result: string = template;
|
|
128
|
+
//console.log('text node "', template, '" callbach data:', data);
|
|
127
129
|
phs.forEach((placeholder) => {
|
|
128
130
|
result = result.replace(
|
|
129
131
|
placeholder,
|
|
@@ -135,7 +137,11 @@ class Placeholders extends DC {
|
|
|
135
137
|
return !!data[key];
|
|
136
138
|
})
|
|
137
139
|
) {
|
|
138
|
-
|
|
140
|
+
if (!!that.oldDisplay) {
|
|
141
|
+
target.style = that.oldDisplay;
|
|
142
|
+
} else {
|
|
143
|
+
target.removeAttribute('style');
|
|
144
|
+
}
|
|
139
145
|
delete that.oldDisplay;
|
|
140
146
|
}
|
|
141
147
|
childNode.nodeValue = result;
|
|
@@ -144,7 +150,11 @@ class Placeholders extends DC {
|
|
|
144
150
|
|
|
145
151
|
// hide for now
|
|
146
152
|
that.oldDisplay = target.getAttribute('style)') || '';
|
|
147
|
-
if (
|
|
153
|
+
if (
|
|
154
|
+
hide &&
|
|
155
|
+
!inputs.includes((target as any).constructor) &&
|
|
156
|
+
target.tagName !== 'FIELDSET'
|
|
157
|
+
) {
|
|
148
158
|
target.style.display = 'none';
|
|
149
159
|
}
|
|
150
160
|
});
|
|
@@ -156,7 +166,7 @@ class Placeholders extends DC {
|
|
|
156
166
|
Object.keys(ev.data).forEach((key) => {
|
|
157
167
|
if (that.data.hasOwnProperty(key)) data[key] = ev.data[key];
|
|
158
168
|
});
|
|
159
|
-
//
|
|
169
|
+
//console.log('onData()', ev, data, that.data);
|
|
160
170
|
if (JSON.stringify(data) !== JSON.stringify(that.data))
|
|
161
171
|
Object.assign(that.data, data); // will trigger callbacks
|
|
162
172
|
}
|
|
@@ -169,13 +179,16 @@ function getPlaceholderElements(
|
|
|
169
179
|
target instanceof HTMLElement ? [target] : []
|
|
170
180
|
)
|
|
171
181
|
.concat([...(target.querySelectorAll('*') as unknown as HTMLElement[])])
|
|
172
|
-
.filter((e) => !!getPlaceholders(e as HTMLElement).length)
|
|
182
|
+
.filter((e) => !!getPlaceholders(e as HTMLElement).length)
|
|
183
|
+
.filter((e) => e.tagName !== 'STYLE');
|
|
184
|
+
//console.log('getPlaceholderElements', elements);
|
|
173
185
|
return elements as HTMLElement[];
|
|
174
186
|
}
|
|
175
187
|
|
|
176
|
-
function
|
|
188
|
+
function makePlaceholders(
|
|
177
189
|
element: HTMLElement | DocumentFragment | ShadowRoot
|
|
178
190
|
): void {
|
|
191
|
+
//console.log('makePlaceholders', element);
|
|
179
192
|
getPlaceholderElements(element).forEach((e: HTMLElement) => {
|
|
180
193
|
if ((e as HTMLMcElement)?._mc?._placeholders) return;
|
|
181
194
|
DC.add(e, '_placeholders', new Placeholders(e));
|
|
@@ -188,14 +201,17 @@ export type Observable = {
|
|
|
188
201
|
bind: (target: HTMLElement | DocumentFragment | ShadowRoot) => void;
|
|
189
202
|
};
|
|
190
203
|
|
|
191
|
-
export const observe = (
|
|
204
|
+
export const observe = (
|
|
205
|
+
target: LooseObject,
|
|
206
|
+
propertyName?: string
|
|
207
|
+
): LooseObject => {
|
|
192
208
|
let keys = !propertyName
|
|
193
209
|
? [...Object.getOwnPropertyNames(target)]
|
|
194
210
|
: [propertyName];
|
|
195
211
|
|
|
196
212
|
keys.forEach((key) => {
|
|
197
213
|
// console.log( 'co propname', key, typeof target[key], target[key] );
|
|
198
|
-
if (key[0] === '_' || target?.[key] === undefined) return;
|
|
214
|
+
if (key[0] === '_' || target?.[key] === undefined) return target;
|
|
199
215
|
let val: any = target[key],
|
|
200
216
|
Constructor: any;
|
|
201
217
|
|
|
@@ -223,6 +239,8 @@ export const observe = (target: LooseObject, propertyName?: string) => {
|
|
|
223
239
|
}
|
|
224
240
|
|
|
225
241
|
let Observable = class extends Constructor {
|
|
242
|
+
#notify: boolean = true;
|
|
243
|
+
|
|
226
244
|
constructor(val: any) {
|
|
227
245
|
super(val);
|
|
228
246
|
(this.constructor as LooseObject).callbacks = [];
|
|
@@ -246,16 +264,22 @@ export const observe = (target: LooseObject, propertyName?: string) => {
|
|
|
246
264
|
//console.log('bind', iso, target);
|
|
247
265
|
|
|
248
266
|
if (iso) {
|
|
249
|
-
|
|
250
|
-
|
|
267
|
+
makePlaceholders(target);
|
|
268
|
+
const placeholders: unknown = [
|
|
269
|
+
...target.querySelectorAll('[_mc]'),
|
|
270
|
+
].filter((e) => !!(e as LooseObject)?._mc?._placeholders);
|
|
271
|
+
//console.log('placeholders:', target, placeholders);
|
|
272
|
+
const func = function callback(data: LooseObject) {
|
|
251
273
|
// avoid bubbling for speed
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
274
|
+
let d = flattenObject(data);
|
|
275
|
+
//console.log('inside callback', target, d);
|
|
276
|
+
(placeholders as DC[]).forEach((e) => {
|
|
277
|
+
// console.log('trigger callback', e);
|
|
278
|
+
if (!e) return;
|
|
279
|
+
(e as any)._mc.trigger('data', d);
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
(that.constructor as any).callbacks.push(func);
|
|
259
283
|
that.notify();
|
|
260
284
|
} else {
|
|
261
285
|
console.warn(
|
|
@@ -268,22 +292,34 @@ export const observe = (target: LooseObject, propertyName?: string) => {
|
|
|
268
292
|
return this;
|
|
269
293
|
}
|
|
270
294
|
|
|
271
|
-
notify() {
|
|
295
|
+
notify(notify?: boolean) {
|
|
272
296
|
let that = this,
|
|
273
297
|
data =
|
|
274
298
|
isObservableObject(that.valueOf()) &&
|
|
275
299
|
that.valueOf() instanceof Array === false
|
|
276
300
|
? structuredClone(Object.assign({}, that))
|
|
277
301
|
: that.valueOf();
|
|
302
|
+
|
|
303
|
+
if (notify !== undefined) {
|
|
304
|
+
that.#notify = notify;
|
|
305
|
+
// return;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
//if (that.#notify) console.log('notify', this, data);
|
|
278
309
|
(that.constructor as any).callbacks.forEach((f: Function) => {
|
|
279
|
-
// console.log(
|
|
310
|
+
// console.log(
|
|
311
|
+
// (this.constructor as any).callbacks,
|
|
312
|
+
// 'notify: exec callback',
|
|
313
|
+
// f,
|
|
314
|
+
// data
|
|
315
|
+
// );
|
|
280
316
|
f(data);
|
|
281
317
|
});
|
|
282
|
-
|
|
318
|
+
|
|
319
|
+
return that;
|
|
283
320
|
}
|
|
284
321
|
};
|
|
285
322
|
|
|
286
|
-
//(Observable.constructor as LooseObject).callbacks = [];
|
|
287
323
|
let o = new Observable(val);
|
|
288
324
|
|
|
289
325
|
Object.defineProperty(target, key, {
|
|
@@ -311,20 +347,21 @@ export const observe = (target: LooseObject, propertyName?: string) => {
|
|
|
311
347
|
let iso =
|
|
312
348
|
isObservableObject(o.valueOf()) &&
|
|
313
349
|
o.valueOf() instanceof Array === false;
|
|
314
|
-
//let iso = o.constructor.prototype.__proto__.constructor === Object;
|
|
315
350
|
//console.log('target iso:', iso);
|
|
316
351
|
if (iso) {
|
|
317
352
|
let old = structuredClone(Object.assign({}, o));
|
|
318
|
-
val = structuredClone(Object.assign({}, val));
|
|
353
|
+
//val = structuredClone(Object.assign({}, val));
|
|
319
354
|
|
|
320
|
-
let
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
355
|
+
//let callbacks = (o.constructor as LooseObject).callbacks;
|
|
356
|
+
if (o instanceof Observable === false) {
|
|
357
|
+
o = new Observable(structuredClone(Object.assign({}, val)));
|
|
358
|
+
copyGettersSetters(val, o);
|
|
359
|
+
o.seal();
|
|
360
|
+
}
|
|
361
|
+
Object.assign(o, val);
|
|
324
362
|
|
|
325
|
-
//console.log('after set o=', o, 'check', old);
|
|
326
|
-
(o.constructor as LooseObject).callbacks =
|
|
327
|
-
(o.constructor as LooseObject).callbacks = callbacks;
|
|
363
|
+
// console.log('after set o=', o, 'check', old);
|
|
364
|
+
// (o.constructor as LooseObject).callbacks = callbacks;
|
|
328
365
|
|
|
329
366
|
setTimeout(
|
|
330
367
|
// check for changes
|
|
@@ -363,4 +400,6 @@ export const observe = (target: LooseObject, propertyName?: string) => {
|
|
|
363
400
|
// replace old property with proxy (observable)
|
|
364
401
|
target[key] = val;
|
|
365
402
|
});
|
|
403
|
+
|
|
404
|
+
return target;
|
|
366
405
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DC, defineCE, getCE } from '.././microcomponents.js';
|
|
2
|
+
import { TestGrandchild } from './Grandchild.js';
|
|
3
|
+
defineCE(
|
|
4
|
+
'test-child',
|
|
5
|
+
|
|
6
|
+
class TestChild extends DC {
|
|
7
|
+
constructor(target: HTMLElement) {
|
|
8
|
+
super(target);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
onConnected() {
|
|
12
|
+
let that = this;
|
|
13
|
+
|
|
14
|
+
for (let x = 0; x < 10; x++) {
|
|
15
|
+
that.target.append(new TestGrandchild!());
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export const TestChild = getCE('test-child');
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DC, defineCE, getCE } from '.././microcomponents.js';
|
|
2
|
+
import { TestGreatgrandchild } from './Greatgrandchild.js';
|
|
3
|
+
defineCE(
|
|
4
|
+
'test-grandchild',
|
|
5
|
+
|
|
6
|
+
class TestGrandchild extends DC {
|
|
7
|
+
constructor(target: HTMLElement) {
|
|
8
|
+
super(target);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
onConnected() {
|
|
12
|
+
let that = this;
|
|
13
|
+
|
|
14
|
+
for (let x = 0; x < 2; x++) {
|
|
15
|
+
that.target.append(new TestGreatgrandchild!());
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export const TestGrandchild = getCE('test-grandchild');
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DC, defineCE, getCE } from '.././microcomponents.js';
|
|
2
|
+
import { TestParent } from './Parent.js';
|
|
3
|
+
defineCE(
|
|
4
|
+
'test-grandparent',
|
|
5
|
+
|
|
6
|
+
class TestGrandparent extends DC {
|
|
7
|
+
constructor(target: HTMLElement) {
|
|
8
|
+
super(target);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
onConnected() {
|
|
12
|
+
let that = this;
|
|
13
|
+
|
|
14
|
+
for (let x = 0; x < 5; x++) {
|
|
15
|
+
that.target.append(new TestParent!());
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export const TestGrandparent = getCE('test-grandparent');
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { DC, defineCE, getCE } from '.././microcomponents.js';
|
|
2
|
+
|
|
3
|
+
function random(min: number, max: number) {
|
|
4
|
+
var random = Math.floor(Math.random() * (max - min + 1) + min);
|
|
5
|
+
return random;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
defineCE(
|
|
9
|
+
'test-greatgrandchild',
|
|
10
|
+
|
|
11
|
+
class TestGreatgrandchild extends DC {
|
|
12
|
+
constructor(target: HTMLElement) {
|
|
13
|
+
super(target);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
onConnected() {
|
|
17
|
+
let that = this;
|
|
18
|
+
|
|
19
|
+
that.updateStyle();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
updateStyle() {
|
|
23
|
+
var that = this;
|
|
24
|
+
|
|
25
|
+
function randomBorderColor() {
|
|
26
|
+
return (
|
|
27
|
+
'rgb(' +
|
|
28
|
+
random(0, 255) +
|
|
29
|
+
',' +
|
|
30
|
+
random(0, 255) +
|
|
31
|
+
',' +
|
|
32
|
+
random(0, 255) +
|
|
33
|
+
')'
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
that.target.setAttribute('style', 'border-color:' + randomBorderColor());
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
export const TestGreatgrandchild = getCE('test-greatgrandchild');
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DC, defineCE, getCE } from '.././microcomponents.js';
|
|
2
|
+
import { TestChild } from './Child.js';
|
|
3
|
+
defineCE(
|
|
4
|
+
'test-parent',
|
|
5
|
+
|
|
6
|
+
class TestParent extends DC {
|
|
7
|
+
constructor(target: HTMLElement) {
|
|
8
|
+
super(target);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
onConnected() {
|
|
12
|
+
let that = this;
|
|
13
|
+
|
|
14
|
+
for (let x = 0; x < 5; x++) {
|
|
15
|
+
that.target.append(new TestChild!());
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export const TestParent = getCE('test-parent');
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<!-- test form -->
|
|
2
|
+
<fieldset>
|
|
3
|
+
<legend>Inputs</legend>
|
|
4
|
+
<label>text</label><input type="text" name="textInput" value="" /> <strong>2wB: </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 <strong>2wB: </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>
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
import { DC, defineCE, Observable, FormValues } from '.././microcomponents.js';
|
|
3
|
+
|
|
4
|
+
defineCE(
|
|
5
|
+
'test-testform',
|
|
6
|
+
|
|
7
|
+
class TestTestForm extends DC {
|
|
8
|
+
data: unknown;
|
|
9
|
+
|
|
10
|
+
constructor(target: HTMLElement) {
|
|
11
|
+
super(target);
|
|
12
|
+
|
|
13
|
+
const that = this;
|
|
14
|
+
|
|
15
|
+
delete this._mc;
|
|
16
|
+
|
|
17
|
+
let shadow = (that as DC).target.attachShadow({ mode: 'open' });
|
|
18
|
+
shadow.innerHTML = `<style>${this.css}</style>${this.template}`;
|
|
19
|
+
|
|
20
|
+
new FormValues(that, 'data', shadow);
|
|
21
|
+
|
|
22
|
+
(that.data as Observable).bind(shadow);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
onConnected() {}
|
|
26
|
+
|
|
27
|
+
oneInit() {
|
|
28
|
+
let that = this;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get template() {
|
|
32
|
+
return /*html*/ `
|
|
33
|
+
<form>
|
|
34
|
+
<!-- sample form to start with -->
|
|
35
|
+
<fieldset>
|
|
36
|
+
<legend>Inputs</legend>
|
|
37
|
+
<label>text</label><input type="text" name="textInput" value="Hallo" /> <strong>2wB: </strong>{textInput}
|
|
38
|
+
<label>color</label><input type="color" name="colorInput" value="" />
|
|
39
|
+
<label>date</label><input type="date" name="dateInput" value="" />
|
|
40
|
+
<label>datetime-local</label><input type="datetime-local" name="dtlInput" value="" />
|
|
41
|
+
<label>email</label><input type="email" name="email" value="" />
|
|
42
|
+
<label>file</label><input type="file" name="fileInput" value="" />
|
|
43
|
+
<label>hidden</label><input type="hidden" name="hiddenInput" value="hiddenVal" />
|
|
44
|
+
<label>month</label><input type="month" name="month" value="" />
|
|
45
|
+
<label>number</label><input type="number" name="number" value="" />
|
|
46
|
+
<label>password</label><input type="password" name="passInput" value="" />
|
|
47
|
+
<label>range</label><input type="range" name="rangeInput" value="" />
|
|
48
|
+
<label>search</label><input type="search" name="searchInput" value="" />
|
|
49
|
+
<label>tel</label><input type="tel" name="telInput" value="" />
|
|
50
|
+
<label>time</label><input type="time" name="timeInput" value="" />
|
|
51
|
+
<label>url</label><input type="url" name="urlInput" value="" />
|
|
52
|
+
<label>week</label><input type="week" name="weekInput" value="" />
|
|
53
|
+
</fieldset>
|
|
54
|
+
|
|
55
|
+
<fieldset>
|
|
56
|
+
<legend>Selects</legend>
|
|
57
|
+
|
|
58
|
+
<label>singleSelect</label>
|
|
59
|
+
<select name="singleSelect">
|
|
60
|
+
<option disabled selected value> -- select -- </option>
|
|
61
|
+
<option value="1">Option 1</option>
|
|
62
|
+
<option value="2">Option 2</option>
|
|
63
|
+
<option value="3">Option 3</option>
|
|
64
|
+
<option value="4">Option 4</option>
|
|
65
|
+
</select>
|
|
66
|
+
|
|
67
|
+
<label>multiSelect</label>
|
|
68
|
+
<select name="multiSelect" multiple="multiple" type="select-multiple">
|
|
69
|
+
<option value="1">Option 1</option>
|
|
70
|
+
<option value="2" selected=true>Option 2</option>
|
|
71
|
+
<option value="3">Option 3</option>
|
|
72
|
+
<option value="4" selected=true>Option 4</option>
|
|
73
|
+
</select>
|
|
74
|
+
|
|
75
|
+
</fieldset>
|
|
76
|
+
|
|
77
|
+
<fieldset>
|
|
78
|
+
<legend>Radiobuttons <strong>2wB: </strong><span>{myRadio}</span></legend>
|
|
79
|
+
|
|
80
|
+
<label>radio1</label><input type="radio" name="myRadio" value="radio1">
|
|
81
|
+
<label>radio2</label><input type="radio" name="myRadio" value="radio2">
|
|
82
|
+
<label>radio3</label><input type="radio" name="myRadio" value="radio3">
|
|
83
|
+
|
|
84
|
+
</fieldset>
|
|
85
|
+
|
|
86
|
+
<fieldset>
|
|
87
|
+
<legend>Checkboxes</legend>
|
|
88
|
+
<label>cb1</label><input type="checkbox" name="cb1">
|
|
89
|
+
<label>cb2</label><input type="checkbox" name="cb2">
|
|
90
|
+
<label>cb3</label><input type="checkbox" name="cb3">
|
|
91
|
+
<label>cb4</label><input type="checkbox" name="cb4">
|
|
92
|
+
<label>cb5</label><input type="checkbox" name="cb5">
|
|
93
|
+
|
|
94
|
+
</fieldset>
|
|
95
|
+
|
|
96
|
+
<fieldset>
|
|
97
|
+
<legend>TextArea</legend>
|
|
98
|
+
<label>textArea</label>
|
|
99
|
+
<textarea name="textArea">abc</textarea>
|
|
100
|
+
</fieldset>
|
|
101
|
+
|
|
102
|
+
</form>
|
|
103
|
+
`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
get css() {
|
|
107
|
+
return /*css*/ `
|
|
108
|
+
legend {
|
|
109
|
+
display: inherit;
|
|
110
|
+
margin: inherit;
|
|
111
|
+
vertical-align: inherit;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
label {
|
|
115
|
+
display: inline;
|
|
116
|
+
margin-top: 5px;
|
|
117
|
+
margin-left: 5px;
|
|
118
|
+
vertical-align: top;
|
|
119
|
+
width: 10em;
|
|
120
|
+
text-align: right;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
label::before {
|
|
124
|
+
content: ' ';
|
|
125
|
+
display: block;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
form input,
|
|
129
|
+
form select,
|
|
130
|
+
form textarea {
|
|
131
|
+
margin-left: 5px;
|
|
132
|
+
margin-top: 0px;
|
|
133
|
+
display: inline;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
form label + textarea {
|
|
137
|
+
display: inline-block;
|
|
138
|
+
margin-top: 3px;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
form input + label {
|
|
142
|
+
width: inherit;
|
|
143
|
+
margin-top: 3px;
|
|
144
|
+
text-align: left;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
body > form {
|
|
148
|
+
display: block;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
form fieldset {
|
|
152
|
+
border: 1px solid darkslategrey;
|
|
153
|
+
border-radius: 3px;
|
|
154
|
+
margin: 0.5em 0;
|
|
155
|
+
}
|
|
156
|
+
`;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
);
|