lilact 0.27.1 → 0.27.3

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 (79) hide show
  1. package/dist/lilact.development.js +413 -308
  2. package/dist/lilact.development.js.map +4 -4
  3. package/dist/lilact.development.min.js +59 -59
  4. package/dist/lilact.development.min.js.map +4 -4
  5. package/dist/lilact.production.min.js +58 -58
  6. package/docs/classes/accessories.ErrorBoundary.html +3 -3
  7. package/docs/classes/accessories.Suspense.html +2 -2
  8. package/docs/classes/components.Component.html +3 -3
  9. package/docs/classes/components.HTMLComponent.html +4 -4
  10. package/docs/classes/components.RootComponent.html +5 -5
  11. package/docs/functions/components.cloneComponent.html +1 -1
  12. package/docs/functions/components.createComponent.html +1 -1
  13. package/docs/functions/components.createPortal.html +1 -1
  14. package/docs/functions/components.createRoot.html +1 -1
  15. package/docs/functions/components.memo.html +1 -1
  16. package/docs/functions/components.render.html +1 -1
  17. package/docs/functions/hooks.startTransition.html +1 -1
  18. package/docs/functions/hooks.useActionState.html +1 -1
  19. package/docs/functions/hooks.useDebugValue.html +1 -1
  20. package/docs/functions/hooks.useDeferredValue.html +1 -1
  21. package/docs/functions/hooks.useEffect.html +1 -1
  22. package/docs/functions/hooks.useId.html +1 -1
  23. package/docs/functions/hooks.useImperativeHandle.html +1 -1
  24. package/docs/functions/hooks.useInsertionEffect.html +1 -1
  25. package/docs/functions/hooks.useLayoutEffect.html +1 -1
  26. package/docs/functions/hooks.useLocalStorage.html +1 -1
  27. package/docs/functions/hooks.useMemo.html +1 -1
  28. package/docs/functions/hooks.useReducer.html +1 -1
  29. package/docs/functions/hooks.useRef.html +1 -1
  30. package/docs/functions/hooks.useTransition.html +1 -1
  31. package/docs/functions/misc.Fragment.html +2 -2
  32. package/docs/functions/misc.Portal.html +2 -2
  33. package/docs/functions/misc.deepEqual.html +1 -1
  34. package/docs/functions/misc.findDOMNode.html +1 -1
  35. package/docs/functions/misc.forwardRef.html +1 -1
  36. package/docs/functions/misc.getComponentByPointer.html +1 -1
  37. package/docs/functions/misc.isAsync.html +1 -1
  38. package/docs/functions/misc.isClass.html +1 -1
  39. package/docs/functions/misc.isEmpty.html +1 -1
  40. package/docs/functions/misc.isError.html +1 -1
  41. package/docs/functions/misc.isThenable.html +1 -1
  42. package/docs/functions/misc.shallowEqual.html +1 -1
  43. package/docs/functions/misc.toBool.html +1 -1
  44. package/docs/functions/run.lazy.html +1 -1
  45. package/docs/functions/run.require.html +1 -1
  46. package/docs/functions/run.run.html +1 -1
  47. package/docs/functions/run.runScripts.html +1 -1
  48. package/docs/functions/timers.animationFramePromise.html +1 -1
  49. package/docs/functions/timers.clearInterval.html +1 -1
  50. package/docs/functions/timers.grabTimers.html +1 -1
  51. package/docs/functions/timers.releaseTimers.html +1 -1
  52. package/docs/functions/timers.timeoutPromise.html +14 -14
  53. package/docs/static/index.html +1 -1
  54. package/docs/static/lilact.development.js +413 -308
  55. package/docs/static/lilact.development.js.map +4 -4
  56. package/docs/static/lilact.development.min.js +59 -59
  57. package/docs/static/lilact.development.min.js.map +4 -4
  58. package/docs/static/lilact.production.min.js +58 -58
  59. package/docs/variables/components.cloneElement.html +1 -1
  60. package/docs/variables/misc.Children.html +10 -10
  61. package/docs/variables/misc.isValidElement.html +1 -1
  62. package/docs/variables/run.required_scripts.html +1 -1
  63. package/examples/index.html +1 -1
  64. package/examples/lilact.development.js +413 -308
  65. package/examples/lilact.development.js.map +4 -4
  66. package/examples/lilact.development.min.js +59 -59
  67. package/examples/lilact.development.min.js.map +4 -4
  68. package/examples/lilact.production.min.js +58 -58
  69. package/package.json +1 -1
  70. package/src/accessories.jsx +1 -1
  71. package/src/components.jsx +27 -16
  72. package/src/errors.jsx +310 -310
  73. package/src/expscan.js +2 -2
  74. package/src/hooks.jsx +52 -56
  75. package/src/lilact.jsx +7 -1
  76. package/src/misc.jsx +46 -18
  77. package/src/run.jsx +405 -290
  78. package/src/timers.jsx +2 -0
  79. package/src/transition.jsx +1 -1
