lilact 0.31.15 → 0.31.17

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 (52) hide show
  1. package/bin/bundle.cjs +1 -1
  2. package/dist/lilact.development.js +406 -391
  3. package/dist/lilact.development.js.map +4 -4
  4. package/dist/lilact.development.min.js +35 -35
  5. package/dist/lilact.development.min.js.map +4 -4
  6. package/dist/lilact.production.min.js +38 -38
  7. package/docs/assets/hierarchy.js +1 -1
  8. package/docs/assets/navigation.js +1 -1
  9. package/docs/assets/search.js +1 -1
  10. package/docs/classes/accessories.ErrorBoundary.html +11 -11
  11. package/docs/classes/accessories.Suspense.html +10 -10
  12. package/docs/classes/components.Component.html +11 -11
  13. package/docs/classes/components.HTMLComponent.html +11 -11
  14. package/docs/classes/components.RootComponent.html +11 -11
  15. package/docs/functions/accessories.DragHandle.html +1 -1
  16. package/docs/functions/accessories.Spinner.html +1 -1
  17. package/docs/functions/components.cloneComponent.html +1 -1
  18. package/docs/functions/components.createComponent.html +1 -1
  19. package/docs/functions/components.createPortal.html +1 -1
  20. package/docs/functions/components.createRoot.html +1 -1
  21. package/docs/functions/components.memo.html +1 -1
  22. package/docs/functions/components.render.html +1 -1
  23. package/docs/functions/hooks.useLocalStorage.html +2 -2
  24. package/docs/functions/run.lazy.html +1 -1
  25. package/docs/functions/run.require.html +1 -1
  26. package/docs/functions/run.run.html +1 -1
  27. package/docs/functions/run.runScripts.html +1 -1
  28. package/docs/hierarchy.html +1 -1
  29. package/docs/modules/components.html +1 -1
  30. package/docs/static/lilact.development.js +406 -391
  31. package/docs/static/lilact.development.js.map +4 -4
  32. package/docs/static/lilact.development.min.js +35 -35
  33. package/docs/static/lilact.development.min.js.map +4 -4
  34. package/docs/static/lilact.production.min.js +38 -38
  35. package/docs/variables/accessories.SplitPane.html +1 -1
  36. package/docs/variables/components.cloneElement.html +1 -1
  37. package/examples/lilact.development.js +406 -391
  38. package/examples/lilact.development.js.map +4 -4
  39. package/examples/lilact.development.min.js +35 -35
  40. package/examples/lilact.development.min.js.map +4 -4
  41. package/examples/lilact.production.min.js +38 -38
  42. package/package.json +1 -1
  43. package/scripts/build.mjs +1 -1
  44. package/src/accessories.jsx +4 -2
  45. package/src/cache.jsx +299 -0
  46. package/src/components.jsx +6 -1042
  47. package/src/core.jsx +799 -0
  48. package/src/hooks.jsx +2 -2
  49. package/src/run.jsx +2 -1
  50. package/src/symbols.jsx +0 -2
  51. package/docs/functions/components.replaceAllComponentInstances.html +0 -1
  52. package/docs/functions/components.replaceComponentEntity.html +0 -1
@@ -29,1007 +29,17 @@
29
29
  */
30
30
 
31
31
  import Lilact from './lilact.jsx';
32
+ import { registerComponentCore, unregisterComponentCore, resolveHotEntity } from './cache.jsx';
33
+ import { ComponentCore } from './core.jsx';
32
34
 
33
- import { CORE, COMPONENT, TEXT, IS_ZOMBIE, IDX, CHILD_CLASS_ADDENDUM, MEMOIZED, LOCATION, CLONED_STYLE } from "./symbols.jsx"
34
- import { shallowEqual, toBool, isClass, isThenable } from "./misc.jsx";
35
+ import { CORE, COMPONENT, TEXT, IDX, CHILD_CLASS_ADDENDUM, MEMOIZED, CLONED_STYLE } from "./symbols.jsx"
35
36
 
