@lexriver/dome 1.5.11 → 2.0.1

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 (48) hide show
  1. package/README.md +10 -4
  2. package/out/{AnimatedArray.d.ts → src/AnimatedArray.d.mts} +29 -29
  3. package/out/{AnimatedArray.js → src/AnimatedArray.mjs} +52 -51
  4. package/out/{AnimatedTable.d.ts → src/AnimatedTable.d.mts} +38 -38
  5. package/out/{AnimatedTable.js → src/AnimatedTable.mjs} +88 -91
  6. package/out/{AnimatedText.d.ts → src/AnimatedText.d.mts} +13 -13
  7. package/out/{AnimatedText.js → src/AnimatedText.mjs} +24 -24
  8. package/out/{Animation.d.ts → src/Animation.d.mts} +4 -4
  9. package/out/{temp-test.d.ts → src/Animation.mjs} +1 -1
  10. package/out/{Dome.d.ts → src/Dome.d.mts} +9 -9
  11. package/out/{Dome.js → src/Dome.mjs} +291 -295
  12. package/out/{DomeComponent.d.ts → src/DomeComponent.d.mts} +22 -19
  13. package/out/{DomeComponent.js → src/DomeComponent.mjs} +47 -44
  14. package/out/{DomeManipulator.d.ts → src/DomeManipulator.d.mts} +48 -48
  15. package/out/{DomeManipulator.js → src/DomeManipulator.mjs} +329 -329
  16. package/out/src/DomeRouter.console-test.d.mts +1 -0
  17. package/out/{DomeRouter.console-test.js → src/DomeRouter.console-test.mjs} +44 -44
  18. package/out/{DomeRouter.d.ts → src/DomeRouter.d.mts} +32 -30
  19. package/out/{DomeRouter.js → src/DomeRouter.mjs} +249 -237
  20. package/out/{LongestCommonSubsequence.d.ts → src/LongestCommonSubsequence.d.mts} +15 -15
  21. package/out/{LongestCommonSubsequence.js → src/LongestCommonSubsequence.mjs} +164 -164
  22. package/out/src/index.d.mts +11 -0
  23. package/out/src/index.mjs +11 -0
  24. package/out/src/temp-test.d.mts +1 -0
  25. package/out/{temp-test.js → src/temp-test.mjs} +20 -20
  26. package/out/vitest.config.d.ts +2 -0
  27. package/out/vitest.config.js +9 -0
  28. package/package.json +16 -14
  29. package/src/{AnimatedArray.ts → AnimatedArray.mts} +3 -3
  30. package/src/{AnimatedTable.ts → AnimatedTable.mts} +6 -6
  31. package/src/{AnimatedText.ts → AnimatedText.mts} +4 -4
  32. package/src/{Animation.ts → Animation.mts} +0 -0
  33. package/src/{Dome.ts → Dome.mts} +7 -11
  34. package/src/{DomeComponent.ts → DomeComponent.mts} +3 -3
  35. package/src/{DomeManipulator.ts → DomeManipulator.mts} +5 -5
  36. package/src/{DomeRouter.console-test.ts → DomeRouter.console-test.mts} +0 -0
  37. package/src/{DomeRouter.ts → DomeRouter.mts} +20 -6
  38. package/src/{LongestCommonSubsequence.ts → LongestCommonSubsequence.mts} +0 -0
  39. package/src/index.mts +12 -0
  40. package/src/{temp-test.ts → temp-test.mts} +1 -1
  41. package/tsconfig.json +57 -60
  42. package/vitest.config.ts +10 -0
  43. package/jest.config.js +0 -22
  44. package/out/Animation.js +0 -0
  45. package/out/DomeRouter.console-test.d.ts +0 -0
  46. package/out/index.d.ts +0 -12
  47. package/out/index.js +0 -14
  48. package/src/index.ts +0 -14