package/src/expscan.js CHANGED
@@ -240,10 +240,10 @@ export function processImportExports(node, jsx)
240
240
  }
241
241
 
242
242
  let cjs = '';
243
- for(const s of import_alls) {
243
+ for(const s of star_imports) {
244
244
  cjs+=`const ${s} = require(${src},{requirer:module});\n`;
245
245
  }
246
- for(const s of star_imports) {
246
+ for(const s of import_alls) {
247
247
  cjs+=`const ${s} = require(${src},{requirer:module, checkExport: ['default']}).default;\n`;
248
248
  }
249
249
  if(Object.keys(imports).length) {
package/src/hooks.jsx CHANGED
@@ -88,9 +88,9 @@ export function useState(initialValue)
88
88
  export function useCallback(callback, deps=undefined)
89
89
  {
90
90
  if(
91
- deps !== undefined && !Array.isArray(deps) &&
92
- deps !== null && typeof deps !== "object"
93
- )
91
+ deps !== undefined && !Array.isArray(deps) &&
92
+ deps !== null && typeof deps !== "object"
93
+ )
94
94
  {
95
95
  throw new Error("Callback dependencies must be an array, object or omitted.");
96
96
  }
@@ -137,22 +137,17 @@ export function createContext(defaultValue)
137
137
  * @param {any} context - Context object created by `createContext`.
138
138
  * @returns {any} Current context value.
139
139
  */
140
- export function useContext(context)
141
- {
142
- let core = Lilact.current_component[0].parent;
140
+ export function useContext(context) {
141
+ let core = Lilact.current_component[0]?.parent;
143
142
 
144
- while(core.entity!==context.Provider && core.parent) {
143
+ while (core && core.entity !== context.Provider) {
145
144
  core = core.parent;
146
145
  }
147
146
 
148
- if(core.parent) {
149
- let v = core.props?.value;
150
- return v??=context.default;
151
- }
152
-
153
- return context.default;
147
+ return core
148
+ ? core.props?.value ?? context.default
149
+ : context.default;
154
150
  }
155
-
156
151
  /**
157
152
  * Returns a stable, unique ID that is consistent across renders.
158
153
  *
@@ -182,26 +177,24 @@ export function useTransition()
182
177
  if( isEmpty(hk) ) {
183
178
  hk.count=0;
184
179
 
185
- hk.func =
186
-
187
- (async function(core, hk, fn) {
188
-
189
- if(hk.count===0) {
180
+ hk.func = (async function(core, hk, fn) {
181
+ if (hk.count === 0) {
190
182
  core.component.forceUpdate();
191
183
  }
192
184
 
193
185
  hk.count++;
194
186
 
195
- await fn();
187
+ try {
188
+ return await fn();
189
+ } finally {
190
+ hk.count--;
196
191
 
197
- hk.count--;
198
-
199
- if(hk.count===0) {
200
- core.component.forceUpdate();
192
+ if (hk.count === 0) {
193
+ core.component.forceUpdate();
194
+ }
201
195
  }
202
- }
196
+ }).bind(undefined, Lilact.current_component[0], hk);
203
197
 
204
- ).bind(undefined, Lilact.current_component[0], hk);
205
198
  }
206
199
 
207
200
  return [ hk.count!=0, hk.func ];
@@ -280,9 +273,9 @@ export function useRef(initialValue = null)
280
273
  export async function useLayoutEffect(effect, deps=undefined)
281
274
  {
282
275
  if(
283
- deps !== undefined && !Array.isArray(deps) &&
284
- deps !== null && typeof deps !== "object"
285
- )
276
+ deps !== undefined && !Array.isArray(deps) &&
277
+ deps !== null && typeof deps !== "object"
278
+ )
286
279
  {
287
280
  throw new Error("Layout effect dependencies must be an array, object or omitted.");
288
281
  }
@@ -295,14 +288,14 @@ export async function useLayoutEffect(effect, deps=undefined)
295
288
 
296
289
  if(hk?.cleanup) {
297
290
  await hk.cleanup();
298
- hk.cleanup = undefined;
299
- }
291
+ hk.cleanup = undefined;
292
+ }
300
293
 
301
294
  hk.deps = deps;
302
295
  Lilact.layout_effects.add( async ()=>{ hk.cleanup = await effect(); });
303
296
 
304
- Lilact.clearTimeout( Lilact.effect_timeout );
305
- Lilact.setTimeout( Lilact.processEffects, 0 );
297
+ Lilact._clearTimeout( Lilact.effect_timeout );
298
+ Lilact._setTimeout( Lilact.processEffects, 0 );
306
299
  }
307
300
 
308
301
  /**
@@ -316,9 +309,9 @@ export async function useLayoutEffect(effect, deps=undefined)
316
309
  export async function useEffect(effect, deps=undefined)
317
310
  {
318
311
  if(
319
- deps !== undefined && !Array.isArray(deps) &&
320
- deps !== null && typeof deps !== "object"
321
- )
312
+ deps !== undefined && !Array.isArray(deps) &&
313
+ deps !== null && typeof deps !== "object"
314
+ )
322
315
  {
323
316
  throw new Error("Effect dependencies must be an array, object or omitted.");
324
317
  }
@@ -331,14 +324,14 @@ export async function useEffect(effect, deps=undefined)
331
324
 
332
325
  if(hk?.cleanup) {
333
326
  await hk.cleanup();
334
- hk.cleanup = undefined;
327
+ hk.cleanup = undefined;
335
328
  }
336
329
 
337
330
  hk.deps = deps;
338
331
  Lilact.passive_effects.add( async ()=>{ hk.cleanup = await effect(); });
339
332
 
340
- Lilact.clearTimeout( Lilact.effect_timeout );
341
- Lilact.setTimeout( Lilact.processEffects, 0 );
333
+ Lilact._clearTimeout( Lilact.effect_timeout );
334
+ Lilact._setTimeout( Lilact.processEffects, 0 );
342
335
  }
343
336
 
344
337
 
@@ -353,9 +346,9 @@ export async function useEffect(effect, deps=undefined)
353
346
  export async function useInsertionEffect(effect, deps=undefined)
354
347
  {
355
348
  if(
356
- deps !== undefined && !Array.isArray(deps) &&
357
- deps !== null && typeof deps !== "object"
358
- )
349
+ deps !== undefined && !Array.isArray(deps) &&
350
+ deps !== null && typeof deps !== "object"
351
+ )
359
352
  {
360
353
  throw new Error("Insertion effect dependencies must be an array, object, or omitted.");
361
354
  }
@@ -368,14 +361,14 @@ export async function useInsertionEffect(effect, deps=undefined)
368
361
 
369
362
  if(hk?.cleanup) {
370
363
  await hk.cleanup();
371
- hk.cleanup = undefined;
364
+ hk.cleanup = undefined;
372
365
  }
373
366
 
374
367
  hk.deps = deps;
375
368
  Lilact.insertion_effects.add( async ()=>{ hk.cleanup = await effect(); });
376
369
 
377
- Lilact.clearTimeout( Lilact.effect_timeout );
378
- Lilact.setTimeout( Lilact.processEffects, 0 );
370
+ Lilact._clearTimeout( Lilact.effect_timeout );
371
+ Lilact._setTimeout( Lilact.processEffects, 0 );
379
372
  }
380
373
 
381
374
 
@@ -390,9 +383,9 @@ export async function useInsertionEffect(effect, deps=undefined)
390
383
  export function useMemo(factory,deps=undefined)
391
384
  {
392
385
  if(
393
- deps !== undefined && !Array.isArray(deps) &&
394
- deps !== null && typeof deps !== "object"
395
- )
386
+ deps !== undefined && !Array.isArray(deps) &&
387
+ deps !== null && typeof deps !== "object"
388
+ )
396
389
  {
397
390
  throw new Error("Memo dependencies must be an array or omitted.");
398
391
  }
@@ -453,27 +446,30 @@ export function useActionState(action, initialState)
453
446
  * @param {Function} [init] - Optional initializer function for lazy initial state.
454
447
  * @returns {any} Hook result `[state, dispatch]`.
455
448
  */
456
- export function useReducer(reducer, initialArg, init)
457
- {
449
+ export function useReducer(reducer, initialArg, init) {
458
450
  const hk = useHook();
459
451
 
460
- if( isEmpty(hk) ) {
461
- hk.reducer = reducer;
462
- hk.state = init?init(initialArg):initialArg;
452
+ if(isEmpty(hk)) {
453
+ hk.state = init ? init(initialArg) : initialArg;
454
+
463
455
  hk.dispatch = function(core, hk, action) {
464
- const newst = hk.reducer(hk.state, action);
465
- if(!Lilact.defaultIsEqual(newst,hk.state)) {
466
- hk.state = newst;
456
+ const newState = hk.reducer(hk.state, action);
457
+
458
+ if (!Lilact.defaultIsEqual(newState, hk.state)) {
459
+ hk.state = newState;
467
460
  core.component.forceUpdate();
468
461
  }
469
462
  }.bind(undefined, Lilact.current_component[0], hk);
470
463
  }
471
464
 
465
+ hk.reducer = reducer;
466
+
472
467
  return [hk.state, hk.dispatch];
473
468
  }
474
469
 
475
470
 
476
471
 
472
+
477
473
  // todo: very simple implementation. and not lilactish at all! must be modified
478
474
 
479
475
  /**
package/src/lilact.jsx CHANGED
@@ -126,10 +126,14 @@ export const Lilact =
126
126
  redux,
127
127
  emotion,
128
128
 
129
+ _setTimeout: window.setTimeout.bind(window),
130
+ _setInterval: window.setInterval.bind(window),
131
+ _clearTimeout: window.clearTimeout.bind(window),
132
+ _clearInterval: window.clearInterval.bind(window),
133
+
129
134
  }
130
135
 
131
136
  Lilact.default = Lilact;
132
-
133
137
  export default Lilact;
134
138
 
135
139
  Lilact.importObjectPaths = {
@@ -144,6 +148,8 @@ globalThis.Fragment = Lilact.Fragment;
144
148
  globalThis.require = Lilact.require;
145
149
 
146
150
  document.addEventListener("DOMContentLoaded", () => {
151
+ Lilact.grabTimers();
152
+
147
153
  Lilact.runScripts().catch(error => {
148
154
  Lilact.globalErrorHandler?.(error);
149
155
  });
package/src/misc.jsx CHANGED
@@ -54,9 +54,12 @@ const typeOf = (input) => {
54
54
  * @param value - Value to inspect.
55
55
  * @returns True if the value is a class component; otherwise false.
56
56
  */
57
- export const isValidComponent = (value) => {
58
- return value[CORE]!==undefined || value[TEXT]!==undefined;
59
- }
57
+ export const isValidComponent = value => {
58
+ return Boolean(
59
+ value &&
60
+ (value[CORE] !== undefined || value[TEXT] !== undefined)
61
+ );
62
+ };
60
63
 
61
64
  /**
62
65
  * Checks whether a value is a Lilact component. It is the same as `isValidComponent`.
@@ -359,23 +362,48 @@ export function isEmpty(value) {
359
362
  * @returns True if shallowly equal; otherwise false.
360
363
  */
361
364
  export const shallowEqual = (source, target, ignore) => {
362
- if (typeOf(source) !== typeOf(target)) {
363
- return false;
364
- }
365
+ if (Object.is(source, target)) {
366
+ return true;
367
+ }
365
368
 
366
- if (typeOf(source) === "array") {
367
- if (source.length !== target.length) {
368
- return false;
369
- }
370
- return source.every((el, index) => el === target[index] || index===ignore );
371
- } else if (typeOf(source) === "object") {
372
- return Object.keys(source).every((key) => source[key] === target[key] || key===ignore );
373
- } else if (typeOf(source) === "date") {
374
- return source.getTime() === target.getTime();
375
- }
369
+ if (typeOf(source) !== typeOf(target)) {
370
+ return false;
371
+ }
376
372
 
377
- return source === target;
378
- }
373
+ if (typeOf(source) === "array") {
374
+ if (source.length !== target.length) {
375
+ return false;
376
+ }
377
+
378
+ return source.every(
379
+ (value, index) =>
380
+ index === ignore || Object.is(value, target[index])
381
+ );
382
+ }
383
+
384
+ if (typeOf(source) === "object") {
385
+ const sourceKeys = Object.keys(source)
386
+ .filter(key => key !== ignore);
387
+
388
+ const targetKeys = Object.keys(target)
389
+ .filter(key => key !== ignore);
390
+
391
+ if (sourceKeys.length !== targetKeys.length) {
392
+ return false;
393
+ }
394
+
395
+ return sourceKeys.every(key =>
396
+ Object.prototype.hasOwnProperty.call(target, key) &&
397
+ Object.is(source[key], target[key])
398
+ );
399
+ }
400
+
401
+ if (typeOf(source) === "date") {
402
+ return source.getTime() === target.getTime();
403
+ }
404
+
405
+ return Object.is(source, target);
406
+ };
379
407
 
380
408
 
381
409
  /**