36
- import { PropTypes } from './proptypes.jsx';
37
-
38
- const SVG_NS = "http://www.w3.org/2000/svg";
39
-
40
-
41
-
42
- function getComponentEntity(entity) {
43
- return entity?.[MEMOIZED] ? entity.component : entity;
44
- }
45
-
46
- const hotEntityAliases = new Map();
47
- const hotEntityCacheTokens = new WeakMap();
48
-
49
- function getHotEntityCacheToken(entity) {
50
- entity = getComponentEntity(entity);
51
-
52
- if (typeof entity !== "function") {
53
- return entity;
54
- }
55
-
56
- let token = hotEntityCacheTokens.get(entity);
57
-
58
- if (!token) {
59
- const resolved = resolveHotEntity(entity);
60
- token = hotEntityCacheTokens.get(resolved) || {};
61
- hotEntityCacheTokens.set(entity, token);
62
- hotEntityCacheTokens.set(resolved, token);
63
- }
64
-
65
- return token;
66
- }
67
-
68
- function resolveHotEntity(entity) {
69
- entity = getComponentEntity(entity);
70
-
71
- const visited = new Set();
72
-
73
- while (
74
- typeof entity === "function" &&
75
- hotEntityAliases.has(entity) &&
76
- !visited.has(entity)
77
- ) {
78
- visited.add(entity);
79
- entity = hotEntityAliases.get(entity);
80
- }
81
-
82
- return entity;
83
- }
84
-
85
- const componentInstances = new Map();
86
-
87
- function registerComponentCore(core) {
88
- const entity = getComponentEntity(core.entity);
89
-
90
- if (typeof entity !== "function") return;
91
-
92
- let instances = componentInstances.get(entity);
93
-
94
- if (!instances) {
95
- instances = new Set();
96
- componentInstances.set(entity, instances);
97
- }
98
-
99
- instances.add(core);
100
- core.registered_entity = entity;
101
- }
102
-
103
- function unregisterComponentCore(core) {
104
- const entity = core.registered_entity;
105
- if (!entity) return;
106
-
107
- const instances = componentInstances.get(entity);
108
-
109
- if (instances) {
110
- instances.delete(core);
111
-
112
- if (instances.size === 0) {
113
- componentInstances.delete(entity);
114
- }
115
- }
116
-
117
- delete core.registered_entity;
118
- }
119
-
120
- function moveComponentCore(core, oldEntity, newEntity) {
121
- const oldInstances = componentInstances.get(oldEntity);
122
-
123
- if (oldInstances) {
124
- oldInstances.delete(core);
125
-
126
- if (oldInstances.size === 0) {
127
- componentInstances.delete(oldEntity);
128
- }
129
- }
130
-
131
- let newInstances = componentInstances.get(newEntity);
132
-
133
- if (!newInstances) {
134
- newInstances = new Set();
135
- componentInstances.set(newEntity, newInstances);
136
- }
137
-
138
- newInstances.add(core);
139
- core.registered_entity = newEntity;
140
- }
141
-
142
- export function replaceComponentEntity(componentCore, nextEntity) {
143
- if (!componentCore || typeof nextEntity !== "function") {
144
- return false;
145
- }
146
-
147
- const oldEntity = getComponentEntity(componentCore.entity);
148
- const newEntity = resolveHotEntity(nextEntity);
149
-
150
- const cacheToken = hotEntityCacheTokens.get(oldEntity) || hotEntityCacheTokens.get(newEntity) || {};
151
-
152
- hotEntityCacheTokens.set(oldEntity, cacheToken);
153
- hotEntityCacheTokens.set(newEntity, cacheToken);
154
-
155
- if (oldEntity === newEntity) {
156
- return true;
157
- }
158
-
159
- const component = componentCore.component;
160
-
161
- if (!component) {
162
- return false;
163
- }
164
-
165
- if (
166
- typeof oldEntity !== "function" ||
167
- typeof newEntity !== "function" ||
168
- isClass(oldEntity) !== isClass(newEntity)
169
- ) {
170
- return false;
171
- }
172
-
173
- if (isClass(newEntity)) {
174
- Object.setPrototypeOf(component, newEntity.prototype);
175
- } else {
176
- component.render = newEntity.bind(component);
177
- }
178
-
179
- componentCore.entity = newEntity;
180
- moveComponentCore(componentCore, oldEntity, newEntity);
181
-
182
- return true;
183
- }
184
-
185
- export function replaceAllComponentInstances(oldEntity, newEntity)
186
- {
187
- oldEntity = getComponentEntity(oldEntity);
188
- newEntity = getComponentEntity(newEntity);
189
-
190
- if (
191
- typeof oldEntity !== "function" ||
192
- typeof newEntity !== "function"
193
- ) {
194
- return 0;
195
- }
196
-
197
- newEntity = resolveHotEntity(newEntity);
198
-
199
- if (oldEntity === newEntity) {
200
- return 0;
201
- }
202
-
203
- const cacheToken = hotEntityCacheTokens.get(oldEntity) || hotEntityCacheTokens.get(newEntity) || {};
204
-
205
- hotEntityCacheTokens.set(oldEntity, cacheToken);
206
- hotEntityCacheTokens.set(newEntity, cacheToken);
207
-
208
- hotEntityAliases.set(oldEntity, newEntity);
209
-
210
- const instances = componentInstances.get(oldEntity);
211
-
212
- if (!instances) {
213
- return 0;
214
- }
215
-
216
- let count = 0;
217
-
218
- for (const core of [...instances]) {
219
- if (!replaceComponentEntity(core, newEntity)) {
220
- continue;
221
- }
222
-
223
- core.apply(core.props, core.state);
224
- count++;
225
- }
226
-
227
- return count;
228
- }
229
-
230
-
231
-
232
- /*
233
- ComponentCache is for internal use. It is the heart of the JSX runtime,
234
- it holds child components and detects which one is being rendered or updated.
235
- */
236
-
237
- class ComponentCache
238
- {
239
- owner;
240
- current_map = new Map;
241
- new_map = new Map;
242
- pick_index = 0;
243
-
244
- constructor(owner)
245
- {
246
- this.owner = owner;
247
- }
248
-
249
- pick(key, construct_func, nextEntity) {
250
- let componentCore;
251
- let bucket = this.current_map.get(key);
252
-
253
- if (bucket && bucket.length > bucket[IDX]) {
254
- componentCore = bucket[bucket[IDX]];
255
- bucket[IDX]++;
256
-
257
- const oldEntity = getComponentEntity(componentCore.entity);
258
- const newEntity = resolveHotEntity(nextEntity);
259
-
260
- const incompatible =
261
- typeof oldEntity !== typeof newEntity ||
262
- (
263
- typeof oldEntity === "function" &&
264
- isClass(oldEntity) !== isClass(newEntity)
265
- );
266
-
267
- if (incompatible) {
268
- componentCore = construct_func();
269
- } else if (newEntity) {
270
- replaceComponentEntity(componentCore, newEntity);
271
- }
272
- } else {
273
- componentCore = construct_func();
274
- }
275
-
276
- bucket = this.new_map.get(key);
277
-
278
- if (bucket) {
279
- bucket.push(componentCore);
280
- } else {
281
- bucket = [componentCore];
282
- this.new_map.set(key, bucket);
283
- bucket[IDX] = 0;
284
- }
285
-
286
- if (componentCore) {
287
- componentCore.parent ??= this.owner;
288
- }
289
-
290
- return componentCore;
291
- }
292
-
293
- commit()
294
- {
295
- this.current_map.forEach( (arr)=>{
296
- arr.slice(arr[IDX]).forEach((ex)=>{
297
- if(ex.cleanup) {
298
- ex.cleanup();
299
- }
300
- else if(ex.element && !ex.portal) {
301
- ex.element.parentElement?.removeChild?.(ex.element);
302
- }
303
- });
304
- });
305
-
306
- this.current_map = this.new_map;
307
- this.new_map = new Map;
308
- }
309
-
310
- }
311
-
312
- /** ComponentCore - Mostly for internal use. This is where all the component data and methods
313
- * used by lilact are kept. The Component class uses it under the hood, so there is a separation
314
- * and user can set whatever property they want in the component. Each Lilact.Component
315
- * has a core that is accessible via lilact symbol CORE, i.e. component[CORE]. Note
316
- * that you should define a LILACT:CORE symbol.
317
- *
318
- * ComponentCore methods are not to be called by the user. But it can also be used
319
- * to store data more efficiently, and I have used it extensively. But it is
320
- * better for the user to work according react paradigms instead if memory
321
- * efficiency is not a high priority. It is not compatible with React API. So if
322
- * you want to do so, check the code to prevent accidental shadowing of the methods
323
- * and properties.
324
- *
325
- * @class ComponentCore
326
- */
327
-
328
- class ComponentCore
329
- {
330
- /*
331
-
332
- // these are commented so they are not allocated by default. i just wanted to keep a list.
333
-
334
- entity = undefined
335
-
336
- ref = undefined;
337
-
338
- context = undefined;
339
- state = undefined;
340
-
341
- container = null;
342
- outlet = null;
343
-
344
- depo = new ComponentCache;
345
-
346
- element = undefined;
347
- mount_state
348
-
349
- insert_index
350
- loader_args
351
-
352
- is_svg
353
-
354
- */
355
-
356
- component;
357
- props;
358
-
359
- constructor(comp, props)
360
- {
361
- this.component = comp;
362
- this.props = props || {};
363
- }
364
-
365
- /*
366
- */
367
- // TODO: should componentDidUpdate be called after arranging/appending the outlet or before?
368
- apply(next_props = this.props, next_state = this.next_state || this.state)
369
- {
370
- try {
371
-
372
- let do_rerender = true;
373
-
374
- if(this.outlet && this?.[MEMOIZED]) {
375
-
376
- if( shallowEqual(this.props, next_props, "children") &&
377
- shallowEqual(this.props?.children, next_props?.children) ) {
378
- do_rerender=false;
379
- }
380
- }
381
-
382
- if(do_rerender) {
383
-
384
- if(DEBUG) {
385
- if(this.entity?.propTypes) {
386
- PropTypes.checkPropTypes( this.entity.propTypes, next_props, 'prop', this.entity.name );
387
- }
388
- else if(this.component?.propTypes) {
389
- PropTypes.checkPropTypes( this.component.propTypes, next_props, 'prop', this.component.name );
390
- }
391
- }
392
-
393
- if(typeof(next_state)==='function') next_state = next_state(this.state);
394
-
395
- const defaultProps = this.entity?.defaultProps || this.component?.constructor?.defaultProps;
396
-
397
- if (defaultProps) {
398
- next_props = {
399
- ...defaultProps,
400
- ...(next_props || {}),
401
- };
402
- }
403
-
404
- if(next_props?.style && typeof next_props.style === 'object' && !next_props.style[CLONED_STYLE]) {
405
- next_props.style = { ...next_props.style, [CLONED_STYLE]: true };
406
- }
407
-
408
- if(this?.parent?.component?.context || this?.parent?.component?.getChildContext ) {
409
- this.context = { ...this.parent.component.context, ...this.parent.component.getChildContext?.() };
410
-
411
- if(DEBUG && this.component.constructor.contextTypes) {
412
- PropTypes.checkPropTypes(this.component.constructor.contextTypes, this.context, 'context', this.entity.name);
413
- }
414
- }
415
-
416
- if( this.component.shouldComponentUpdate &&
417
- !this.component.shouldComponentUpdate
418
- (next_state, next_props, this.context) ) return;
419
-
420
-
421
- if( typeof(this.entity)==='string' ) {
422
- if(!(this.element instanceof Element)) {
423
-
424
- if(this.is_svg || this.container.is_svg) {
425
- this.is_svg = true;
426
- this.element = document.createElementNS(SVG_NS, this.entity);
427
- }
428
- else {
429
- this.element = document.createElement(this.entity);
430
- }
431
- if(next_props?.defaultValue) this.element.value = String(next_props.defaultValue).slice(0, next_props?.maxLength);
432
- if(next_props?.defaultChecked) this.element.checked = next_props.defaultChecked;
433
- }
434
- this.element[COMPONENT] = this.component;
435
- }
436
-
437
- if(next_props.ref) {
438
- if(typeof(next_props.ref)==='function') {
439
- next_props.ref(this.element || this.component);
440
- }
441
- else {
442
- next_props.ref.current = this.element || this.component;
443
- }
444
- }
445
-
446
- if(next_props!==undefined && this.component.componentWillReceiveProps) {
447
- this.component.componentWillReceiveProps(next_props);
448
- }
449
-
450
- if(this.component.componentWillUpdate) {
451
- this.component.componentWillUpdate(next_props, next_state);
452
- }
453
-
454
- const prev_state = this.state, prev_props=this.props;
455
-
456
- if( this.element && ! (this?.component instanceof RootComponent) ) {
457
- this.updateElementProps(next_props);
458
- }
459
- this.props = next_props;
460
-
461
- if(typeof this.next_state==='object') {
462
- if(!this.state) this.state = {...next_state};
463
- else Object.assign( this.state, next_state );
464
- }
465
- else if(this.next_state!==undefined) throw new Error('Component.setState only accepts objects or functions is new state.');
466
-
467
-
468
- if(this.next_state) delete this.next_state;
469
-
470
-
471
- if(this.hooks!==undefined) {
472
- this.hook_index = 0;
473
- Lilact.current_component = [this, Lilact.current_component];
474
-
475
- this.outlet = this.component.render(next_props, {current: this.element || this.component} );
476
-
477
- Lilact.current_component = Lilact.current_component[1];
478
- }
479
- else {
480
- this.outlet = this.component.render({current: this.element || this.component});
481
- }
482
-
483
- if( this?.portal ) {
484
- this.element = this.portal;
485
- }
486
-
487
- if(this.outlet?.constructor?.name!=='Array') {
488
- this.outlet = [this.outlet];
489
- }
490
- else {
491
- this.outlet = [...this.outlet];
492
- }
493
-
494
- for (let i=0;i<this.outlet.length;i++) {
495
- let item = this.outlet[i];
496
-
497
- if(item===undefined || item===null || typeof(item)==='boolean') {
498
- this.outlet.splice(i, 1);
499
- i--;
500
- }
501
- else if(typeof item==='function') {
502
- const res = this.childFunctionHandler(item);
503
- this.outlet.splice(i, 1, res);
504
- i--;
505
- }
506
- else if(item.constructor.name === 'Array') {
507
- this.outlet.splice(i, 1, ...item);
508
- i--;
509
- }
510
- else {
511
- const core = prepareCore(this, item);
512
- this.outlet[i] = core;
513
-
514
- if(core[TEXT]===undefined) {
515
- core.container = this.element? this : this.container;
516
- core.apply(item.props);
517
- }
518
- else {
519
- if(!core.element) {
520
- core.element = document.createTextNode(item[TEXT]);
521
- core[TEXT] = item[TEXT];
522
- }
523
- else if(core[TEXT]!==item[TEXT]) {
524
- core.element.textContent = item[TEXT];
525
- core[TEXT] = item[TEXT];
526
- }
527
- }
528
- }
529
- }
530
-
531
- if(this.cache) this.cache.commit();
532
-
533
- if(this.element) this.arrangeOutlet();
534
-
535
- if(this.component.componentDidUpdate) {
536
- this.component.componentDidUpdate(prev_props, prev_state, this.last_snapshot);
537
- }
538
-
539
- if(this.last_snapshot) delete this.last_snapshot;
540
- }
541
-
542
- }
543
- catch(e) {
544
- renderErrorHandler(this, e);
545
- }
546
-
547
- }
548
-
549
- async cleanup()
550
- {
551
- unregisterComponentCore(this);
552
- try {
553
- const promises = [];
554
-
555
- if(this.props?.ref) {
556
- if(typeof(this.props.ref)==='function') {
557
- this.props.ref(null);
558
- }
559
- else {
560
- this.props.ref.current = null;
561
- }
562
- }
563
-
564
- if(this.component.componentWillUnmount) {
565
- this.component.componentWillUnmount();
566
- }
567
-
568
- if(this?.element?.parentElement && !this.portal) {
569
- this.element.parentElement.removeChild( this.element );
570
- }
571
-
572
- if(this.outlet!==undefined) {
573
- for(let c of this.outlet) {
574
- if(c.cleanup) {
575
- promises.push(c.cleanup());
576
- }
577
- }
578
- }
579
-
580
- if(this.props?.children!==undefined) {
581
- for(let c of this.props.children) {
582
- if(c.cleanup) {
583
- promises.push(c.cleanup());
584
- }
585
- }
586
- }
587
-
588
- if(this.hooks!==undefined) {
589
- for(let h of this.hooks) {
590
- if(h.cleanup) {
591
- promises.push(h.cleanup());
592
- }
593
- }
594
- }
595
-
596
- await Promise.all(promises);
597
- }
598
-
599
- catch(e) {
600
- throw(e);
601
- }
602
- }
603
-
604
- updateElementProps(patch, force=false)
605
- {
606
- // note: string.slice(0,undefined) returns the complete string. that's why
607
- // the slices are correct even if maxLength is not set.
608
-
609
- if(this.entity==="input") {
610
- if(!patch?.type) patch.type = 'text';
611
- if(patch.type!==this.element.type) {
612
- this.element.type=patch.type;
613
- }
614
-
615
- if(patch?.value!==undefined && patch?.value!==this.element.value) {
616
- if(patch.value===undefined) patch.value='';
617
- this.element.value=String(patch.value).slice(0, patch?.maxLength);
618
- }
619
- }
620
- else if(this.entity==="textarea") {
621
- if(patch?.value!==this.element.value) {
622
- this.element.value=String(patch.value).slice(0, patch?.maxLength);
623
- }
624
- }
625
- else if(this.entity==="select") {
626
- if(typeof(patch.value)==='string') {
627
- if(patch.value!==this.element.value) {
628
- this.element.value=patch.value;
629
- }
630
- }
631
- }
632
- else if(this.entity==="option") {
633
- if(this.container?.props?.value?.constructor?.name==='Array') {
634
- patch.selected = this.container.props.value.indexOf(patch.value)!==-1;
635
- }
636
- else if(typeof(this.container?.props?.value)==='string') {
637
- patch.selected = this.container.props.value===patch.value;
638
- }
639
- }
640
-
641
- // old ones that don't exist in the new one
642
- for(let a in this.props) {
643
- const al = a.toLowerCase();
644
-
645
- if( !patch.hasOwnProperty(a) || ( !a.startsWith('data-') && !a.startsWith('aria-') &&
646
- (patch[a]===undefined || patch[a]===null || patch[a]==='' || patch[a]===false ) ) )
647
- {
648
- if( events_set.has(al) ) {
649
- this.event_detachers[al]();
650
- }
651
- else {
652
- this.element.removeAttribute(a);
653
- }
654
-
655
- }
656
- }
657
-
658
- for(let a in patch) {
659
- const al = a.toLowerCase();
660
-
661
- if( special_attributes.has(al) ) continue;
662
-
663
- if( patch===this.props || !Lilact.defaultIsEqual(patch[a], this.props[a]) || force ) {
664
-
665
- if( events_set.has(al) ) {
666
- this.event_detachers ??= {};
667
- this.event_detachers[al]?.();
668
- this.event_detachers[al] = Lilact.addWrappedEventListener(this.element, al.substring(2), patch[a]);
669
- }
670
- else if( capture_events_set.hasOwnProperty(al) ) {
671
- const alc = capture_events_set[al];
672
- this.event_detachers ??= {};
673
- this.event_detachers[al]?.();
674
- this.event_detachers[al] =
675
- Lilact.addWrappedEventListener(this.element, alc.substring(2), patch[a], {capture: true});
676
- }
677
- else if(a==='style') {
678
- if(typeof(patch.style)==='string') {
679
- this.element.style = patch.style;
680
- }
681
- else {
682
- if(this.props?.style) {
683
- if(typeof(this.props.style)==='string') {
684
- this.element.style = "";
685
- }
686
- else {
687
- for(let p in this.props.style) {
688
- if( p!==CLONED_STYLE && !patch?.style?.hasOwnProperty?.(p) ) {
689
- this.element.style[p] = "";
690
- }
691
- }
692
- }
693
- }
694
- for(const x in patch.style) {
695
- if( length_css_attributes_set.has(x) ) {
696
- if(isFinite(patch.style[x])) {
697
- patch.style[x]+='px';
698
- }
699
- }
700
- }
701
- Object.assign(this.element.style, patch.style);
702
- }
703
- }
704
- else if(boolean_html_attributes_set.has(a)) { // not lower cased(al), as it is set as a js property
705
- const v = toBool(patch[a]);
706
-
707
- if(v!==this.element[a]) {
708
- this.element[a] = v;
709
- }
710
- }
711
- else if(a==='autoFocus') { // not lower cased(al), as it is set as a js property
712
- this.element['autofocus'] = toBool(patch[a]);
713
- }
714
- else if(a==='htmlFor' || a==='for') { // not lower cased(al), as it is set as a js property
715
- this.element.setAttribute('for', patch[a]);
716
- }
717
- else if(al!=='value' || ['input', 'textarea', 'select'].indexOf(this.entity)===-1) {
718
- this.element.setAttribute(a, patch[a]);
719
- }
720
- }
721
- }
722
-
723
-
724
- if(patch?.action) {
725
- this.element.onsubmit = patch.action;
726
- }
727
- else {
728
- this.element.onsubmit = undefined;
729
- }
730
-
731
- this.updateElementClass(patch);
732
- }
733
-
734
- updateElementClass(patch=this.props)
735
- {
736
- let cn = patch?.className ?? patch?.class ?? '';
737
-
738
- if(this?.parent?.[CHILD_CLASS_ADDENDUM]) {
739
- cn += ' ' + this.parent[CHILD_CLASS_ADDENDUM];
740
- }
741
- cn = cn.trim();
742
-
743
- for(const n of Array.from(this.element.classList)) {
744
- if(cn.indexOf(n)===-1) {
745
- this.element.classList.remove(n);
746
- }
747
- }
748
-
749
- if(cn.length>0) {
750
- cn = cn.split(/\s+/g);
751
- for(const n of cn) {
752
- if(n.length>0) {
753
- this.element.classList.add(n);
754
- }
755
- }
756
- }
757
- }
758
-
759
-
760
- scanZombies(container, next_element)
761
- {
762
- const chs = container.element.childNodes;
763
- while( chs[container.insert_index] &&
764
- chs[container.insert_index][IS_ZOMBIE] &&
765
- chs[container.insert_index]!==next_element )
766
- {
767
- container.insert_index++;
768
- }
769
- }
770
-
771
- appendElement(core)
772
- {
773
- if(core.portal) return;
774
-
775
- this.scanZombies(core.container, core.element);
776
-
777
- if(core?.element.parentNode===null) {
778
- core.container.element.insertBefore(
779
- core.element,
780
- core.container.element.childNodes[core.container.insert_index] || null
781
- );
782
-
783
- if(core?.component?.componentDidMount) {
784
- core.component.componentDidMount();
785
- }
786
-
787
- }
788
- else {
789
- if(core.container.element.childNodes[core.container.insert_index]!==core.element) {
790
- core.container.element.insertBefore(
791
- core.element,
792
- core.container.element.childNodes[core.container.insert_index] || null
793
- );
794
- }
795
- }
796
- core.container.insert_index++;
797
- }
798
-
799
- arrangeOutlet()
800
- {
801
- this.insert_index = 0;
802
-
803
- for(const core of this.outlet) {
804
- if(core) {
805
- if(core.element) {
806
- core.container = this.element?this:this.container;
807
- core.container.appendElement(core);
808
- }
809
- else {
810
- if(core.arrangeOutlet && core.outlet) core.arrangeOutlet();
811
-
812
- // todo: is there a way to remove this useless flag?
813
- if(!core?.mounted) {
814
- core.mounted = true;
815
- if(core?.component?.componentDidMount) {
816
- core.component.componentDidMount();
817
- }
818
-
819
- }
820
-
821
- }
822
- }
823
- }
824
- }
825
-
826
- // note: override this to tailor function children like <Transition>{(state)=>{...}}</Transition>
827
- childFunctionHandler(func) {
828
- return func(this.state);
829
- }
830
-
831
- }
832
-
833
-
834
-
835
- const renderErrorHandler = (c, e) =>
836
- {
837
- const value =
838
- e?.error instanceof Error
839
- ? e.error
840
- : e?.reason !== undefined
841
- ? e.reason
842
- : e;
843
-
844
- const error = Lilact.isThenable(e)? e : Lilact.traceError(
845
- value,
846
- e?.fileName || null
847
- );
848
-
849
- const stack = [c];
850
-
851
- while(c && !c.component?.componentDidCatch) {
852
- c = c.parent;
853
- if(c) stack.push(c);
854
- }
855
-
856
- if(c?.component?.componentDidCatch) {
857
- if(c.entity?.getDerivedStateFromError) {
858
- c.component.setState(c.entity.getDerivedStateFromError.call(c, error));
859
- }
860
- }
861
-
862
- let stack_log = Array.prototype
863
- .map.call(stack, x => (`in ${typeof(x.component.displayName)==='function'?
864
- x.component.displayName():x.component.displayName}` ) )
865
- .join('\n');
866
-
867
- error.componentStack = stack;
868
- error.componentStackLog = stack_log;
869
-
870
- if(c?.component?.componentDidCatch) {
871
- c.component.componentDidCatch(error, {componentStack: stack, componentStackLog: stack_log});
872
- }
873
- else throw(e); // should be e not error
874
- }
875
37
 