@@ -1,295 +1,291 @@
1
- // inspiration: https://github.com/vadimdemedes/dom-chef/blob/master/index.js
2
- //import svgTagNames from 'svg-tag-names'
3
- const svgTagNames = require('svg-tag-names');
4
- //import svgTagNames from 'svg-tag-names'
5
- //import * as flatten from 'arr-flatten'
6
- //import { DomeEventDispatcher } from './DomeEventDispatcher.ts.old'
7
- import { DomeManipulator } from './DomeManipulator';
8
- import { checkIfObservable } from '@lexriver/observable';
9
- import { DataTypes } from '@lexriver/data-types';
10
- const filename = '[Dome]: ';
11
- //const mountFunctionByNode = new Map<Node, (ref:any)=>void>()
12
- // https://github.com/jonschlinkert/arr-flatten/blob/master/index.js
13
- function flattenArray(arr, res = []) {
14
- var i = 0, cur;
15
- var len = arr.length;
16
- for (; i < len; i++) {
17
- cur = arr[i];
18
- Array.isArray(cur) ? flattenArray(cur, res) : res.push(cur);
19
- }
20
- return res;
21
- }
22
- function checkIfNonDimensionalCssName(name) {
23
- // Copied from Preact
24
- const IS_NON_DIMENSIONAL = /acit|ex(?:s|g|n|p|$)|rph|ows|mnc|ntw|ine[ch]|zoo|^ord/i;
25
- return IS_NON_DIMENSIONAL.test(name);
26
- }
27
- const excludeSvgTags = [
28
- 'a',
29
- 'audio',
30
- 'canvas',
31
- 'iframe',
32
- 'script',
33
- 'video'
34
- ];
35
- const svgTags = svgTagNames.filter(name => !excludeSvgTags.includes(name));
36
- const isSVG = tagName => svgTags.includes(tagName);
37
- const setCSSProps = (el, style) => {
38
- if (DataTypes.isString(style)) {
39
- el.style = style;
40
- }
41
- else if (DataTypes.isObjectWithKeys(style)) {
42
- Object.keys(style).forEach(name => {
43
- let value = style[name];
44
- if (typeof value === 'number' && !checkIfNonDimensionalCssName(name)) {
45
- value = `${value}px`;
46
- }
47
- el.style[name] = value;
48
- });
49
- }
50
- };
51
- const createElement = (tagName) => {
52
- if (isSVG(tagName)) {
53
- return document.createElementNS('http://www.w3.org/2000/svg', tagName);
54
- }
55
- if (tagName === DocumentFragment) {
56
- return document.createDocumentFragment();
57
- }
58
- return document.createElement(tagName);
59
- };
60
- // function subscribeToEventByParam(x:OnEventObject, el:HTMLElement){
61
- // if(
62
- // !x.eventName ||
63
- // Data.isString(x.eventName) == false ||
64
- // !x.eventReaction ||
65
- // Data.isFunction(x.eventReaction) == false
66
- // ){
67
- // console.error('x=', x, 'el=', el)
68
- // throw new Error(`Please provide object of type {eventName:string, eventParams:Object, eventReaction:(eventParams, htmlElement)=>void}`)
69
- // }
70
- // //DomeEventDispatcher.subscribeToEvent(el, x.eventName, x.eventParams || {}, x.eventReaction)
71
- // DomeEventDispatcher.subscribeToEvent({
72
- // eventName: x.eventName,
73
- // eventParamsFilter: x.eventParams || {},
74
- // action: x.eventReaction,
75
- // unsubscribeWhen: () => DomeManipulator.isInDom(el) == false
76
- // })
77
- // }
78
- const build = (tagName, attrs, children) => {
79
- if (!tagName) {
80
- console.trace();
81
- throw new Error('tagName=' + tagName);
82
- }
83
- // if(children && typeof children !== 'object'){
84
- // //console.log('tagName=', tagName, 'attrs=',attrs, 'children=', children)
85
- // console.log('tagName=', tagName, 'children=', children, 'typeof children=', typeof children)
86
- // }
87
- if (tagName == DocumentFragment) {
88
- //console.warn(filename, 'isDocumentFragment!')
89
- const el = createElement(tagName);
90
- el.appendChild(children);
91
- return el;
92
- }
93
- //console.log(filename, 'instaceof=', tagName instanceof DomeComponent)
94
- //console.log(filename, 'has render=', tagName.render)
95
- //console.log(filename, 'instanceof Object=', tagName instanceof Object)
96
- if (tagName.prototype && tagName.prototype['__DomeComponent']) {
97
- // we have a DomeComponent
98
- //console.warn('DomeComponent!')
99
- try {
100
- const instance = new tagName(attrs, children);
101
- //console.log('instance=', instance)
102
- if (instance['render'] && DataTypes.isFunction(instance['render'])) {
103
- //#region make ref points to instance, not element
104
- if (attrs.ref && DataTypes.isFunction(attrs.ref)) {
105
- attrs.ref(instance);
106
- }
107
- //#endregion
108
- instance['init']();
109
- instance.rootElement = instance['render']();
110
- //#region subscribe to observable attribute
111
- for (let attribute of Object.values(attrs)) {
112
- if (checkIfObservable(attribute)) {
113
- attribute.eventOnChange.subscribe(() => {
114
- //this.update()
115
- instance.scheduleUpdate();
116
- });
117
- }
118
- }
119
- //#endregion
120
- //requestAnimationFrame(() => {
121
- instance['afterRender']();
122
- //})
123
- return instance.rootElement;
124
- }
125
- }
126
- catch (error) {
127
- console.error('error while creating DomeComponent class', error);
128
- }
129
- return;
130
- }
131
- if (DataTypes.isFunction(tagName)) {
132
- // call functional component
133
- return tagName(attrs, children);
134
- }
135
- else if (DataTypes.isString(tagName)) {
136
- const el = createElement(tagName);
137
- //console.log('lex-dome', 'creating element', el)
138
- Object.keys(attrs).forEach(name => {
139
- const value = attrs[name];
140
- if (name === 'class' || name === 'className' || name === 'cssClasses') {
141
- //DomeManipulator.setCssClasses(el, value)
142
- assignDynamicCssClasses(name, value, el);
143
- }
144
- else if (name === 'style') {
145
- setCSSProps(el, value);
146
- }
147
- else if (['disabled', 'autocomplete', 'selected', 'checked'].indexOf(name) >= 0) {
148
- if (attrs[name]) {
149
- DomeManipulator.setAttribute(el, name, name);
150
- }
151
- }
152
- else if (name === 'onCreate' || name === 'ref') {
153
- if (DataTypes.isFunction(value) == false)
154
- throw new Error(`Please provide function <${tagName} ${name}={ref => myRef=ref} />`);
155
- value(el);
156
- // } else if(name === 'onEvent'){ //TODO: remove this!?
157
- // // <div onEvent={{eventName:'myCumstomEvent', eventParams:{any:'params',can:'be',here:true}, eventReaction:()=>{}}}>some text for div</div>
158
- // //#region is Object
159
- // if(Data.isObjectWithKeys(value)){
160
- // subscribeToEventByParam(value as OnEventObject, el)
161
- // return
162
- // }
163
- // //#endregion
164
- // //#region is Array
165
- // if(Data.isArray(value)){
166
- // for(let x of value){
167
- // subscribeToEventByParam(x as OnEventObject, el)
168
- // }
169
- // }
170
- // //#endregion
171
- }
172
- else if (name == 'visibleIf') { //TODO: remove this!?
173
- if (checkIfObservable(value) == false) {
174
- console.error('value=', value);
175
- throw new Error('Please provide Observable<boolean> as argument for visibleIf');
176
- }
177
- let obs = value;
178
- obs.eventOnChange.subscribe((isVisible) => {
179
- if (isVisible) {
180
- DomeManipulator.unhideElementAsync(el);
181
- }
182
- else {
183
- DomeManipulator.hideElementAsync(el);
184
- }
185
- });
186
- setTimeout(() => {
187
- obs.eventOnChange.triggerAsync(obs.get());
188
- }, 1);
189
- }
190
- else if (name.indexOf('on') === 0 && value) {
191
- const eventName = name.slice(2).toLowerCase();
192
- if (DataTypes.isFunction(value) == false) {
193
- console.error('unable to subscribe for event', eventName, 'listener is not a function', 'element=', el, 'listener=', value);
194
- return;
195
- }
196
- //console.log('adding event listener for', el, 'eventName=', eventName, 'value=', value)
197
- el.addEventListener(eventName, value);
198
- }
199
- else if (name === 'innerHtml') {
200
- el.innerHTML = value;
201
- }
202
- else if (name !== 'key' && value !== false) {
203
- DomeManipulator.setAttribute(el, name, value === true ? '' : value);
204
- }
205
- });
206
- if (!attrs.innerHtml) {
207
- el.appendChild(children);
208
- }
209
- return el;
210
- }
211
- else
212
- throw new Error("not implemented");
213
- };
214
- /**
215
- *
216
- * @param value
217
- * @param name
218
- * @param element
219
- */
220
- function assignDynamicCssClasses(name, value, element) {
221
- if (DataTypes.isObjectWithKeys(value) == false) {
222
- DomeManipulator.setCssClasses(element, value);
223
- return;
224
- //throw new Error(`Please provide object for ${name}, ex: {class1:true, class2:myVarO}`)
225
- }
226
- let resultArray = [];
227
- for (let [k, v] of Object.entries(value)) {
228
- if (v === undefined) {
229
- //skip
230
- }
231
- else if (DataTypes.isBoolean(v)) {
232
- if (v) {
233
- resultArray.push(k);
234
- }
235
- }
236
- else if (checkIfObservable(v)) {
237
- let o = v;
238
- o.eventOnChange.subscribe((showThiCssClass) => {
239
- if (!DomeManipulator.isInDom(element))
240
- return { unsubscribe: true }; //TODO: test it
241
- // reassign whole attribute
242
- DomeManipulator.setCssClasses(element, value);
243
- });
244
- if (o.get()) {
245
- resultArray.push(k);
246
- }
247
- }
248
- else {
249
- console.error(`Please provide classNames as a keys and boolean or Observable<boolean> for values., ex: {class1:true, class2:myVarO}`, 'name=', name, 'value=', value, 'typeof value =', typeof value);
250
- throw new Error('Wrong value for `class` attribute');
251
- }
252
- }
253
- DomeManipulator.setCssClasses(element, resultArray); // yes, array of classes is ok here
254
- }
255
- export function h(tagName, attrs, ...childrenArgs) {
256
- // eslint-disable-next-line prefer-rest-params
257
- //const childrenArgs = [].slice.apply(arguments, [2])
258
- const children = document.createDocumentFragment();
259
- //const childArray:any[] = []
260
- // console.log(filename, 'childrenArgs=', childrenArgs)
261
- // console.log(filename, 'childrenO=', childrenO)
262
- // if(tagName === 'hoho'){
263
- // console.warn(filename, tagName, attrs, ...childrenArgs)
264
- // }
265
- flattenArray(childrenArgs).forEach(child => {
266
- //(childrenArgs).forEach(child => {
267
- // if(tagName === 'hoho'){
268
- // console.warn(filename, 'child=', child)
269
- // }
270
- if (child instanceof Node) {
271
- children.appendChild(child);
272
- //childArray.push(child)
273
- // const mountFunction = mountFunctionByNode.get(child)
274
- // if(mountFunction){
275
- // mountFunction(child)
276
- // mountFunctionByNode.delete(child)// delete after execution
277
- // }
278
- }
279
- else if (typeof child !== 'boolean' && typeof child !== 'undefined' && child !== null) {
280
- //console.log('[Dome] child=', child)
281
- //console.warn(filename, 'text? child=', child)
282
- children.appendChild(document.createTextNode(child));
283
- //childArray.push(document.createTextNode(child))
284
- }
285
- });
286
- //return build(tagName, attrs || {}, children)
287
- return build(tagName, attrs || {}, children);
288
- }
289
- // Improve TypeScript support for DocumentFragment
290
- // https://github.com/Microsoft/TypeScript/issues/20469
291
- export const React = {
292
- createElement: h,
293
- Fragment: typeof DocumentFragment === 'function' ? DocumentFragment : () => { }
294
- };
295
- export default React;
1
+ // inspiration: https://github.com/vadimdemedes/dom-chef/blob/master/index.js
2
+ const svgTagNames = require('svg-tag-names');
3
+ import { DataTypes } from '@lexriver/data-types';
4
+ import { checkIfObservable } from '@lexriver/observable';
5
+ import { DomeManipulator } from './DomeManipulator.mjs';
6
+ const filename = '[Dome]: ';
7
+ //const mountFunctionByNode = new Map<Node, (ref:any)=>void>()
8
+ // https://github.com/jonschlinkert/arr-flatten/blob/master/index.js
9
+ function flattenArray(arr, res = []) {
10
+ var i = 0, cur;
11
+ var len = arr.length;
12
+ for (; i < len; i++) {
13
+ cur = arr[i];
14
+ Array.isArray(cur) ? flattenArray(cur, res) : res.push(cur);
15
+ }
16
+ return res;
17
+ }
18
+ function checkIfNonDimensionalCssName(name) {
19
+ // Copied from Preact
20
+ const IS_NON_DIMENSIONAL = /acit|ex(?:s|g|n|p|$)|rph|ows|mnc|ntw|ine[ch]|zoo|^ord/i;
21
+ return IS_NON_DIMENSIONAL.test(name);
22
+ }
23
+ const excludeSvgTags = [
24
+ 'a',
25
+ 'audio',
26
+ 'canvas',
27
+ 'iframe',
28
+ 'script',
29
+ 'video'
30
+ ];
31
+ const svgTags = svgTagNames.filter(name => !excludeSvgTags.includes(name));
32
+ const isSVG = tagName => svgTags.includes(tagName);
33
+ const setCSSProps = (el, style) => {
34
+ if (DataTypes.isString(style)) {
35
+ el.style = style;
36
+ }
37
+ else if (DataTypes.isObjectWithKeys(style)) {
38
+ Object.keys(style).forEach(name => {
39
+ let value = style[name];
40
+ if (typeof value === 'number' && !checkIfNonDimensionalCssName(name)) {
41
+ value = `${value}px`;
42
+ }
43
+ el.style[name] = value;
44
+ });
45
+ }
46
+ };
47
+ const createElement = (tagName) => {
48
+ if (isSVG(tagName)) {
49
+ return document.createElementNS('http://www.w3.org/2000/svg', tagName);
50
+ }
51
+ if (tagName === DocumentFragment) {
52
+ return document.createDocumentFragment();
53
+ }
54
+ return document.createElement(tagName);
55
+ };
56
+ // function subscribeToEventByParam(x:OnEventObject, el:HTMLElement){
57
+ // if(
58
+ // !x.eventName ||
59
+ // Data.isString(x.eventName) == false ||
60
+ // !x.eventReaction ||
61
+ // Data.isFunction(x.eventReaction) == false
62
+ // ){
63
+ // console.error('x=', x, 'el=', el)
64
+ // throw new Error(`Please provide object of type {eventName:string, eventParams:Object, eventReaction:(eventParams, htmlElement)=>void}`)
65
+ // }
66
+ // //DomeEventDispatcher.subscribeToEvent(el, x.eventName, x.eventParams || {}, x.eventReaction)
67
+ // DomeEventDispatcher.subscribeToEvent({
68
+ // eventName: x.eventName,
69
+ // eventParamsFilter: x.eventParams || {},
70
+ // action: x.eventReaction,
71
+ // unsubscribeWhen: () => DomeManipulator.isInDom(el) == false
72
+ // })
73
+ // }
74
+ const build = (tagName, attrs, children) => {
75
+ if (!tagName) {
76
+ console.trace();
77
+ throw new Error('tagName=' + tagName);
78
+ }
79
+ // if(children && typeof children !== 'object'){
80
+ // //console.log('tagName=', tagName, 'attrs=',attrs, 'children=', children)
81
+ // console.log('tagName=', tagName, 'children=', children, 'typeof children=', typeof children)
82
+ // }
83
+ if (tagName == DocumentFragment) {
84
+ //console.warn(filename, 'isDocumentFragment!')
85
+ const el = createElement(tagName);
86
+ el.appendChild(children);
87
+ return el;
88
+ }
89
+ //console.log(filename, 'instaceof=', tagName instanceof DomeComponent)
90
+ //console.log(filename, 'has render=', tagName.render)
91
+ //console.log(filename, 'instanceof Object=', tagName instanceof Object)
92
+ if (tagName.prototype && tagName.prototype['__DomeComponent']) {
93
+ // we have a DomeComponent
94
+ //console.warn('DomeComponent!')
95
+ try {
96
+ const instance = new tagName(attrs, children);
97
+ //console.log('instance=', instance)
98
+ if (instance['render'] && DataTypes.isFunction(instance['render'])) {
99
+ //#region make ref points to instance, not element
100
+ if (attrs.ref && DataTypes.isFunction(attrs.ref)) {
101
+ attrs.ref(instance);
102
+ }
103
+ //#endregion
104
+ instance['init']();
105
+ instance.rootElement = instance['render']();
106
+ //#region subscribe to observable attribute
107
+ for (let attribute of Object.values(attrs)) {
108
+ if (checkIfObservable(attribute)) {
109
+ attribute.eventOnChange.subscribe(() => {
110
+ //this.update()
111
+ instance.scheduleUpdate();
112
+ });
113
+ }
114
+ }
115
+ //#endregion
116
+ //requestAnimationFrame(() => {
117
+ instance['afterRender']();
118
+ //})
119
+ return instance.rootElement;
120
+ }
121
+ }
122
+ catch (error) {
123
+ console.error('error while creating DomeComponent class', error);
124
+ }
125
+ return;
126
+ }
127
+ if (DataTypes.isFunction(tagName)) {
128
+ // call functional component
129
+ return tagName(attrs, children);
130
+ }
131
+ else if (DataTypes.isString(tagName)) {
132
+ const el = createElement(tagName);
133
+ //console.log('lex-dome', 'creating element', el)
134
+ Object.keys(attrs).forEach(name => {
135
+ const value = attrs[name];
136
+ if (name === 'class' || name === 'className' || name === 'cssClasses') {
137
+ //DomeManipulator.setCssClasses(el, value)
138
+ assignDynamicCssClasses(name, value, el);
139
+ }
140
+ else if (name === 'style') {
141
+ setCSSProps(el, value);
142
+ }
143
+ else if (['disabled', 'autocomplete', 'selected', 'checked'].indexOf(name) >= 0) {
144
+ if (attrs[name]) {
145
+ DomeManipulator.setAttribute(el, name, name);
146
+ }
147
+ }
148
+ else if (name === 'onCreate' || name === 'ref') {
149
+ if (DataTypes.isFunction(value) == false)
150
+ throw new Error(`Please provide function <${tagName} ${name}={ref => myRef=ref} />`);
151
+ value(el);
152
+ // } else if(name === 'onEvent'){ //TODO: remove this!?
153
+ // // <div onEvent={{eventName:'myCumstomEvent', eventParams:{any:'params',can:'be',here:true}, eventReaction:()=>{}}}>some text for div</div>
154
+ // //#region is Object
155
+ // if(Data.isObjectWithKeys(value)){
156
+ // subscribeToEventByParam(value as OnEventObject, el)
157
+ // return
158
+ // }
159
+ // //#endregion
160
+ // //#region is Array
161
+ // if(Data.isArray(value)){
162
+ // for(let x of value){
163
+ // subscribeToEventByParam(x as OnEventObject, el)
164
+ // }
165
+ // }
166
+ // //#endregion
167
+ }
168
+ else if (name == 'visibleIf') { //TODO: remove this!?
169
+ if (checkIfObservable(value) == false) {
170
+ console.error('value=', value);
171
+ throw new Error('Please provide Observable<boolean> as argument for visibleIf');
172
+ }
173
+ let obs = value;
174
+ obs.eventOnChange.subscribe((isVisible) => {
175
+ if (isVisible) {
176
+ DomeManipulator.unhideElementAsync(el);
177
+ }
178
+ else {
179
+ DomeManipulator.hideElementAsync(el);
180
+ }
181
+ });
182
+ setTimeout(() => {
183
+ obs.eventOnChange.triggerAsync(obs.get());
184
+ }, 1);
185
+ }
186
+ else if (name.indexOf('on') === 0 && value) {
187
+ const eventName = name.slice(2).toLowerCase();
188
+ if (DataTypes.isFunction(value) == false) {
189
+ console.error('unable to subscribe for event', eventName, 'listener is not a function', 'element=', el, 'listener=', value);
190
+ return;
191
+ }
192
+ //console.log('adding event listener for', el, 'eventName=', eventName, 'value=', value)
193
+ el.addEventListener(eventName, value);
194
+ }
195
+ else if (name === 'innerHtml') {
196
+ el.innerHTML = value;
197
+ }
198
+ else if (name !== 'key' && value !== false) {
199
+ DomeManipulator.setAttribute(el, name, value === true ? '' : value);
200
+ }
201
+ });
202
+ if (!attrs.innerHtml) {
203
+ el.appendChild(children);
204
+ }
205
+ return el;
206
+ }
207
+ else
208
+ throw new Error("not implemented");
209
+ };
210
+ /**
211
+ *
212
+ * @param value
213
+ * @param name
214
+ * @param element
215
+ */
216
+ function assignDynamicCssClasses(name, value, element) {
217
+ if (DataTypes.isObjectWithKeys(value) == false) {
218
+ DomeManipulator.setCssClasses(element, value);
219
+ return;
220
+ //throw new Error(`Please provide object for ${name}, ex: {class1:true, class2:myVarO}`)
221
+ }
222
+ let resultArray = [];
223
+ for (let [k, v] of Object.entries(value)) {
224
+ if (v === undefined) {
225
+ //skip
226
+ }
227
+ else if (DataTypes.isBoolean(v)) {
228
+ if (v) {
229
+ resultArray.push(k);
230
+ }
231
+ }
232
+ else if (checkIfObservable(v)) {
233
+ let o = v;
234
+ o.eventOnChange.subscribe((showThiCssClass) => {
235
+ if (!DomeManipulator.isInDom(element))
236
+ return { unsubscribe: true }; //TODO: test it
237
+ // reassign whole attribute
238
+ DomeManipulator.setCssClasses(element, value);
239
+ });
240
+ if (o.get()) {
241
+ resultArray.push(k);
242
+ }
243
+ }
244
+ else {
245
+ console.error(`Please provide classNames as a keys and boolean or Observable<boolean> for values., ex: {class1:true, class2:myVarO}`, 'name=', name, 'value=', value, 'typeof value =', typeof value);
246
+ throw new Error('Wrong value for `class` attribute');
247
+ }
248
+ }
249
+ DomeManipulator.setCssClasses(element, resultArray); // yes, array of classes is ok here
250
+ }
251
+ export function h(tagName, attrs, ...childrenArgs) {
252
+ // eslint-disable-next-line prefer-rest-params
253
+ //const childrenArgs = [].slice.apply(arguments, [2])
254
+ const children = document.createDocumentFragment();
255
+ //const childArray:any[] = []
256
+ // console.log(filename, 'childrenArgs=', childrenArgs)
257
+ // console.log(filename, 'childrenO=', childrenO)
258
+ // if(tagName === 'hoho'){
259
+ // console.warn(filename, tagName, attrs, ...childrenArgs)
260
+ // }
261
+ flattenArray(childrenArgs).forEach(child => {
262
+ //(childrenArgs).forEach(child => {
263
+ // if(tagName === 'hoho'){
264
+ // console.warn(filename, 'child=', child)
265
+ // }
266
+ if (child instanceof Node) {
267
+ children.appendChild(child);
268
+ //childArray.push(child)
269
+ // const mountFunction = mountFunctionByNode.get(child)
270
+ // if(mountFunction){
271
+ // mountFunction(child)
272
+ // mountFunctionByNode.delete(child)// delete after execution
273
+ // }
274
+ }
275
+ else if (typeof child !== 'boolean' && typeof child !== 'undefined' && child !== null) {
276
+ //console.log('[Dome] child=', child)
277
+ //console.warn(filename, 'text? child=', child)
278
+ children.appendChild(document.createTextNode(child));
279
+ //childArray.push(document.createTextNode(child))
280
+ }
281
+ });
282
+ //return build(tagName, attrs || {}, children)
283
+ return build(tagName, attrs || {}, children);
284
+ }
285
+ // Improve TypeScript support for DocumentFragment
286
+ // https://github.com/Microsoft/TypeScript/issues/20469
287
+ export const React = {
288
+ createElement: h,
289
+ Fragment: typeof DocumentFragment === 'function' ? DocumentFragment : () => { }
290
+ };
291
+ export default React;