lilact 0.27.1 → 0.27.2
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/dist/lilact.development.js +221 -121
- package/dist/lilact.development.js.map +3 -3
- package/dist/lilact.development.min.js +57 -57
- package/dist/lilact.development.min.js.map +3 -3
- package/dist/lilact.production.min.js +57 -57
- package/docs/classes/accessories.ErrorBoundary.html +3 -3
- package/docs/classes/accessories.Suspense.html +2 -2
- package/docs/classes/components.Component.html +3 -3
- package/docs/classes/components.HTMLComponent.html +4 -4
- package/docs/classes/components.RootComponent.html +5 -5
- package/docs/functions/components.cloneComponent.html +1 -1
- package/docs/functions/components.createComponent.html +1 -1
- package/docs/functions/components.createPortal.html +1 -1
- package/docs/functions/components.createRoot.html +1 -1
- package/docs/functions/components.memo.html +1 -1
- package/docs/functions/components.render.html +1 -1
- package/docs/functions/hooks.startTransition.html +1 -1
- package/docs/functions/hooks.useActionState.html +1 -1
- package/docs/functions/hooks.useDebugValue.html +1 -1
- package/docs/functions/hooks.useDeferredValue.html +1 -1
- package/docs/functions/hooks.useEffect.html +1 -1
- package/docs/functions/hooks.useId.html +1 -1
- package/docs/functions/hooks.useImperativeHandle.html +1 -1
- package/docs/functions/hooks.useInsertionEffect.html +1 -1
- package/docs/functions/hooks.useLayoutEffect.html +1 -1
- package/docs/functions/hooks.useLocalStorage.html +1 -1
- package/docs/functions/hooks.useMemo.html +1 -1
- package/docs/functions/hooks.useReducer.html +1 -1
- package/docs/functions/hooks.useRef.html +1 -1
- package/docs/functions/hooks.useTransition.html +1 -1
- package/docs/functions/misc.Fragment.html +2 -2
- package/docs/functions/misc.Portal.html +2 -2
- package/docs/functions/misc.deepEqual.html +1 -1
- package/docs/functions/misc.findDOMNode.html +1 -1
- package/docs/functions/misc.forwardRef.html +1 -1
- package/docs/functions/misc.getComponentByPointer.html +1 -1
- package/docs/functions/misc.isAsync.html +1 -1
- package/docs/functions/misc.isClass.html +1 -1
- package/docs/functions/misc.isEmpty.html +1 -1
- package/docs/functions/misc.isError.html +1 -1
- package/docs/functions/misc.isThenable.html +1 -1
- package/docs/functions/misc.shallowEqual.html +1 -1
- package/docs/functions/misc.toBool.html +1 -1
- package/docs/functions/run.lazy.html +1 -1
- package/docs/functions/run.require.html +1 -1
- package/docs/functions/run.run.html +1 -1
- package/docs/functions/run.runScripts.html +1 -1
- package/docs/functions/timers.timeoutPromise.html +10 -10
- package/docs/static/index.html +1 -1
- package/docs/static/lilact.development.js +221 -121
- package/docs/static/lilact.development.js.map +3 -3
- package/docs/static/lilact.development.min.js +57 -57
- package/docs/static/lilact.development.min.js.map +3 -3
- package/docs/static/lilact.production.min.js +57 -57
- package/docs/variables/components.cloneElement.html +1 -1
- package/docs/variables/misc.Children.html +10 -10
- package/docs/variables/misc.isValidElement.html +1 -1
- package/docs/variables/run.required_scripts.html +1 -1
- package/examples/index.html +1 -1
- package/examples/lilact.development.js +221 -121
- package/examples/lilact.development.js.map +3 -3
- package/examples/lilact.development.min.js +57 -57
- package/examples/lilact.development.min.js.map +3 -3
- package/examples/lilact.production.min.js +57 -57
- package/package.json +1 -1
- package/src/components.jsx +24 -13
- package/src/errors.jsx +310 -310
- package/src/hooks.jsx +46 -50
- package/src/misc.jsx +46 -18
- package/src/run.jsx +405 -290
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
|
-
|
|
92
|
-
|
|
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
|
|
143
|
+
while (core && core.entity !== context.Provider) {
|
|
145
144
|
core = core.parent;
|
|
146
145
|
}
|
|
147
146
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
-
|
|
187
|
+
try {
|
|
188
|
+
return await fn();
|
|
189
|
+
} finally {
|
|
190
|
+
hk.count--;
|
|
196
191
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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
|
-
|
|
284
|
-
|
|
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,8 +288,8 @@ export async function useLayoutEffect(effect, deps=undefined)
|
|
|
295
288
|
|
|
296
289
|
if(hk?.cleanup) {
|
|
297
290
|
await hk.cleanup();
|
|
298
|
-
|
|
299
|
-
|
|
291
|
+
hk.cleanup = undefined;
|
|
292
|
+
}
|
|
300
293
|
|
|
301
294
|
hk.deps = deps;
|
|
302
295
|
Lilact.layout_effects.add( async ()=>{ hk.cleanup = await effect(); });
|
|
@@ -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
|
-
|
|
320
|
-
|
|
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,7 +324,7 @@ export async function useEffect(effect, deps=undefined)
|
|
|
331
324
|
|
|
332
325
|
if(hk?.cleanup) {
|
|
333
326
|
await hk.cleanup();
|
|
334
|
-
|
|
327
|
+
hk.cleanup = undefined;
|
|
335
328
|
}
|
|
336
329
|
|
|
337
330
|
hk.deps = deps;
|
|
@@ -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
|
-
|
|
357
|
-
|
|
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,7 +361,7 @@ export async function useInsertionEffect(effect, deps=undefined)
|
|
|
368
361
|
|
|
369
362
|
if(hk?.cleanup) {
|
|
370
363
|
await hk.cleanup();
|
|
371
|
-
|
|
364
|
+
hk.cleanup = undefined;
|
|
372
365
|
}
|
|
373
366
|
|
|
374
367
|
hk.deps = deps;
|
|
@@ -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
|
-
|
|
394
|
-
|
|
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(
|
|
461
|
-
hk.
|
|
462
|
-
|
|
452
|
+
if(isEmpty(hk)) {
|
|
453
|
+
hk.state = init ? init(initialArg) : initialArg;
|
|
454
|
+
|
|
463
455
|
hk.dispatch = function(core, hk, action) {
|
|
464
|
-
const
|
|
465
|
-
|
|
466
|
-
|
|
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/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 =
|
|
58
|
-
|
|
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
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
+
if (Object.is(source, target)) {
|
|
366
|
+
return true;
|
|
367
|
+
}
|
|
365
368
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
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
|
-
|
|
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
|
/**
|