876
38
 
877
39
  //////////
878
40
 
879
41
 
880
42
 
881
- function constructFunc(core, parent) {
882
- let comp = core;
883
-
884
- if (core[TEXT] === undefined) {
885
- let entity = core.entity;
886
- let memoized = false;
887
-
888
- const loc = core.props[LOCATION];
889
- if(loc) delete core.props[LOCATION];
890
-
891
- if (typeof entity === "object") {
892
- if (entity[MEMOIZED]) {
893
- memoized = entity[MEMOIZED];
894
- entity = entity.component;
895
- } else {
896
- throw new Error("Invalid component.");
897
- }
898
- }
899
-
900
- entity = resolveHotEntity(entity);
901
-
902
- if (typeof entity === "string") {
903
- comp = new HTMLComponent(entity, core.props);
904
- }
905
- else if (isClass(entity)) {
906
- if (entity?.defaultProps) {
907
- core.props = {
908
- ...entity.defaultProps,
909
- ...core.props,
910
- };
911
- }
912
-
913
- comp = new entity(core.props);
914
-
915
- const desc = Object.getOwnPropertyDescriptor(comp, "state");
916
-
917
- if (desc) {
918
- if (
919
- typeof desc.get !== "function" &&
920
- typeof desc.set !== "function"
921
- ) {
922
- comp[CORE].state = comp.state;
923
-
924
- Object.defineProperty(comp, "state", {
925
- get() {
926
- return this[CORE].state;
927
- },
928
- set(value) {
929
- if (this[CORE].state === undefined) {
930
- this[CORE].state = value;
931
- } else {
932
- throw new Error(
933
- "Assigning component state this way is not allowed."
934
- );
935
- }
936
- },
937
- });
938
- }
939
- }
940
- }
941
- else if (typeof entity === "function") {
942
- if (entity?.defaultProps) {
943
- core.props = {
944
- ...entity.defaultProps,
945
- ...core.props,
946
- };
947
- }
948
-
949
- comp = new Component(core.props);
950
- comp.render = entity.bind(comp);
951
- comp[CORE].hooks = [];
952
- comp[CORE].hook_index = 0;
953
- }
954
- else {
955
- throw new Error("Error in constructing component.");
956
- }
957
-
958
- if(loc) comp[CORE].location = loc;
959
-
960
- comp[CORE].entity = entity;
961
- registerComponentCore(comp[CORE]);
962
-
963
- if (core.container) {
964
- comp[CORE].container = core.container;
965
- }
966
-
967
- if (memoized) {
968
- comp[CORE][MEMOIZED] = true;
969
- }
970
- }
971
-
972
- if (parent instanceof ComponentCore) {
973
- comp[CORE].parent = parent;
974
- }
975
-
976
- return comp;
977
- }
978
-
979
-
980
- function prepareCore(parent, core)
981
- {
982
- try {
983
- parent.cache ??= new ComponentCache(parent);
984
-
985
- const isText = core[TEXT] !== undefined;
986
- const isExistingCore = core instanceof ComponentCore;
987
-
988
- const entity = isText || isExistingCore
989
- ? undefined
990
- : resolveHotEntity(core.entity);
991
-
992
- const hasExplicitKey =
993
- !isText &&
994
- core.props &&
995
- core.props.key !== undefined &&
996
- core.props.key !== null;
997
-
998
- let key;
999
-
1000
- if (isText) {
1001
- key = ':text:';
1002
- }
1003
- else if (hasExplicitKey) {
1004
- key = core.props.key;
1005
- }
1006
- else if (typeof entity === "function") {
1007
- key = getHotEntityCacheToken(entity);
1008
- }
1009
- else {
1010
- key = entity;
1011
- }
1012
-
1013
- return parent.cache.pick(
1014
- key,
1015
- () => (
1016
- isText || isExistingCore
1017
- ? core
1018
- : constructFunc(core, parent)[CORE]
1019
- ),
1020
- entity
1021
- );
1022
- }
1023
- catch (e) {
1024
- if (core?.component?.componentDidCatch) {
1025
- core.component.componentDidCatch(e);
1026
- }
1027
- else {
1028
- throw e;
1029
- }
1030
- }
1031
- }
1032
-
1033
43
 
