@twobirds/microcomponents 0.0.65 → 0.0.66

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 (117) hide show
  1. package/assets/documentation/MC.md +22 -28
  2. package/assets/documentation/elements.md +4 -2
  3. package/assets/documentation/observables.md +2 -0
  4. package/assets/test.html +1 -1
  5. package/dist/MC.d.ts.map +1 -1
  6. package/dist/MC.min.js +20 -15
  7. package/dist/MC.ts +23 -16
  8. package/dist/elements.min.js +1 -1
  9. package/dist/formvValues.min.js +1 -1
  10. package/dist/microcomponents.min.js +1 -1
  11. package/dist/observables.d.ts.map +1 -1
  12. package/dist/observables.min.js +1 -1
  13. package/dist/observables.ts +0 -3
  14. package/dist/selectors.min.js +1 -1
  15. package/package.json +4 -4
  16. package/public/MC.js +20 -15
  17. package/public/MC.js.map +1 -1
  18. package/public/MC.min.js +20 -15
  19. package/public/assets/highlight.css +99 -0
  20. package/public/assets/icons.js +18 -0
  21. package/public/assets/icons.svg +1 -0
  22. package/public/assets/main.js +60 -0
  23. package/public/assets/navigation.js +1 -0
  24. package/public/assets/search.js +1 -0
  25. package/public/assets/style.css +1493 -0
  26. package/public/classes/MC.DC.html +12 -0
  27. package/public/classes/MC.MC.html +6 -0
  28. package/public/classes/MC.McBase.html +3 -0
  29. package/public/classes/MC.McEvent.html +9 -0
  30. package/public/elements.min.js +1 -1
  31. package/public/formvValues.min.js +1 -1
  32. package/public/functions/MC.addListener.html +1 -0
  33. package/public/functions/MC.autoload.html +1 -0
  34. package/public/functions/MC.removeListener.html +1 -0
  35. package/public/functions/elements.defineCE.html +1 -0
  36. package/public/functions/elements.getCE.html +1 -0
  37. package/public/functions/formValues.formValues.html +1 -0
  38. package/public/functions/observables.observe.html +1 -0
  39. package/public/functions/selectors._d.html +1 -0
  40. package/public/functions/selectors._t.html +1 -0
  41. package/public/hierarchy.html +1 -0
  42. package/public/index.html +56 -0
  43. package/public/interfaces/MC.HTMLMcElement.html +758 -0
  44. package/public/interfaces/selectors.DSelector.html +50 -0
  45. package/public/interfaces/selectors.TSelector.html +34 -0
  46. package/public/microcomponents.min.js +1 -1
  47. package/public/modules/MC.html +9 -0
  48. package/public/modules/elements.html +3 -0
  49. package/public/modules/formValues.html +2 -0
  50. package/public/modules/observables.html +3 -0
  51. package/public/modules/selectors.html +7 -0
  52. package/public/modules.html +6 -0
  53. package/public/observables.js.map +1 -1
  54. package/public/observables.min.js +1 -1
  55. package/public/selectors.min.js +1 -1
  56. package/public/types/observables.Observable.html +1 -0
  57. package/public/types/selectors.selection.html +1 -0
  58. package/public/types/selectors.singleSelector.html +1 -0
  59. package/src/MC.ts +23 -16
  60. package/src/observables.ts +0 -3
  61. package/src/test/testmc.ts +7 -1
  62. package/assets/documentation/comparision.md +0 -0
  63. package/assets/documentation/how_tos.md +0 -0
  64. package/assets/documentation/introduction.md +0 -0
  65. package/assets/documentation/proposal_draft.md +0 -37
  66. package/public/3d.html +0 -42
  67. package/public/documentation/MC.md +0 -594
  68. package/public/documentation/ajaxian-1.png +0 -0
  69. package/public/documentation/ajaxian-2.png +0 -0
  70. package/public/documentation/ajaxian-3.png +0 -0
  71. package/public/documentation/comparision.md +0 -0
  72. package/public/documentation/elements.md +0 -276
  73. package/public/documentation/functional_requirements.md +0 -8
  74. package/public/documentation/history.md +0 -436
  75. package/public/documentation/how_tos.md +0 -0
  76. package/public/documentation/introduction.md +0 -0
  77. package/public/documentation/magic.md +0 -29
  78. package/public/documentation/observables.md +0 -105
  79. package/public/documentation/proposal_draft.md +0 -37
  80. package/public/documentation/rnd0023-1.jpg +0 -0
  81. package/public/documentation/rnd0023-2.jpg +0 -0
  82. package/public/documentation/rnd0023-3.jpg +0 -0
  83. package/public/documentation/tB_react.md +0 -207
  84. package/public/documentation/usage.md +0 -142
  85. package/public/documentation/why.md +0 -25
  86. package/public/fiddle/MicroComponents.svg +0 -15
  87. package/public/fiddle/fiddle.css +0 -0
  88. package/public/fiddle/fiddle.js +0 -0
  89. package/public/fiddle/index.html +0 -0
  90. package/public/grandparent.css +0 -13
  91. package/public/my-tag.css +0 -19
  92. package/public/src/MC.ts +0 -598
  93. package/public/src/McEvent.ts +0 -96
  94. package/public/src/autoloader.ts +0 -98
  95. package/public/src/elements.ts +0 -76
  96. package/public/src/formValues.ts +0 -233
  97. package/public/src/helpers.ts +0 -149
  98. package/public/src/microcomponents.ts +0 -8
  99. package/public/src/observables.ts +0 -404
  100. package/public/src/selectors.ts +0 -1634
  101. package/public/src/test.ts +0 -193
  102. package/public/test/child.js +0 -15
  103. package/public/test/child.js.map +0 -1
  104. package/public/test/grandchild.js +0 -15
  105. package/public/test/grandchild.js.map +0 -1
  106. package/public/test/grandparent.js +0 -1
  107. package/public/test/grandparent.js.map +0 -1
  108. package/public/test/greatgrandchild.js +0 -29
  109. package/public/test/greatgrandchild.js.map +0 -1
  110. package/public/test/parent.js +0 -15
  111. package/public/test/parent.js.map +0 -1
  112. package/public/test/testform.js +0 -1
  113. package/public/test/testform.js.map +0 -1
  114. package/public/test/testmc.js +0 -10
  115. package/public/test/testmc.js.map +0 -1
  116. package/public/test.html +0 -27
  117. /package/public/{MicroComponents.svg → media/MicroComponents.svg} +0 -0
