lilact 0.2.0 → 0.2.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/README.md +4 -5
- package/dist/lilact.development.min.js +238 -278
- package/dist/lilact.development.min.js.map +1 -1
- package/dist/lilact.production.min.js +8139 -1
- package/dist/lilact.production.min.js.map +1 -1
- package/docs/classes/accessories.ErrorBoundary.html +8 -8
- package/docs/classes/accessories.Suspense.html +7 -7
- package/docs/classes/components.Component.html +10 -10
- package/docs/classes/components.HTMLComponent.html +10 -10
- package/docs/classes/components.RootComponent.html +10 -10
- package/docs/functions/components.createComponent.html +1 -1
- package/docs/functions/components.createRoot.html +1 -1
- package/docs/functions/components.render.html +1 -1
- package/docs/functions/hooks.createContext.html +1 -1
- package/docs/functions/hooks.useActionState.html +3 -2
- package/docs/functions/hooks.useCallback.html +1 -1
- package/docs/functions/hooks.useContext.html +1 -1
- package/docs/functions/hooks.useEffect.html +4 -3
- package/docs/functions/hooks.useId.html +1 -1
- package/docs/functions/hooks.useImperativeHandle.html +1 -1
- package/docs/functions/hooks.useLayoutEffect.html +4 -3
- package/docs/functions/hooks.useLocalStorage.html +4 -3
- package/docs/functions/hooks.useMemo.html +4 -3
- package/docs/functions/hooks.useRef.html +4 -3
- package/docs/functions/hooks.useTransition.html +1 -1
- package/docs/index.html +4 -5
- package/docs/static/demos/pane.jsx +31 -0
- package/docs/static/demos/usetransition.jsx +1 -1
- package/docs/static/index.html +1 -0
- package/docs/static/lilact.development.min.js +238 -278
- package/docs/static/lilact.production.min.js +8139 -1
- package/package.json +1 -2
- package/root/demos/pane.jsx +31 -0
- package/root/demos/usetransition.jsx +1 -1
- package/root/index.html +1 -0
- package/root/lilact.development.min.js +238 -278
- package/root/lilact.production.min.js +8139 -1
- package/src/components.jsx +4 -1
- package/src/hooks.jsx +55 -55
- package/src/misc.jsx +13 -1
- package/src/pane.jsx +207 -269
- package/webpack.config.js +1 -1
- package/docs/static/index 2.html +0 -95
- package/root/index 2.html +0 -95
package/src/components.jsx
CHANGED
|
@@ -401,6 +401,9 @@ class ComponentCore
|
|
|
401
401
|
this.event_detachers[al] = Lilact.addWrappedEventListener(this.element, al.substring(2), patch[a]);
|
|
402
402
|
}
|
|
403
403
|
else if(al==='style') {
|
|
404
|
+
for(const x in patch[a]) {
|
|
405
|
+
if(isFinite(patch[a][x])) patch[a][x]+='px';
|
|
406
|
+
}
|
|
404
407
|
Object.assign(this.element.style, patch[a]);
|
|
405
408
|
}
|
|
406
409
|
else {
|
|
@@ -418,7 +421,7 @@ class ComponentCore
|
|
|
418
421
|
}
|
|
419
422
|
|
|
420
423
|
ʔ if(DEBUG) {
|
|
421
|
-
this.element.setAttribute('key', this.props.key);
|
|
424
|
+
//this.element.setAttribute('key', this.props.key);
|
|
422
425
|
ʔ }
|
|
423
426
|
|
|
424
427
|
this.updateElementClass(patch);
|
package/src/hooks.jsx
CHANGED
|
@@ -82,25 +82,27 @@ export function useState(val)
|
|
|
82
82
|
* @param {Array<any>} deps - Dependency list.
|
|
83
83
|
* @returns {Function} Memoized callback.
|
|
84
84
|
*/
|
|
85
|
-
export function useCallback(callback, deps=
|
|
85
|
+
export function useCallback(callback, deps=undefined)
|
|
86
86
|
{
|
|
87
|
+
if( deps!==undefined && (typeof(deps)!=='object' || deps.constructor.name!=='Array') ) {
|
|
88
|
+
throw "callback dependencies must be an array or omitted.";
|
|
89
|
+
}
|
|
90
|
+
|
|
87
91
|
const hk = Lilact.useHook();
|
|
88
92
|
|
|
89
93
|
if( Lilact.isEmpty(hk) ) {
|
|
90
94
|
hk.callback = callback;
|
|
91
|
-
hk.deps = deps;
|
|
92
95
|
}
|
|
93
96
|
else {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
hk.callback = callback;
|
|
97
|
+
if(deps!==undefined && hk?.deps!==undefined && Lilact.shallowEqual(deps, hk.deps)) return hk.callback;
|
|
98
|
+
}
|
|
97
99
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
}
|
|
100
|
+
if(hk?.cleanup) {
|
|
101
|
+
hk.cleanup();
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
hk.deps = deps;
|
|
105
|
+
|
|
104
106
|
return hk.callback;
|
|
105
107
|
}
|
|
106
108
|
|
|
@@ -205,7 +207,7 @@ export function useTransition()
|
|
|
205
207
|
* @param {any} initialValue - Initial value used if nothing exists in localStorage.
|
|
206
208
|
* @returns {any} Stored state/result.
|
|
207
209
|
*/
|
|
208
|
-
export function useLocalStorage(key,
|
|
210
|
+
export function useLocalStorage(key, initialValue)
|
|
209
211
|
{
|
|
210
212
|
|
|
211
213
|
const hk = Lilact.useHook();
|
|
@@ -218,8 +220,8 @@ export function useLocalStorage(key, default_val)
|
|
|
218
220
|
}
|
|
219
221
|
|
|
220
222
|
if(val===undefined) {
|
|
221
|
-
if(typeof(
|
|
222
|
-
val =
|
|
223
|
+
if(typeof(initialValue)==='function') initialValue = initialValue();
|
|
224
|
+
val = initialValue;
|
|
223
225
|
localStorage[key] = JSON.stringify(val);
|
|
224
226
|
}
|
|
225
227
|
|
|
@@ -249,12 +251,12 @@ export function useLocalStorage(key, default_val)
|
|
|
249
251
|
* @param {any} initialValue - Initial ref value.
|
|
250
252
|
* @returns {Object} Ref object with `.current`.
|
|
251
253
|
*/
|
|
252
|
-
export function useRef(
|
|
254
|
+
export function useRef(initialValue = null)
|
|
253
255
|
{
|
|
254
256
|
const hk = Lilact.useHook();
|
|
255
257
|
|
|
256
258
|
if( Lilact.isEmpty(hk) ) {
|
|
257
|
-
hk.current =
|
|
259
|
+
hk.current = initialValue;
|
|
258
260
|
}
|
|
259
261
|
|
|
260
262
|
return hk;
|
|
@@ -267,25 +269,25 @@ export function useRef(val = null)
|
|
|
267
269
|
* @param {Array<any>} [deps] - Dependency list.
|
|
268
270
|
* @returns {void}
|
|
269
271
|
*/
|
|
270
|
-
export function useLayoutEffect(
|
|
272
|
+
export function useLayoutEffect(effect, deps=undefined)
|
|
271
273
|
{
|
|
272
|
-
if(typeof(deps)!=='object' || deps.constructor.name!=='Array') {
|
|
273
|
-
throw "effect dependencies must be an array or omitted.";
|
|
274
|
+
if( deps!==undefined && (typeof(deps)!=='object' || deps.constructor.name!=='Array') ) {
|
|
275
|
+
throw "layout effect dependencies must be an array or omitted.";
|
|
274
276
|
}
|
|
275
277
|
|
|
276
278
|
const hk = Lilact.useHook();
|
|
277
279
|
|
|
278
280
|
if( !Lilact.isEmpty(hk) ) {
|
|
279
|
-
if(deps.
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
281
|
+
if(deps!==undefined && hk?.deps!==undefined && Lilact.shallowEqual(deps, hk.deps)) return;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if(hk?.cleanup) {
|
|
285
|
+
hk.cleanup();
|
|
283
286
|
}
|
|
284
287
|
|
|
285
288
|
hk.deps = deps;
|
|
286
|
-
Lilact.layout_effects.add( ()=>{ hk.cleanup =
|
|
289
|
+
Lilact.layout_effects.add( ()=>{ hk.cleanup = effect(); });
|
|
287
290
|
Lilact.current_component[0].component.forceUpdate();
|
|
288
|
-
|
|
289
291
|
}
|
|
290
292
|
|
|
291
293
|
/**
|
|
@@ -295,23 +297,24 @@ export function useLayoutEffect(setup, deps=[{}])
|
|
|
295
297
|
* @param {Array<any>} [deps] - Dependency list.
|
|
296
298
|
* @returns {void}
|
|
297
299
|
*/
|
|
298
|
-
export function useEffect(
|
|
300
|
+
export function useEffect(effect, deps=undefined)
|
|
299
301
|
{
|
|
300
|
-
if(typeof(deps)!=='object' || deps.constructor.name!=='Array') {
|
|
302
|
+
if( deps!==undefined && (typeof(deps)!=='object' || deps.constructor.name!=='Array') ) {
|
|
301
303
|
throw "effect dependencies must be an array or omitted.";
|
|
302
304
|
}
|
|
303
305
|
|
|
304
306
|
const hk = Lilact.useHook();
|
|
305
307
|
|
|
306
308
|
if( !Lilact.isEmpty(hk) ) {
|
|
307
|
-
if(deps.
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
309
|
+
if(deps!==undefined && hk?.deps!==undefined && Lilact.shallowEqual(deps, hk.deps)) return;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if(hk?.cleanup) {
|
|
313
|
+
hk.cleanup();
|
|
311
314
|
}
|
|
312
315
|
|
|
313
316
|
hk.deps = deps;
|
|
314
|
-
Lilact.setTimeout( ()=>{ hk.cleanup =
|
|
317
|
+
Lilact.setTimeout( ()=>{ hk.cleanup = effect(); }, 0 );
|
|
315
318
|
|
|
316
319
|
}
|
|
317
320
|
|
|
@@ -322,24 +325,21 @@ export function useEffect(setup, deps=[{}])
|
|
|
322
325
|
* @param {Array<any>} deps - Dependency list.
|
|
323
326
|
* @returns {any} Memoized value.
|
|
324
327
|
*/
|
|
325
|
-
export function useMemo(
|
|
328
|
+
export function useMemo(factory,deps=undefined)
|
|
326
329
|
{
|
|
330
|
+
if( deps!==undefined && (typeof(deps)!=='object' || deps.constructor.name!=='Array') ) {
|
|
331
|
+
throw "memo dependencies must be an array or omitted.";
|
|
332
|
+
}
|
|
333
|
+
|
|
327
334
|
const hk = Lilact.useHook();
|
|
328
335
|
|
|
329
|
-
if( Lilact.isEmpty(hk) ) {
|
|
330
|
-
hk.deps
|
|
331
|
-
hk.value = fn();
|
|
332
|
-
}
|
|
333
|
-
else {
|
|
334
|
-
for(let d in deps) {
|
|
335
|
-
if( !Lilact.defaultIsEqual(deps[d],hk.deps[d]) ) {
|
|
336
|
-
hk.deps = deps;
|
|
337
|
-
hk.value = fn(hk.value);
|
|
338
|
-
break;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
336
|
+
if( !Lilact.isEmpty(hk) ) {
|
|
337
|
+
if(deps!==undefined && hk?.deps!==undefined && Lilact.shallowEqual(deps, hk.deps)) return hk.value;
|
|
341
338
|
}
|
|
342
339
|
|
|
340
|
+
hk.deps = deps;
|
|
341
|
+
hk.value = factory(hk.value);
|
|
342
|
+
|
|
343
343
|
return hk.value;
|
|
344
344
|
}
|
|
345
345
|
|
|
@@ -350,14 +350,14 @@ export function useMemo(fn,deps=[])
|
|
|
350
350
|
* @param {any} initialState - Initial state for the hook.
|
|
351
351
|
* @returns {any} Hook result
|
|
352
352
|
*/
|
|
353
|
-
export function useActionState(fn,
|
|
353
|
+
export function useActionState(fn, initialState)
|
|
354
354
|
{
|
|
355
355
|
const hk = Lilact.useHook();
|
|
356
356
|
const [is_pending, tran_start_func] = Lilact.useTransition();
|
|
357
357
|
|
|
358
358
|
if( Lilact.isEmpty(hk) ) {
|
|
359
359
|
|
|
360
|
-
hk.state =
|
|
360
|
+
hk.state = initialState;
|
|
361
361
|
|
|
362
362
|
hk.form_action = (sub)=>{
|
|
363
363
|
event.preventDefault();
|
|
@@ -486,17 +486,17 @@ export function forwardRef(render)
|
|
|
486
486
|
* Dependency list that controls when the exposed value is recalculated.
|
|
487
487
|
* @returns {void}
|
|
488
488
|
*/
|
|
489
|
-
export function useImperativeHandle(ref, factory, deps)
|
|
489
|
+
export function useImperativeHandle(ref, factory, deps=undefined)
|
|
490
490
|
{
|
|
491
|
+
if(deps!==undefined && ref?.deps!==undefined && Lilact.shallowEqual(deps, ref.deps)) return;
|
|
492
|
+
|
|
493
|
+
ref.deps = deps;
|
|
494
|
+
|
|
491
495
|
Lilact.setTimeout( ()=>{
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
}
|
|
498
|
-
Object.assign( ref.current, factory(), 0 );
|
|
499
|
-
}
|
|
500
|
-
});
|
|
496
|
+
if(typeof ref?.current !== 'object') {
|
|
497
|
+
ref.current = {};
|
|
498
|
+
}
|
|
499
|
+
Object.assign( ref.current, factory(), 0 );
|
|
500
|
+
}, 0);
|
|
501
501
|
}
|
|
502
502
|
|
package/src/misc.jsx
CHANGED
|
@@ -414,6 +414,18 @@ export let events_set = new Set([
|
|
|
414
414
|
"onabort","oncanplay","oncanplaythrough","oncuechange","ondurationchange","onemptied","onended","onerror",
|
|
415
415
|
"onloadeddata","onloadedmetadata","onloadstart","onpause","onplay","onplaying","onprogress","onratechange",
|
|
416
416
|
"onseeked","onseeking","onstalled","onsuspend","ontimeupdate","onvolumechange","onwaiting",
|
|
417
|
-
"ontoggle"
|
|
417
|
+
"ontoggle",
|
|
418
|
+
|
|
419
|
+
"onpointerdown", "onpointerup", "onpointermove", "onpointercancel", "onpointerover", "onpointerout",
|
|
420
|
+
"onpointerenter", "onpointerleave"
|
|
421
|
+
])
|
|
422
|
+
/** @ignore */
|
|
423
|
+
export let length_css_attributes_set = new Set([
|
|
424
|
+
"width","height","minWidth","minHeight","maxWidth","maxHeight","top","right","bottom","left","margin",
|
|
425
|
+
"marginTop","marginRight","marginBottom","marginLeft","padding","paddingTop","paddingRight","paddingBottom",
|
|
426
|
+
"paddingLeft","borderWidth","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth",
|
|
427
|
+
"outlineWidth","fontSize","lineHeight","letterSpacing","wordSpacing","textIndent","borderRadius",
|
|
428
|
+
"borderTopLeftRadius","borderTopRightRadius","borderBottomLeftRadius","borderBottomRightRadius",
|
|
429
|
+
"columnGap","rowGap","gap"
|
|
418
430
|
])
|
|
419
431
|
|