1034
44
  function doUpdates()
1035
45
  {
@@ -1383,6 +393,8 @@ export class RootComponent extends HTMLComponent
1383
393
  element = document.querySelector(element);
1384
394
  }
1385
395
 
396
+ element.innerHTML="";
397
+
1386
398
  this[CORE].element = element;
1387
399
 
1388
400
  for(const ch of props.children) {
@@ -1475,7 +487,7 @@ export function createRoot(element)
1475
487
 
1476
488
  unmount() {
1477
489
  if(root) {
1478
- root.cleanup();
490
+ root[CORE].cleanup();
1479
491
  element.innerHTML="";
1480
492
  }
1481
493
  },
@@ -1639,51 +651,3 @@ export let update_timeout = undefined;
1639
651
  export let effect_timeout = undefined;
1640
652
  /** @ignore */
1641
653
  export let update_interval_margin = 0;
1642
-
1643
- /** @ignore */
1644
- export const special_attributes = new Set([
1645
- "classname", "ref", "action", "lilact_jsx_loc", "children", "key",
1646
- "defaultvalue", "defaultchecked"
1647
- ]);
1648
-
1649
- /** @ignore */
1650
- export const events_set = new Set([
1651
- "onafterprint","onbeforeprint","onbeforeunload","onerror","onhashchange","onload","onmessage",
1652
- "onoffline","ononline","onpagehide","onpageshow","onpopstate","onresize","onstorage","onunload",
1653
- "onblur","onchange","oncontextmenu","onfocus","oninput","oninvalid","onreset","onsearch","onselect",
1654
- "onsubmit", "oncancel",
1655
- "onkeydown","onkeypress","onkeyup",
1656
- "onclick","ondblclick","onmousedown","onmousemove","onmouseout","onmouseover","onmouseup","onmousewheel",
1657
- "onwheel",
1658
- "ondrag","ondragend","ondragenter","ondragleave","ondragover","ondragstart","ondrop","onscroll",
1659
- "oncopy","oncut","onpaste",
1660
- "onabort","oncanplay","oncanplaythrough","oncuechange","ondurationchange","onemptied","onended","onerror",
1661
- "onloadeddata","onloadedmetadata","onloadstart","onpause","onplay","onplaying","onprogress","onratechange",
1662
- "onseeked","onseeking","onstalled","onsuspend","ontimeupdate","onvolumechange","onwaiting",
1663
- "ontoggle",
1664
- "onpointerdown", "onpointerup", "onpointermove", "onpointercancel", "onpointerover", "onpointerout",
1665
- "onpointerenter", "onpointerleave"
1666
- ]);
1667
-
1668
- /** @ignore */
1669
- export const capture_events_set = {};
1670
- for (const x of events_set) {
1671
- capture_events_set[x+"capture"] = x;
1672
- }
1673
-
1674
- /** @ignore */
1675
- export const length_css_attributes_set = new Set([
1676
- "width","height","minWidth","minHeight","maxWidth","maxHeight","top","right","bottom","left","margin",
1677
- "marginTop","marginRight","marginBottom","marginLeft","padding","paddingTop","paddingRight","paddingBottom",
1678
- "paddingLeft","borderWidth","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth",
1679
- "outlineWidth","fontSize","lineHeight","letterSpacing","wordSpacing","textIndent","borderRadius",
1680
- "borderTopLeftRadius","borderTopRightRadius","borderBottomLeftRadius","borderBottomRightRadius",
1681
- "columnGap","rowGap","gap"
1682
- ]);
1683
-
1684
- /** @ignore */
1685
- export const boolean_html_attributes_set = new
1686
- Set(["disabled", "readOnly", "required", "checked", "multiple", "selected",
1687
- "hidden","open","loop","muted","controls","playsInline","allowFullScreen"]);
1688
-
1689
-