lilact 0.26.16 → 0.27.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.
- package/dist/lilact.development.js +250 -348
- package/dist/lilact.development.js.map +3 -3
- package/dist/lilact.development.min.js +34 -34
- package/dist/lilact.development.min.js.map +3 -3
- package/dist/lilact.production.min.js +34 -34
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/accessories.ErrorBoundary.html +8 -8
- package/docs/classes/accessories.Suspense.html +7 -7
- package/docs/classes/components.Component.html +11 -11
- package/docs/classes/components.HTMLComponent.html +11 -11
- package/docs/classes/components.RootComponent.html +11 -11
- 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/errors.globalErrorHandler.html +1 -2
- package/docs/functions/errors.scanBlockLabels.html +1 -2
- package/docs/functions/errors.traceError.html +1 -3
- package/docs/functions/hooks.createContext.html +1 -1
- package/docs/functions/hooks.startTransition.html +1 -1
- package/docs/functions/hooks.useActionState.html +1 -1
- package/docs/functions/hooks.useContext.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/run.lazy.html +1 -2
- package/docs/functions/run.require.html +1 -2
- package/docs/functions/run.run.html +1 -2
- package/docs/functions/run.runScripts.html +1 -1
- package/docs/functions/timers.timeoutPromise.html +3 -3
- package/docs/modules/errors.html +1 -1
- package/docs/modules/run.html +1 -1
- package/docs/static/index.html +1 -1
- package/docs/static/lilact.development.js +250 -348
- package/docs/static/lilact.development.js.map +3 -3
- package/docs/static/lilact.development.min.js +34 -34
- package/docs/static/lilact.development.min.js.map +3 -3
- package/docs/static/lilact.production.min.js +34 -34
- package/docs/variables/components.cloneElement.html +1 -1
- package/docs/variables/errors.blocks_info.html +1 -1
- package/docs/variables/errors.error.html +1 -1
- package/docs/variables/run.required_scripts.html +1 -0
- package/examples/index.html +1 -1
- package/examples/lilact.development.js +250 -348
- package/examples/lilact.development.js.map +3 -3
- package/examples/lilact.development.min.js +34 -34
- package/examples/lilact.development.min.js.map +3 -3
- package/examples/lilact.production.min.js +34 -34
- package/package.json +1 -1
- package/src/components.jsx +10 -4
- package/src/errors.jsx +179 -364
- package/src/expscan.js +1 -1
- package/src/hooks.jsx +33 -10
- package/src/jsx.js +14 -14
- package/src/lilact.jsx +5 -3
- package/src/run.jsx +121 -159
- package/docs/functions/errors.mapLocation.html +0 -1
package/src/hooks.jsx
CHANGED
|
@@ -87,8 +87,12 @@ export function useState(initialValue)
|
|
|
87
87
|
*/
|
|
88
88
|
export function useCallback(callback, deps=undefined)
|
|
89
89
|
{
|
|
90
|
-
if(
|
|
91
|
-
|
|
90
|
+
if(
|
|
91
|
+
deps !== undefined && !Array.isArray(deps) &&
|
|
92
|
+
deps !== null && typeof deps !== "object"
|
|
93
|
+
)
|
|
94
|
+
{
|
|
95
|
+
throw new Error("Callback dependencies must be an array, object or omitted.");
|
|
92
96
|
}
|
|
93
97
|
|
|
94
98
|
const hk = useHook();
|
|
@@ -275,7 +279,11 @@ export function useRef(initialValue = null)
|
|
|
275
279
|
*/
|
|
276
280
|
export async function useLayoutEffect(effect, deps=undefined)
|
|
277
281
|
{
|
|
278
|
-
if(
|
|
282
|
+
if(
|
|
283
|
+
deps !== undefined && !Array.isArray(deps) &&
|
|
284
|
+
deps !== null && typeof deps !== "object"
|
|
285
|
+
)
|
|
286
|
+
{
|
|
279
287
|
throw new Error("Layout effect dependencies must be an array, object or omitted.");
|
|
280
288
|
}
|
|
281
289
|
|
|
@@ -287,7 +295,8 @@ export async function useLayoutEffect(effect, deps=undefined)
|
|
|
287
295
|
|
|
288
296
|
if(hk?.cleanup) {
|
|
289
297
|
await hk.cleanup();
|
|
290
|
-
|
|
298
|
+
hk.cleanup = undefined;
|
|
299
|
+
}
|
|
291
300
|
|
|
292
301
|
hk.deps = deps;
|
|
293
302
|
Lilact.layout_effects.add( async ()=>{ hk.cleanup = await effect(); });
|
|
@@ -306,7 +315,11 @@ export async function useLayoutEffect(effect, deps=undefined)
|
|
|
306
315
|
*/
|
|
307
316
|
export async function useEffect(effect, deps=undefined)
|
|
308
317
|
{
|
|
309
|
-
if(
|
|
318
|
+
if(
|
|
319
|
+
deps !== undefined && !Array.isArray(deps) &&
|
|
320
|
+
deps !== null && typeof deps !== "object"
|
|
321
|
+
)
|
|
322
|
+
{
|
|
310
323
|
throw new Error("Effect dependencies must be an array, object or omitted.");
|
|
311
324
|
}
|
|
312
325
|
|
|
@@ -318,6 +331,7 @@ export async function useEffect(effect, deps=undefined)
|
|
|
318
331
|
|
|
319
332
|
if(hk?.cleanup) {
|
|
320
333
|
await hk.cleanup();
|
|
334
|
+
hk.cleanup = undefined;
|
|
321
335
|
}
|
|
322
336
|
|
|
323
337
|
hk.deps = deps;
|
|
@@ -338,7 +352,11 @@ export async function useEffect(effect, deps=undefined)
|
|
|
338
352
|
*/
|
|
339
353
|
export async function useInsertionEffect(effect, deps=undefined)
|
|
340
354
|
{
|
|
341
|
-
if(
|
|
355
|
+
if(
|
|
356
|
+
deps !== undefined && !Array.isArray(deps) &&
|
|
357
|
+
deps !== null && typeof deps !== "object"
|
|
358
|
+
)
|
|
359
|
+
{
|
|
342
360
|
throw new Error("Insertion effect dependencies must be an array, object, or omitted.");
|
|
343
361
|
}
|
|
344
362
|
|
|
@@ -350,6 +368,7 @@ export async function useInsertionEffect(effect, deps=undefined)
|
|
|
350
368
|
|
|
351
369
|
if(hk?.cleanup) {
|
|
352
370
|
await hk.cleanup();
|
|
371
|
+
hk.cleanup = undefined;
|
|
353
372
|
}
|
|
354
373
|
|
|
355
374
|
hk.deps = deps;
|
|
@@ -370,7 +389,11 @@ export async function useInsertionEffect(effect, deps=undefined)
|
|
|
370
389
|
*/
|
|
371
390
|
export function useMemo(factory,deps=undefined)
|
|
372
391
|
{
|
|
373
|
-
if(
|
|
392
|
+
if(
|
|
393
|
+
deps !== undefined && !Array.isArray(deps) &&
|
|
394
|
+
deps !== null && typeof deps !== "object"
|
|
395
|
+
)
|
|
396
|
+
{
|
|
374
397
|
throw new Error("Memo dependencies must be an array or omitted.");
|
|
375
398
|
}
|
|
376
399
|
|
|
@@ -404,12 +427,12 @@ export function useActionState(action, initialState)
|
|
|
404
427
|
|
|
405
428
|
hk.state = initialState;
|
|
406
429
|
|
|
407
|
-
hk.form_action = (
|
|
430
|
+
hk.form_action = (event)=>{
|
|
408
431
|
event.preventDefault();
|
|
409
432
|
|
|
410
433
|
tran_start_func(
|
|
411
434
|
async ()=> {
|
|
412
|
-
const form_data = new FormData(
|
|
435
|
+
const form_data = new FormData(event.target, event.submitter);
|
|
413
436
|
hk.state = await action(hk.state, form_data);
|
|
414
437
|
},
|
|
415
438
|
[]
|
|
@@ -523,7 +546,7 @@ export function useImperativeHandle(ref, factory, deps=undefined)
|
|
|
523
546
|
if(typeof ref?.current !== 'object') {
|
|
524
547
|
ref.current = {};
|
|
525
548
|
}
|
|
526
|
-
Object.assign( ref.current, factory()
|
|
549
|
+
Object.assign( ref.current, factory());
|
|
527
550
|
|
|
528
551
|
}
|
|
529
552
|
|
package/src/jsx.js
CHANGED
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
// to report any bugs, and please include a testable example. Thanks! :)
|
|
45
45
|
|
|
46
46
|
// note: JSX or preprocessors are not processed inside template strings
|
|
47
|
-
// todo: injected string try
|
|
47
|
+
// todo: injected string try/catches should be generated by a function
|
|
48
48
|
|
|
49
49
|
/** @ignore */
|
|
50
50
|
export const transpilerConfig = {
|
|
@@ -88,7 +88,7 @@ function parseRegex(code, index, container)
|
|
|
88
88
|
|
|
89
89
|
let i = index;
|
|
90
90
|
let dels = `;=,([{}!^~&|:?*%-+/<>${transpilerConfig.preprocessorDelimiter}`;
|
|
91
|
-
while(--i
|
|
91
|
+
while(--i>=0) {
|
|
92
92
|
if( ' \t\r'.indexOf(code[i])!==-1 ) continue;
|
|
93
93
|
if(code[i]==='\n' ) {
|
|
94
94
|
dels+=")]";
|
|
@@ -615,10 +615,10 @@ function parseXML(code, index, container, look_behind=false)
|
|
|
615
615
|
}
|
|
616
616
|
|
|
617
617
|
|
|
618
|
-
function
|
|
618
|
+
function parseParenthesis(code, index, container)
|
|
619
619
|
{
|
|
620
620
|
const b = { // block
|
|
621
|
-
type: "
|
|
621
|
+
type: "parenthesis",
|
|
622
622
|
begin: index,
|
|
623
623
|
cbegin: ++index,
|
|
624
624
|
children: [],
|
|
@@ -647,7 +647,7 @@ function parseParanthesis(code, index, container)
|
|
|
647
647
|
break;
|
|
648
648
|
|
|
649
649
|
case '(':
|
|
650
|
-
[index] = lookAhead(
|
|
650
|
+
[index] = lookAhead( parseParenthesis, code, index, b );
|
|
651
651
|
break;
|
|
652
652
|
|
|
653
653
|
case '}':
|
|
@@ -674,7 +674,7 @@ function parseParanthesis(code, index, container)
|
|
|
674
674
|
}
|
|
675
675
|
}
|
|
676
676
|
|
|
677
|
-
raiseError(`Unterminated
|
|
677
|
+
raiseError(`Unterminated parenthesis block`, b.begin);
|
|
678
678
|
}
|
|
679
679
|
|
|
680
680
|
|
|
@@ -713,11 +713,11 @@ function parseJS(code, index=0, is_block=false, container)
|
|
|
713
713
|
}
|
|
714
714
|
|
|
715
715
|
case '(': // this is only for function detection
|
|
716
|
-
[index] = lookAhead(
|
|
716
|
+
[index] = lookAhead( parseParenthesis, code, index, b );
|
|
717
717
|
break;
|
|
718
718
|
|
|
719
719
|
case ')': // this is only for function detection
|
|
720
|
-
raiseError(`Unmatched
|
|
720
|
+
raiseError(`Unmatched parenthesis`, b.begin);
|
|
721
721
|
break;
|
|
722
722
|
|
|
723
723
|
case '}':
|
|
@@ -790,7 +790,7 @@ function labelFunctions(node, eols, blocks_info)
|
|
|
790
790
|
let i, nxt, prev;
|
|
791
791
|
for(let chi=0; chi<node.children.length; chi++) {
|
|
792
792
|
|
|
793
|
-
if(typeof(node.children[chi])==='object' && node.children[chi].type==='
|
|
793
|
+
if(typeof(node.children[chi])==='object' && node.children[chi].type==='parenthesis') {
|
|
794
794
|
|
|
795
795
|
[i, prev] = getNext(chi, -1);
|
|
796
796
|
if(prev===null) continue;
|
|
@@ -808,7 +808,7 @@ function labelFunctions(node, eols, blocks_info)
|
|
|
808
808
|
if(nxt===null) continue;
|
|
809
809
|
|
|
810
810
|
if(transpilerConfig.injectTraceLabels && typeof(nxt)==='object' && nxt.type==='js') {
|
|
811
|
-
const begin = getRowCol(eols, chi); // begin is always the location of function args
|
|
811
|
+
const begin = getRowCol(eols, chi); // begin is always the location of function args parenthesis
|
|
812
812
|
nxt.children.splice(1,0, `/*LILACTBLOCK${++blocks_info.counter}:${begin}:${label}*/try{`);
|
|
813
813
|
if(transpilerConfig.enableLabelStack) {
|
|
814
814
|
nxt.children.splice(nxt.children.length-1, 0, `} catch(e){ if(typeof(e)!=='object') e=new Error(e);e.lilact_trace=[${blocks_info.counter},e.lilact_trace];throw e}`);
|
|
@@ -823,9 +823,9 @@ function labelFunctions(node, eols, blocks_info)
|
|
|
823
823
|
else if(node.children[chi]==='=>') {
|
|
824
824
|
[i, prev] = getNext(chi, -1);
|
|
825
825
|
|
|
826
|
-
if(typeof(prev)==='object' && prev.type==='
|
|
826
|
+
if(typeof(prev)==='object' && prev.type==='parenthesis') {
|
|
827
827
|
|
|
828
|
-
const begin = getRowCol(eols, prev.begin); // begin is always the location of function args
|
|
828
|
+
const begin = getRowCol(eols, prev.begin); // begin is always the location of function args parenthesis
|
|
829
829
|
|
|
830
830
|
[i, nxt] = getNext(chi);
|
|
831
831
|
|
|
@@ -958,7 +958,7 @@ function generateSourceMap(json, path, jsx_eols, out_eols, mappings=[])
|
|
|
958
958
|
/**
|
|
959
959
|
* This is the function that transpiles jsx code to js. It is not recommended to use directly.
|
|
960
960
|
*
|
|
961
|
-
* Use `Lilact.require` instead, or `Lilact.run` available in `run`, or add a `<
|
|
961
|
+
* Use `Lilact.require` instead, or `Lilact.run` available in `run`, or add a `<script type="text/jsx" .../>` to your html.
|
|
962
962
|
*
|
|
963
963
|
* Lilact jsx parser doesn't rely on the Lilact itself, and can be used by other engines. The easiest way
|
|
964
964
|
* is using the `bin/transpile.js` script. It has its own help.
|
|
@@ -1090,7 +1090,7 @@ export function transpileJSX( jsx, {
|
|
|
1090
1090
|
if(node.type==='directive') return node.value;
|
|
1091
1091
|
|
|
1092
1092
|
|
|
1093
|
-
if(node.type==='
|
|
1093
|
+
if(node.type==='parenthesis') {
|
|
1094
1094
|
let out = "(";
|
|
1095
1095
|
|
|
1096
1096
|
if(node.out) {
|
package/src/lilact.jsx
CHANGED
|
@@ -94,7 +94,7 @@ export {transpileJSX, transpilerConfig} from "./jsx";
|
|
|
94
94
|
export const Lilact =
|
|
95
95
|
{
|
|
96
96
|
|
|
97
|
-
VERSION: "RC.
|
|
97
|
+
VERSION: "RC.4",
|
|
98
98
|
|
|
99
99
|
// Configuration
|
|
100
100
|
|
|
@@ -143,8 +143,10 @@ globalThis.createComponent = Lilact.createComponent;
|
|
|
143
143
|
globalThis.Fragment = Lilact.Fragment;
|
|
144
144
|
globalThis.require = Lilact.require;
|
|
145
145
|
|
|
146
|
-
document.addEventListener(
|
|
147
|
-
Lilact.runScripts()
|
|
146
|
+
document.addEventListener("DOMContentLoaded", () => {
|
|
147
|
+
Lilact.runScripts().catch(error => {
|
|
148
|
+
Lilact.globalErrorHandler?.(error);
|
|
149
|
+
});
|
|
148
150
|
});
|
|
149
151
|
|
|
150
152
|
if(DEBUG) {
|