@@ -1,404 +0,0 @@
1
- 'use strict';
2
-
3
- import {
4
- LooseObject,
5
- debounce,
6
- deepEqual,
7
- flattenObject,
8
- copyGettersSetters,
9
- } from './helpers.js';
10
-
11
- import { DC, HTMLMcElement, McEvent } from './MC.js';
12
-
13
- function isObservableObject(value: any): boolean {
14
- return value != null && typeof value === 'object';
15
- }
16
-
17
- type Callback = (value: any) => void;
18
-
19
- function getPlaceholders(target: HTMLElement): string[] {
20
- let placeholders: Set<string> = new Set(),
21
- regEx = /\{[^\{\}]*\}/g;
22
-
23
- // scan attributes
24
- target
25
- .getAttributeNames()
26
- .filter((attr) => target.getAttribute(attr)?.match(regEx)) // extract placeholder(s)
27
- .forEach((attr) => {
28
- let phs: Set<string> = new Set(target.getAttribute(attr)?.match(regEx));
29
- phs.forEach((placeholder) =>
30
- placeholders.add(placeholder.replace(/[\{\}]/g, ''))
31
- );
32
- });
33
-
34
- // scan children text nodes
35
- [...target.childNodes]
36
- .filter((childNode) => {
37
- return (
38
- // is text node and has placeholders
39
- childNode.nodeType === 3 &&
40
- ((childNode as any).nodeValue || '').match(regEx)
41
- );
42
- })
43
- .forEach((childNode) => {
44
- ((childNode as any).nodeValue || '')
45
- .match(regEx)
46
- .forEach((placeholder: string) => {
47
- placeholders.add(placeholder.replace(/[\{\}]/g, ''));
48
- });
49
- });
50
-
51
-
52
- //console.log('getPlaceholders()', target, result);
53
-
54
- // extract {} and return result
55
- return [...placeholders].map((placeholder) =>
56
- placeholder.replace(/[\{\}]/g, '')
57
- );
58
- }
59
-
60
- const inputs = [HTMLInputElement, HTMLSelectElement, HTMLTextAreaElement];
61
-
62
- class Placeholders extends DC {
63
- data: LooseObject = {};
64
- oldDisplay?: string = '';
65
-
66
- constructor(target: HTMLElement) {
67
- super(target);
68
- let that = this;
69
- getPlaceholders(target).forEach((property) => (that.data[property] = ''));
70
- observe(that);
71
- that.#attachCallbacks();
72
- delete that._mc; // cleanup, not needed
73
- }
74
-
75
- #attachCallbacks() {
76
- let that = this,
77
- target = that.target,
78
- hide: boolean = false;
79
-
80
- //console.log('attachCallbacks', that.target);
81
-
82
- // scan attributes
83
- target
84
- .getAttributeNames()
85
- .filter((attr: string) =>
86
- target.getAttribute(attr)?.match(/\{[^\{\}]*\}/g)
87
- ) // extract placeholder(s)
88
- .forEach((attr: string) => {
89
- let phs: Set<string> = new Set(
90
- target.getAttribute(attr)?.match(/\{[^\{\}]*\}/g)
91
- );
92
- // attach callback
93
- that.data.observe(
94
- ((template: string) => (data: LooseObject) => {
95
- let result: string = template;
96
- phs.forEach((placeholder) => {
97
- result = result.replace(
98
- placeholder,
99
- data[placeholder.replace(/[\{\}]/g, '')]
100
- );
101
- });
102
- target.setAttribute(attr, result);
103
- //console.log('cb setAttribute()', data, template, attr, result);
104
- })(target.getAttribute(attr))
105
- );
106
- });
107
-
108
- // scan children text nodes
109
- [...target.childNodes]
110
- .filter((childNode) => {
111
- return (
112
- // is text node and has placeholders
113
- childNode.nodeType === 3 &&
114
- ((childNode as any).nodeValue || '').match(/\{[^\{\}]*\}/g)
115
- );
116
- })
117
- .forEach((childNode) => {
118
- hide = true;
119
- let phs: Set<string> = new Set(
120
- childNode.nodeValue.match(/\{[^\{\}]*\}/g)
121
- );
122
-
123
- // attach callback
124
- that.data.observe(
125
- ((template: string) => (data: LooseObject) => {
126
- let result: string = template;
127
- //console.log('text node "', template, '" callbach data:', data);
128
- phs.forEach((placeholder) => {
129
- result = result.replace(
130
- placeholder,
131
- data[placeholder.replace(/[\{\}]/g, '')]
132
- );
133
- });
134
- if (
135
- Object.keys(data).some((key) => {
136
- return !!data[key];
137
- })
138
- ) {
139
- if (!!that.oldDisplay) {
140
- target.style = that.oldDisplay;
141
- } else {
142
- target.removeAttribute('style');
143
- }
144
- delete that.oldDisplay;
145
- }
146
- childNode.nodeValue = result;
147
- })(childNode.nodeValue)
148
- );
149
-
150
- // hide for now
151
- that.oldDisplay = target.getAttribute('style)') || '';
152
- if (
153
- hide &&
154
- !inputs.includes((target as any).constructor) &&
155
- target.tagName !== 'FIELDSET'
156
- ) {
157
- target.style.display = 'none';
158
- }
159
- });
160
- }
161
-
162
- onData(ev: McEvent) {
163
- let that = this,
164
- data: LooseObject = {};
165
- Object.keys(ev.data).forEach((key) => {
166
- if (that.data.hasOwnProperty(key)) data[key] = ev.data[key];
167
- });
168
- //console.log('onData()', ev, data, that.data);
169
- if (JSON.stringify(data) !== JSON.stringify(that.data))
170
- Object.assign(that.data, data); // will trigger callbacks
171
- }
172
- }
173
-
174
- function getPlaceholderElements(
175
- target: HTMLElement | DocumentFragment | ShadowRoot
176
- ): HTMLElement[] {
177
- let elements: Array<HTMLElement> = (
178
- target instanceof HTMLElement ? [target] : []
179
- )
180
- .concat([...(target.querySelectorAll('*') as unknown as HTMLElement[])])
181
- .filter((e) => !!getPlaceholders(e as HTMLElement).length)
182
- .filter((e) => e.tagName !== 'STYLE');
183
- //console.log('getPlaceholderElements', elements);
184
- return elements as HTMLElement[];
185
- }
186
-
187
- function makePlaceholders(
188
- element: HTMLElement | DocumentFragment | ShadowRoot
189
- ): void {
190
- //console.log('makePlaceholders', element);
191
- getPlaceholderElements(element).forEach((e: HTMLElement) => {
192
- if ((e as HTMLMcElement)?._mc?._placeholders) return;
193
- DC.add(e, '_placeholders', new Placeholders(e));
194
- });
195
- }
196
-
197
- export type Observable = {
198
- observe: (cb: Callback) => void;
199
- notify: () => void;
200
- bind: (target: HTMLElement | DocumentFragment | ShadowRoot) => void;
201
- };
202
-
203
- export const observe = (
204
- target: LooseObject,
205
- propertyName?: string
206
- ): LooseObject => {
207
- let keys = !propertyName
208
- ? [...Object.getOwnPropertyNames(target)]
209
- : [propertyName];
210
-
211
- keys.forEach((key) => {
212
- // console.log( 'co propname', key, typeof target[key], target[key] );
213
- if (key[0] === '_' || target?.[key] === undefined) return target;
214
- let val: any = target[key],
215
- Constructor: any;
216
-
217
- if (!val.prototype) {
218
- switch (typeof val) {
219
- case 'string':
220
- Constructor = String;
221
- break;
222
- case 'number':
223
- Constructor = Number;
224
- break;
225
- case 'boolean':
226
- Constructor = Boolean;
227
- break;
228
- case 'object':
229
- if (val instanceof Array) {
230
- Constructor = Array;
231
- } else {
232
- Constructor = Object;
233
- }
234
- break;
235
- default:
236
- return;
237
- }
238
- }
239
-
240
- let Observable = class extends Constructor {
241
- #notify: boolean = true;
242
-
243
- constructor(val: any) {
244
- super(val);
245
- (this.constructor as LooseObject).callbacks = [];
246
- if (isObservableObject(val)) {
247
- // you cannot bind native values to the dom
248
- Object.getOwnPropertyNames(val).forEach((key) => {
249
- this[key] = val[key];
250
- });
251
- }
252
- }
253
-
254
- observe(f: Function) {
255
- //console.log('observe');
256
- (this.constructor as any).callbacks.push(f);
257
- return this;
258
- }
259
-
260
- bind(target: HTMLElement | DocumentFragment | ShadowRoot) {
261
- const that = this,
262
- iso = isObservableObject(that.valueOf());
263
- //console.log('bind', iso, target);
264
-
265
- if (iso) {
266
- makePlaceholders(target);
267
- const placeholders: unknown = [
268
- ...target.querySelectorAll('[_mc]'),
269
- ].filter((e) => !!(e as LooseObject)?._mc?._placeholders);
270
- //console.log('placeholders:', target, placeholders);
271
- const func = function callback(data: LooseObject) {
272
- // avoid bubbling for speed
273
- let d = flattenObject(data);
274
- //console.log('inside callback', target, d);
275
- (placeholders as DC[]).forEach((e) => {
276
- // console.log('trigger callback', e);
277
- if (!e) return;
278
- (e as any)._mc.trigger('data', d);
279
- });
280
- };
281
- (that.constructor as any).callbacks.push(func);
282
- that.notify();
283
- } else {
284
- console.warn(
285
- 'IGNORED - cannot bind a non-Object to the dom, IS:',
286
- typeof that.valueOf(),
287
- that
288
- );
289
- }
290
-
291
- return this;
292
- }
293
-
294
- notify(notify?: boolean) {
295
- let that = this,
296
- data =
297
- isObservableObject(that.valueOf()) &&
298
- that.valueOf() instanceof Array === false
299
- ? structuredClone(Object.assign({}, that))
300
- : that.valueOf();
301
-
302
- if (notify !== undefined) {
303
- that.#notify = notify;
304
- // return;
305
- }
306
-
307
- //if (that.#notify) console.log('notify', this, data);
308
- (that.constructor as any).callbacks.forEach((f: Function) => {
309
- // console.log(
310
- // (this.constructor as any).callbacks,
311
- // 'notify: exec callback',
312
- // f,
313
- // data
314
- // );
315
- f(data);
316
- });
317
-
318
- return that;
319
- }
320
- };
321
-
322
- let o = new Observable(val);
323
-
324
- Object.defineProperty(target, key, {
325
- enumerable: true,
326
- get() {
327
- if (isObservableObject(o.valueOf())) {
328
- let check = structuredClone(Object.assign({}, o));
329
- setTimeout(
330
- debounce(function checkChanges() {
331
- let state = structuredClone(Object.assign({}, o));
332
- //console.log( 'check changes', state, check );
333
- if (!deepEqual(state, check)) {
334
- //console.log( '-> not equal!' );
335
- o.notify();
336
- }
337
- }, 0),
338
- 0
339
- );
340
- }
341
- return o;
342
- },
343
- set(val: any) {
344
- //console.log( 'SET:', isObservableObject( val.valueOf() ), 'set:', val, 'to', isObservableObject( o.valueOf() ), o, );
345
- if (typeof val === typeof o.valueOf()) {
346
- let iso =
347
- isObservableObject(o.valueOf()) &&
348
- o.valueOf() instanceof Array === false;
349
- //console.log('target iso:', iso);
350
- if (iso) {
351
- let old = structuredClone(Object.assign({}, o));
352
- //val = structuredClone(Object.assign({}, val));
353
-
354
- //let callbacks = (o.constructor as LooseObject).callbacks;
355
- if (o instanceof Observable === false) {
356
- o = new Observable(structuredClone(Object.assign({}, val)));
357
- copyGettersSetters(val, o);
358
- o.seal();
359
- }
360
- Object.assign(o, val);
361
-
362
- // console.log('after set o=', o, 'check', old);
363
- // (o.constructor as LooseObject).callbacks = callbacks;
364
-
365
- setTimeout(
366
- // check for changes
367
- debounce(function checkChanges() {
368
- let state = structuredClone(Object.assign({}, o));
369
- //console.log( 'check changes', state, check );
370
- if (!deepEqual(state, old)) {
371
- //console.log( '-> not equal!' );
372
- o.notify();
373
- }
374
- }, 0),
375
- 0
376
- );
377
- } else {
378
- // simple native var
379
- let old = o.valueOf(),
380
- callbacks = (o.constructor as LooseObject).callbacks;
381
- o = new Observable(val);
382
- (o.constructor as LooseObject).callbacks = callbacks;
383
- if (val !== old) {
384
- o.notify();
385
- }
386
- }
387
- } else {
388
- console.warn(
389
- 'IGNORED - cannot change observable types, IS:',
390
- typeof o.valueOf(),
391
- o,
392
- '- CANNOT BECOME:',
393
- typeof val
394
- );
395
- }
396
- },
397
- });
398
-
399
- // replace old property with proxy (observable)
400
- target[key] = val;
401
- });
402
-
403
- return target;
404
- };