@coherent.js/core 1.0.0-beta.2 → 1.0.0-beta.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.
- package/dist/coherent.d.ts +10 -150
- package/dist/coherent.d.ts.map +1 -1
- package/dist/coherent.js +33 -166
- package/dist/coherent.js.map +1 -1
- package/dist/components/component-system.js +109 -109
- package/dist/core/html-utils.js +5 -5
- package/dist/core/object-factory.js +21 -21
- package/dist/core/object-utils.js +2 -2
- package/dist/database/adapters/mongodb.d.ts +15 -0
- package/dist/database/adapters/mongodb.d.ts.map +1 -0
- package/dist/database/adapters/mongodb.js +216 -0
- package/dist/database/adapters/mongodb.js.map +1 -0
- package/dist/database/adapters/mysql.d.ts +12 -0
- package/dist/database/adapters/mysql.d.ts.map +1 -0
- package/dist/database/adapters/mysql.js +171 -0
- package/dist/database/adapters/mysql.js.map +1 -0
- package/dist/database/adapters/postgresql.d.ts +12 -0
- package/dist/database/adapters/postgresql.d.ts.map +1 -0
- package/dist/database/adapters/postgresql.js +177 -0
- package/dist/database/adapters/postgresql.js.map +1 -0
- package/dist/database/adapters/sqlite.d.ts +15 -0
- package/dist/database/adapters/sqlite.d.ts.map +1 -0
- package/dist/database/adapters/sqlite.js +241 -0
- package/dist/database/adapters/sqlite.js.map +1 -0
- package/dist/database/connection-manager.d.ts +135 -0
- package/dist/database/connection-manager.d.ts.map +1 -0
- package/dist/database/connection-manager.js +362 -0
- package/dist/database/connection-manager.js.map +1 -0
- package/dist/database/index.d.ts +38 -0
- package/dist/database/index.d.ts.map +1 -0
- package/dist/database/index.js +60 -0
- package/dist/database/index.js.map +1 -0
- package/dist/database/middleware.d.ts +122 -0
- package/dist/database/middleware.d.ts.map +1 -0
- package/dist/database/middleware.js +390 -0
- package/dist/database/middleware.js.map +1 -0
- package/dist/database/migration.d.ts +62 -0
- package/dist/database/migration.d.ts.map +1 -0
- package/dist/database/migration.js +423 -0
- package/dist/database/migration.js.map +1 -0
- package/dist/database/model.d.ts +8 -0
- package/dist/database/model.d.ts.map +1 -0
- package/dist/database/model.js +167 -0
- package/dist/database/model.js.map +1 -0
- package/dist/database/query-builder.d.ts +111 -0
- package/dist/database/query-builder.d.ts.map +1 -0
- package/dist/database/query-builder.js +187 -0
- package/dist/database/query-builder.js.map +1 -0
- package/dist/database/utils.d.ts +196 -0
- package/dist/database/utils.d.ts.map +1 -0
- package/dist/database/utils.js +372 -0
- package/dist/database/utils.js.map +1 -0
- package/dist/dev/dev-tools.d.ts +1 -1
- package/dist/dev/dev-tools.js +28 -28
- package/dist/performance/bundle-optimizer.js +11 -11
- package/dist/performance/cache-manager.js +6 -6
- package/dist/performance/monitor.js +10 -10
- package/dist/performance/monitor.js.map +1 -1
- package/dist/rendering/base-renderer.js +13 -13
- package/dist/rendering/dom-renderer.d.ts +0 -23
- package/dist/rendering/dom-renderer.d.ts.map +1 -1
- package/dist/rendering/dom-renderer.js +9 -77
- package/dist/rendering/dom-renderer.js.map +1 -1
- package/dist/rendering/html-renderer.d.ts +0 -15
- package/dist/rendering/html-renderer.d.ts.map +1 -1
- package/dist/rendering/html-renderer.js +4 -85
- package/dist/rendering/html-renderer.js.map +1 -1
- package/dist/rendering/streaming-renderer.js +12 -12
- package/dist/utils/dependency-utils.js +2 -2
- package/dist/utils/normalization.js +1 -1
- package/dist/utils/validation.js +1 -1
- package/package.json +1 -1
- package/dist/components/lifecycle.d.ts +0 -212
- package/dist/components/lifecycle.d.ts.map +0 -1
- package/dist/components/lifecycle.js +0 -525
- package/dist/components/lifecycle.js.map +0 -1
- package/dist/forms/validation.d.ts +0 -271
- package/dist/forms/validation.d.ts.map +0 -1
- package/dist/forms/validation.js +0 -573
- package/dist/forms/validation.js.map +0 -1
- package/dist/performance/component-cache.d.ts +0 -120
- package/dist/performance/component-cache.d.ts.map +0 -1
- package/dist/performance/component-cache.js +0 -364
- package/dist/performance/component-cache.js.map +0 -1
- package/dist/rendering/css-manager.d.ts +0 -73
- package/dist/rendering/css-manager.d.ts.map +0 -1
- package/dist/rendering/css-manager.js +0 -176
- package/dist/rendering/css-manager.js.map +0 -1
- package/dist/rendering/vdom-diff.d.ts +0 -47
- package/dist/rendering/vdom-diff.d.ts.map +0 -1
- package/dist/rendering/vdom-diff.js +0 -416
- package/dist/rendering/vdom-diff.js.map +0 -1
- package/dist/routing/router.d.ts +0 -241
- package/dist/routing/router.d.ts.map +0 -1
- package/dist/routing/router.js +0 -648
- package/dist/routing/router.js.map +0 -1
- package/dist/state/reactive-state.d.ts +0 -166
- package/dist/state/reactive-state.d.ts.map +0 -1
- package/dist/state/reactive-state.js +0 -546
- package/dist/state/reactive-state.js.map +0 -1
- package/dist/utils/error-handler.d.ts +0 -148
- package/dist/utils/error-handler.d.ts.map +0 -1
- package/dist/utils/error-handler.js +0 -468
- package/dist/utils/error-handler.js.map +0 -1
|
@@ -85,8 +85,8 @@ class ComponentState {
|
|
|
85
85
|
try {
|
|
86
86
|
listener(newState, oldState);
|
|
87
87
|
}
|
|
88
|
-
catch (
|
|
89
|
-
console.
|
|
88
|
+
catch (_error) {
|
|
89
|
+
console._error('State listener _error:', _error);
|
|
90
90
|
}
|
|
91
91
|
});
|
|
92
92
|
this.isUpdating = false;
|
|
@@ -215,20 +215,20 @@ export class Component {
|
|
|
215
215
|
return this.hooks[hookName].call(this, ...args);
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
|
-
catch (
|
|
219
|
-
this.handleError(
|
|
218
|
+
catch (_error) {
|
|
219
|
+
this.handleError(_error, `${hookName} hook`);
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
222
|
/**
|
|
223
223
|
* Handle component errors
|
|
224
224
|
*/
|
|
225
|
-
handleError(
|
|
226
|
-
console.
|
|
227
|
-
// Call
|
|
228
|
-
this.callHook('errorCaptured',
|
|
225
|
+
handleError(_error) {
|
|
226
|
+
console._error(`Component Error in ${this.name}:`, _error);
|
|
227
|
+
// Call _error hook
|
|
228
|
+
this.callHook('errorCaptured', _error);
|
|
229
229
|
// Propagate to parent
|
|
230
230
|
if (this.parent && this.parent.handleError) {
|
|
231
|
-
this.parent.handleError(
|
|
231
|
+
this.parent.handleError(_error, `${this.name} -> ${context}`);
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
234
|
/**
|
|
@@ -263,9 +263,9 @@ export class Component {
|
|
|
263
263
|
}
|
|
264
264
|
return this.rendered;
|
|
265
265
|
}
|
|
266
|
-
catch (
|
|
267
|
-
this.handleError(
|
|
268
|
-
return { div: { className: 'component-
|
|
266
|
+
catch (_error) {
|
|
267
|
+
this.handleError(_error);
|
|
268
|
+
return { div: { className: 'component-_error', text: `Error in ${this.name}` } };
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
271
|
/**
|
|
@@ -384,9 +384,9 @@ export function createComponent(definition) {
|
|
|
384
384
|
* Create a component factory
|
|
385
385
|
*/
|
|
386
386
|
export function defineComponent(definition) {
|
|
387
|
-
const componentFactory = (
|
|
387
|
+
const componentFactory = (props) => {
|
|
388
388
|
const component = new Component(definition);
|
|
389
|
-
return component.render(
|
|
389
|
+
return component.render(props);
|
|
390
390
|
};
|
|
391
391
|
// Add static properties
|
|
392
392
|
componentFactory.componentName = definition.name || 'Component';
|
|
@@ -425,8 +425,8 @@ export function createHOC(enhancer) {
|
|
|
425
425
|
return (WrappedComponent) => {
|
|
426
426
|
return defineComponent({
|
|
427
427
|
name: `HOC(${WrappedComponent.componentName || 'Component'})`,
|
|
428
|
-
render(
|
|
429
|
-
return enhancer(WrappedComponent,
|
|
428
|
+
render(props) {
|
|
429
|
+
return enhancer(WrappedComponent, props);
|
|
430
430
|
}
|
|
431
431
|
});
|
|
432
432
|
};
|
|
@@ -472,8 +472,8 @@ export const compose = {
|
|
|
472
472
|
combine: (...components) => {
|
|
473
473
|
return defineComponent({
|
|
474
474
|
name: 'ComposedComponent',
|
|
475
|
-
render(
|
|
476
|
-
return components.map(comp => typeof comp === 'function' ? comp(
|
|
475
|
+
render(props) {
|
|
476
|
+
return components.map(comp => typeof comp === 'function' ? comp(props) : comp);
|
|
477
477
|
}
|
|
478
478
|
});
|
|
479
479
|
},
|
|
@@ -483,16 +483,16 @@ export const compose = {
|
|
|
483
483
|
conditional: (condition, trueComponent, falseComponent = null) => {
|
|
484
484
|
return defineComponent({
|
|
485
485
|
name: 'ConditionalComponent',
|
|
486
|
-
render(
|
|
486
|
+
render(props) {
|
|
487
487
|
const shouldRender = typeof condition === 'function' ?
|
|
488
|
-
condition(
|
|
488
|
+
condition(props) : condition;
|
|
489
489
|
if (shouldRender) {
|
|
490
490
|
return typeof trueComponent === 'function' ?
|
|
491
|
-
trueComponent(
|
|
491
|
+
trueComponent(props) : trueComponent;
|
|
492
492
|
}
|
|
493
493
|
else if (falseComponent) {
|
|
494
494
|
return typeof falseComponent === 'function' ?
|
|
495
|
-
falseComponent(
|
|
495
|
+
falseComponent(props) : falseComponent;
|
|
496
496
|
}
|
|
497
497
|
return null;
|
|
498
498
|
}
|
|
@@ -504,8 +504,8 @@ export const compose = {
|
|
|
504
504
|
loop: (data, itemComponent, keyFn = (item, index) => index) => {
|
|
505
505
|
return defineComponent({
|
|
506
506
|
name: 'LoopComponent',
|
|
507
|
-
render(
|
|
508
|
-
const items = typeof data === 'function' ? data(
|
|
507
|
+
render(props) {
|
|
508
|
+
const items = typeof data === 'function' ? data(props) : data;
|
|
509
509
|
if (!Array.isArray(items)) {
|
|
510
510
|
console.warn('Loop component expects array data');
|
|
511
511
|
return null;
|
|
@@ -692,9 +692,9 @@ export function lazy(factory, options = {}) {
|
|
|
692
692
|
}
|
|
693
693
|
// Handle promises
|
|
694
694
|
if (result && typeof result.then === 'function') {
|
|
695
|
-
return result.catch(
|
|
695
|
+
return result.catch(_error => {
|
|
696
696
|
if (onError)
|
|
697
|
-
onError(
|
|
697
|
+
onError(_error);
|
|
698
698
|
return fallback;
|
|
699
699
|
});
|
|
700
700
|
}
|
|
@@ -705,12 +705,12 @@ export function lazy(factory, options = {}) {
|
|
|
705
705
|
}
|
|
706
706
|
return result;
|
|
707
707
|
}
|
|
708
|
-
catch (
|
|
708
|
+
catch (_error) {
|
|
709
709
|
if (onError) {
|
|
710
|
-
onError(
|
|
710
|
+
onError(_error);
|
|
711
711
|
}
|
|
712
712
|
else {
|
|
713
|
-
console.
|
|
713
|
+
console._error('Lazy evaluation _error:', _error);
|
|
714
714
|
}
|
|
715
715
|
return fallback;
|
|
716
716
|
}
|
|
@@ -831,7 +831,7 @@ export function batchEvaluate(lazyValues, ...args) {
|
|
|
831
831
|
const result = lazyValue.evaluate(...args);
|
|
832
832
|
if (result && typeof result.then === 'function') {
|
|
833
833
|
promises.push(result.then(value => ({ key, value }))
|
|
834
|
-
.catch(
|
|
834
|
+
.catch(_error => ({ key, _error })));
|
|
835
835
|
}
|
|
836
836
|
else {
|
|
837
837
|
results[key] = result;
|
|
@@ -845,9 +845,9 @@ export function batchEvaluate(lazyValues, ...args) {
|
|
|
845
845
|
return results;
|
|
846
846
|
}
|
|
847
847
|
return Promise.all(promises).then(asyncResults => {
|
|
848
|
-
asyncResults.forEach(({ key, value,
|
|
849
|
-
if (
|
|
850
|
-
console.
|
|
848
|
+
asyncResults.forEach(({ key, value, _error }) => {
|
|
849
|
+
if (_error) {
|
|
850
|
+
console._error(`Batch evaluation _error for ${key}:`, _error);
|
|
851
851
|
results[key] = null;
|
|
852
852
|
}
|
|
853
853
|
else {
|
|
@@ -884,9 +884,9 @@ function evaluateWithTimeout(factory, timeout, args, fallback) {
|
|
|
884
884
|
clearTimeout(timer);
|
|
885
885
|
resolve(value);
|
|
886
886
|
})
|
|
887
|
-
.catch(
|
|
887
|
+
.catch(_error => {
|
|
888
888
|
clearTimeout(timer);
|
|
889
|
-
reject(
|
|
889
|
+
reject(_error);
|
|
890
890
|
});
|
|
891
891
|
}
|
|
892
892
|
else {
|
|
@@ -894,9 +894,9 @@ function evaluateWithTimeout(factory, timeout, args, fallback) {
|
|
|
894
894
|
resolve(result);
|
|
895
895
|
}
|
|
896
896
|
}
|
|
897
|
-
catch (
|
|
897
|
+
catch (_error) {
|
|
898
898
|
clearTimeout(timer);
|
|
899
|
-
reject(
|
|
899
|
+
reject(_error);
|
|
900
900
|
}
|
|
901
901
|
}).catch(() => fallback);
|
|
902
902
|
}
|
|
@@ -1091,16 +1091,16 @@ export function memoComponent(component, options = {}) {
|
|
|
1091
1091
|
const { propsEqual = shallowEqual, stateEqual = shallowEqual, name = component.name || 'AnonymousComponent' } = options;
|
|
1092
1092
|
return memo((props = {}, state = {}, context = {}) => {
|
|
1093
1093
|
return typeof component === 'function' ?
|
|
1094
|
-
component(props, state,
|
|
1094
|
+
component(props, state, context) :
|
|
1095
1095
|
component;
|
|
1096
1096
|
}, {
|
|
1097
1097
|
keyFn: (props, state) => {
|
|
1098
1098
|
// Create key based on props and state
|
|
1099
|
-
return `${name}:${JSON.stringify(
|
|
1099
|
+
return `${name}:${JSON.stringify(props)}:${JSON.stringify(state)}`;
|
|
1100
1100
|
},
|
|
1101
1101
|
compareFn: (a, b) => {
|
|
1102
1102
|
// Custom comparison for component args
|
|
1103
|
-
return propsEqual(a.props, b.
|
|
1103
|
+
return propsEqual(a.props, b.props) &&
|
|
1104
1104
|
stateEqual(a.state, b.state);
|
|
1105
1105
|
},
|
|
1106
1106
|
...options
|
|
@@ -1120,10 +1120,10 @@ export function memoAsync(asyncFn, options = {}) {
|
|
|
1120
1120
|
return promiseCache.get(key);
|
|
1121
1121
|
}
|
|
1122
1122
|
// Start new async operation
|
|
1123
|
-
const promise = asyncFn(...args).catch(
|
|
1123
|
+
const promise = asyncFn(...args).catch(_error => {
|
|
1124
1124
|
// Remove failed promise from cache
|
|
1125
1125
|
promiseCache.delete(key);
|
|
1126
|
-
throw
|
|
1126
|
+
throw _error;
|
|
1127
1127
|
});
|
|
1128
1128
|
promiseCache.set(key, promise);
|
|
1129
1129
|
// Clean up resolved promise
|
|
@@ -1200,7 +1200,7 @@ class TTLCache {
|
|
|
1200
1200
|
}
|
|
1201
1201
|
get(key) {
|
|
1202
1202
|
if (this.cache.has(key)) {
|
|
1203
|
-
const
|
|
1203
|
+
const entry = this.cache.get(key);
|
|
1204
1204
|
if (Date.now() < entry.expires) {
|
|
1205
1205
|
return entry.value;
|
|
1206
1206
|
}
|
|
@@ -1226,7 +1226,7 @@ class TTLCache {
|
|
|
1226
1226
|
}
|
|
1227
1227
|
has(key) {
|
|
1228
1228
|
if (this.cache.has(key)) {
|
|
1229
|
-
const
|
|
1229
|
+
const entry = this.cache.get(key);
|
|
1230
1230
|
return Date.now() < entry.expires;
|
|
1231
1231
|
}
|
|
1232
1232
|
return false;
|
|
@@ -1234,7 +1234,7 @@ class TTLCache {
|
|
|
1234
1234
|
delete(key) {
|
|
1235
1235
|
const had = this.cache.has(key);
|
|
1236
1236
|
if (had) {
|
|
1237
|
-
const
|
|
1237
|
+
const entry = this.cache.get(key);
|
|
1238
1238
|
this.cache.delete(key);
|
|
1239
1239
|
if (this.timers.has(key)) {
|
|
1240
1240
|
clearTimeout(this.timers.get(key));
|
|
@@ -1367,7 +1367,7 @@ export function withProps(propsTransform, options = {}) {
|
|
|
1367
1367
|
memoOptions = {}, // Memoization options
|
|
1368
1368
|
// Error handling
|
|
1369
1369
|
onError = null, // Error handler for transformation
|
|
1370
|
-
fallbackProps = {}, // Fallback props on
|
|
1370
|
+
fallbackProps = {}, // Fallback props on _error
|
|
1371
1371
|
// Development
|
|
1372
1372
|
displayName = null, // Component name for debugging
|
|
1373
1373
|
debug = false, // Debug logging
|
|
@@ -1382,7 +1382,7 @@ export function withProps(propsTransform, options = {}) {
|
|
|
1382
1382
|
// Transform props
|
|
1383
1383
|
let transformedProps;
|
|
1384
1384
|
if (typeof propsTransform === 'function') {
|
|
1385
|
-
transformedProps = propsTransform(originalProps, state,
|
|
1385
|
+
transformedProps = propsTransform(originalProps, state, context);
|
|
1386
1386
|
}
|
|
1387
1387
|
else if (typeof propsTransform === 'object') {
|
|
1388
1388
|
transformedProps = propsTransform;
|
|
@@ -1393,26 +1393,26 @@ export function withProps(propsTransform, options = {}) {
|
|
|
1393
1393
|
// Handle async transformations
|
|
1394
1394
|
if (transformedProps && typeof transformedProps.then === 'function') {
|
|
1395
1395
|
return transformedProps.then(resolved => {
|
|
1396
|
-
return processProps(resolved, originalProps, WrappedComponent, state,
|
|
1397
|
-
}).catch(
|
|
1396
|
+
return processProps(resolved, originalProps, WrappedComponent, state, context);
|
|
1397
|
+
}).catch(_error => {
|
|
1398
1398
|
if (onError)
|
|
1399
|
-
onError(
|
|
1400
|
-
return processProps(fallbackProps, originalProps, WrappedComponent, state,
|
|
1399
|
+
onError(_error, originalProps);
|
|
1400
|
+
return processProps(fallbackProps, originalProps, WrappedComponent, state, context);
|
|
1401
1401
|
});
|
|
1402
1402
|
}
|
|
1403
|
-
return processProps(transformedProps, originalProps, WrappedComponent, state,
|
|
1403
|
+
return processProps(transformedProps, originalProps, WrappedComponent, state, context);
|
|
1404
1404
|
}
|
|
1405
|
-
catch (
|
|
1405
|
+
catch (_error) {
|
|
1406
1406
|
if (debug)
|
|
1407
|
-
console.
|
|
1407
|
+
console._error('withProps _error:', _error);
|
|
1408
1408
|
if (onError)
|
|
1409
|
-
onError(
|
|
1409
|
+
onError(_error, originalProps);
|
|
1410
1410
|
// Use fallback props
|
|
1411
|
-
return processProps(fallbackProps, originalProps, WrappedComponent, state,
|
|
1411
|
+
return processProps(fallbackProps, originalProps, WrappedComponent, state, context);
|
|
1412
1412
|
}
|
|
1413
1413
|
}
|
|
1414
1414
|
// Process and merge props
|
|
1415
|
-
function processProps(transformed, original, component, state,
|
|
1415
|
+
function processProps(transformed, original, component, state, context) {
|
|
1416
1416
|
let finalProps;
|
|
1417
1417
|
if (merge) {
|
|
1418
1418
|
if (override) {
|
|
@@ -1449,7 +1449,7 @@ export function withProps(propsTransform, options = {}) {
|
|
|
1449
1449
|
}
|
|
1450
1450
|
// Render wrapped component
|
|
1451
1451
|
return typeof component === 'function' ?
|
|
1452
|
-
component(finalProps, state,
|
|
1452
|
+
component(finalProps, state, context) :
|
|
1453
1453
|
component;
|
|
1454
1454
|
}
|
|
1455
1455
|
// Set display name for debugging
|
|
@@ -1480,16 +1480,16 @@ export const withPropsUtils = {
|
|
|
1480
1480
|
/**
|
|
1481
1481
|
* Transform props based on conditions
|
|
1482
1482
|
*/
|
|
1483
|
-
conditional: (condition, trueProps, falseProps = {}) => withProps((props, state,
|
|
1483
|
+
conditional: (condition, trueProps, falseProps = {}) => withProps((props, state, context) => {
|
|
1484
1484
|
const shouldApply = typeof condition === 'function' ?
|
|
1485
|
-
condition(props, state,
|
|
1485
|
+
condition(props, state, context) :
|
|
1486
1486
|
condition;
|
|
1487
1487
|
return shouldApply ? trueProps : falseProps;
|
|
1488
1488
|
}),
|
|
1489
1489
|
/**
|
|
1490
1490
|
* Map specific props to new names/values
|
|
1491
1491
|
*/
|
|
1492
|
-
map: (mapping) => withProps((
|
|
1492
|
+
map: (mapping) => withProps((props) => {
|
|
1493
1493
|
const result = {};
|
|
1494
1494
|
Object.entries(mapping).forEach(([newKey, mapper]) => {
|
|
1495
1495
|
if (typeof mapper === 'string') {
|
|
@@ -1498,7 +1498,7 @@ export const withPropsUtils = {
|
|
|
1498
1498
|
}
|
|
1499
1499
|
else if (typeof mapper === 'function') {
|
|
1500
1500
|
// Transform function
|
|
1501
|
-
result[newKey] = mapper(
|
|
1501
|
+
result[newKey] = mapper(props);
|
|
1502
1502
|
}
|
|
1503
1503
|
else {
|
|
1504
1504
|
// Static value
|
|
@@ -1510,7 +1510,7 @@ export const withPropsUtils = {
|
|
|
1510
1510
|
/**
|
|
1511
1511
|
* Pick only specific props
|
|
1512
1512
|
*/
|
|
1513
|
-
pick: (keys) => withProps((
|
|
1513
|
+
pick: (keys) => withProps((props) => {
|
|
1514
1514
|
const result = {};
|
|
1515
1515
|
keys.forEach(key => {
|
|
1516
1516
|
if (props.hasOwnProperty(key)) {
|
|
@@ -1522,7 +1522,7 @@ export const withPropsUtils = {
|
|
|
1522
1522
|
/**
|
|
1523
1523
|
* Omit specific props
|
|
1524
1524
|
*/
|
|
1525
|
-
omit: (keys) => withProps((
|
|
1525
|
+
omit: (keys) => withProps((props) => {
|
|
1526
1526
|
const result = { ...props };
|
|
1527
1527
|
keys.forEach(key => delete result[key]);
|
|
1528
1528
|
return result;
|
|
@@ -1530,7 +1530,7 @@ export const withPropsUtils = {
|
|
|
1530
1530
|
/**
|
|
1531
1531
|
* Default values for missing props
|
|
1532
1532
|
*/
|
|
1533
|
-
defaults: (defaultProps) => withProps((
|
|
1533
|
+
defaults: (defaultProps) => withProps((props) => ({
|
|
1534
1534
|
...defaultProps,
|
|
1535
1535
|
...props
|
|
1536
1536
|
}), { merge: false }),
|
|
@@ -1539,17 +1539,17 @@ export const withPropsUtils = {
|
|
|
1539
1539
|
*/
|
|
1540
1540
|
validated: (transform, validator) => withProps(transform, {
|
|
1541
1541
|
validate: validator,
|
|
1542
|
-
onError: (
|
|
1542
|
+
onError: (_error) => console.warn('Prop validation failed:', _error)
|
|
1543
1543
|
}),
|
|
1544
1544
|
/**
|
|
1545
1545
|
* Async prop transformation
|
|
1546
1546
|
*/
|
|
1547
|
-
async: (asyncTransform, loadingProps = {}) => withProps(async (props, state,
|
|
1547
|
+
async: (asyncTransform, loadingProps = {}) => withProps(async (props, state, context) => {
|
|
1548
1548
|
try {
|
|
1549
|
-
return await asyncTransform(props, state,
|
|
1549
|
+
return await asyncTransform(props, state, context);
|
|
1550
1550
|
}
|
|
1551
|
-
catch (
|
|
1552
|
-
console.
|
|
1551
|
+
catch (_error) {
|
|
1552
|
+
console._error('Async prop transform failed:', _error);
|
|
1553
1553
|
return loadingProps;
|
|
1554
1554
|
}
|
|
1555
1555
|
}, {
|
|
@@ -1558,11 +1558,11 @@ export const withPropsUtils = {
|
|
|
1558
1558
|
/**
|
|
1559
1559
|
* Computed props based on other props
|
|
1560
1560
|
*/
|
|
1561
|
-
computed: (computedProps) => withProps((
|
|
1561
|
+
computed: (computedProps) => withProps((props) => {
|
|
1562
1562
|
const computed = {};
|
|
1563
1563
|
Object.entries(computedProps).forEach(([key, compute]) => {
|
|
1564
1564
|
computed[key] = typeof compute === 'function' ?
|
|
1565
|
-
compute(
|
|
1565
|
+
compute(props) :
|
|
1566
1566
|
compute;
|
|
1567
1567
|
});
|
|
1568
1568
|
return computed;
|
|
@@ -1570,7 +1570,7 @@ export const withPropsUtils = {
|
|
|
1570
1570
|
/**
|
|
1571
1571
|
* Props with context injection
|
|
1572
1572
|
*/
|
|
1573
|
-
withContext: (contextKeys) => withProps((props, state,
|
|
1573
|
+
withContext: (contextKeys) => withProps((props, state, context) => {
|
|
1574
1574
|
const contextProps = {};
|
|
1575
1575
|
contextKeys.forEach(key => {
|
|
1576
1576
|
if (context && context[key] !== undefined) {
|
|
@@ -1584,7 +1584,7 @@ export const withPropsUtils = {
|
|
|
1584
1584
|
*/
|
|
1585
1585
|
withState: (stateMapping) => withProps((props, state) => {
|
|
1586
1586
|
if (typeof stateMapping === 'function') {
|
|
1587
|
-
return stateMapping(state,
|
|
1587
|
+
return stateMapping(state, props);
|
|
1588
1588
|
}
|
|
1589
1589
|
const stateProps = {};
|
|
1590
1590
|
Object.entries(stateMapping).forEach(([propKey, stateKey]) => {
|
|
@@ -1605,9 +1605,9 @@ export const withPropsUtils = {
|
|
|
1605
1605
|
/**
|
|
1606
1606
|
* Props with performance measurement
|
|
1607
1607
|
*/
|
|
1608
|
-
timed: (transform, name = 'PropTransform') => withProps((props, state,
|
|
1608
|
+
timed: (transform, name = 'PropTransform') => withProps((props, state, context) => {
|
|
1609
1609
|
const start = performance.now();
|
|
1610
|
-
const result = transform(props, state,
|
|
1610
|
+
const result = transform(props, state, context);
|
|
1611
1611
|
const end = performance.now();
|
|
1612
1612
|
if (end - start > 1) { // Log if > 1ms
|
|
1613
1613
|
console.log(`${name} took ${(end - start).toFixed(2)}ms`);
|
|
@@ -1617,13 +1617,13 @@ export const withPropsUtils = {
|
|
|
1617
1617
|
/**
|
|
1618
1618
|
* Chain multiple prop transformations
|
|
1619
1619
|
*/
|
|
1620
|
-
chain: (...transforms) => withProps((props, state,
|
|
1620
|
+
chain: (...transforms) => withProps((props, state, context) => {
|
|
1621
1621
|
return transforms.reduce((acc, transform) => {
|
|
1622
1622
|
if (typeof transform === 'function') {
|
|
1623
|
-
return { ...acc, ...transform(acc, state,
|
|
1623
|
+
return { ...acc, ...transform(acc, state, context) };
|
|
1624
1624
|
}
|
|
1625
1625
|
return { ...acc, ...transform };
|
|
1626
|
-
},
|
|
1626
|
+
}, props);
|
|
1627
1627
|
})
|
|
1628
1628
|
};
|
|
1629
1629
|
/**
|
|
@@ -1631,12 +1631,12 @@ export const withPropsUtils = {
|
|
|
1631
1631
|
*/
|
|
1632
1632
|
export function createPropTransformer(config) {
|
|
1633
1633
|
const { transforms = [], validators = [], defaults = {}, options = {} } = config;
|
|
1634
|
-
return withProps((props, state,
|
|
1634
|
+
return withProps((props, state, context) => {
|
|
1635
1635
|
let result = { ...defaults, ...props };
|
|
1636
1636
|
// Apply transforms in sequence
|
|
1637
1637
|
for (const transform of transforms) {
|
|
1638
1638
|
if (typeof transform === 'function') {
|
|
1639
|
-
result = { ...result, ...transform(result, state,
|
|
1639
|
+
result = { ...result, ...transform(result, state, context) };
|
|
1640
1640
|
}
|
|
1641
1641
|
else {
|
|
1642
1642
|
result = { ...result, ...transform };
|
|
@@ -1656,12 +1656,12 @@ export function createPropTransformer(config) {
|
|
|
1656
1656
|
*/
|
|
1657
1657
|
export function withPropsDebug(component, debugOptions = {}) {
|
|
1658
1658
|
const { logProps = true, logChanges = true, breakOnError = false } = debugOptions;
|
|
1659
|
-
return withProps((props, state,
|
|
1659
|
+
return withProps((props, state, context) => {
|
|
1660
1660
|
if (logProps) {
|
|
1661
1661
|
console.group(`Props Debug: ${component.name || 'Component'}`);
|
|
1662
|
-
console.log('Props:',
|
|
1662
|
+
console.log('Props:', props);
|
|
1663
1663
|
console.log('State:', state);
|
|
1664
|
-
console.log('Context:',
|
|
1664
|
+
console.log('Context:', context);
|
|
1665
1665
|
console.groupEnd();
|
|
1666
1666
|
}
|
|
1667
1667
|
return props;
|
|
@@ -1738,7 +1738,7 @@ export function withState(initialState = {}, options = {}) {
|
|
|
1738
1738
|
if (!stateContainer.initialized) {
|
|
1739
1739
|
stateContainer.initialize();
|
|
1740
1740
|
if (onMount) {
|
|
1741
|
-
onMount(stateContainer.getState(), props,
|
|
1741
|
+
onMount(stateContainer.getState(), props, context);
|
|
1742
1742
|
}
|
|
1743
1743
|
}
|
|
1744
1744
|
// Get current state
|
|
@@ -1746,7 +1746,7 @@ export function withState(initialState = {}, options = {}) {
|
|
|
1746
1746
|
// Transform state if needed
|
|
1747
1747
|
let transformedState = currentState;
|
|
1748
1748
|
if (stateTransform) {
|
|
1749
|
-
transformedState = stateTransform(currentState, props,
|
|
1749
|
+
transformedState = stateTransform(currentState, props, context);
|
|
1750
1750
|
}
|
|
1751
1751
|
// Create actions bound to this state container
|
|
1752
1752
|
const boundActions = createBoundActions(actions, stateContainer, {
|
|
@@ -1818,7 +1818,7 @@ export function withState(initialState = {}, options = {}) {
|
|
|
1818
1818
|
}
|
|
1819
1819
|
// Render wrapped component
|
|
1820
1820
|
return typeof WrappedComponent === 'function' ?
|
|
1821
|
-
WrappedComponent(enhancedProps, globalState,
|
|
1821
|
+
WrappedComponent(enhancedProps, globalState, context) :
|
|
1822
1822
|
WrappedComponent;
|
|
1823
1823
|
}
|
|
1824
1824
|
// Set display name
|
|
@@ -1861,9 +1861,9 @@ function createStateContainer(initialState, options) {
|
|
|
1861
1861
|
state = { ...state, ...parsed };
|
|
1862
1862
|
}
|
|
1863
1863
|
}
|
|
1864
|
-
catch (
|
|
1864
|
+
catch (_error) {
|
|
1865
1865
|
if (debug)
|
|
1866
|
-
console.warn('Failed to load persisted state:',
|
|
1866
|
+
console.warn('Failed to load persisted state:', _error);
|
|
1867
1867
|
}
|
|
1868
1868
|
}
|
|
1869
1869
|
container.initialized = true;
|
|
@@ -1896,9 +1896,9 @@ function createStateContainer(initialState, options) {
|
|
|
1896
1896
|
try {
|
|
1897
1897
|
storage.setItem(storageKey, JSON.stringify(state));
|
|
1898
1898
|
}
|
|
1899
|
-
catch (
|
|
1899
|
+
catch (_error) {
|
|
1900
1900
|
if (debug)
|
|
1901
|
-
console.warn('Failed to persist state:',
|
|
1901
|
+
console.warn('Failed to persist state:', _error);
|
|
1902
1902
|
}
|
|
1903
1903
|
}
|
|
1904
1904
|
// Notify listeners
|
|
@@ -1907,9 +1907,9 @@ function createStateContainer(initialState, options) {
|
|
|
1907
1907
|
try {
|
|
1908
1908
|
listener(state, prevState);
|
|
1909
1909
|
}
|
|
1910
|
-
catch (
|
|
1910
|
+
catch (_error) {
|
|
1911
1911
|
if (debug)
|
|
1912
|
-
console.
|
|
1912
|
+
console._error('State listener _error:', _error);
|
|
1913
1913
|
}
|
|
1914
1914
|
});
|
|
1915
1915
|
if (onStateChange) {
|
|
@@ -1943,9 +1943,9 @@ function createStateContainer(initialState, options) {
|
|
|
1943
1943
|
try {
|
|
1944
1944
|
storage.removeItem(storageKey);
|
|
1945
1945
|
}
|
|
1946
|
-
catch (
|
|
1946
|
+
catch (_error) {
|
|
1947
1947
|
if (debug)
|
|
1948
|
-
console.warn('Failed to remove persisted state:',
|
|
1948
|
+
console.warn('Failed to remove persisted state:', _error);
|
|
1949
1949
|
}
|
|
1950
1950
|
}
|
|
1951
1951
|
}
|
|
@@ -1964,18 +1964,18 @@ function createBoundActions(actions, stateContainer, options) {
|
|
|
1964
1964
|
const result = actionCreator(stateContainer.getState(), stateContainer.setState.bind(stateContainer), { props, context, args });
|
|
1965
1965
|
// Handle async actions
|
|
1966
1966
|
if (supportAsync && result && typeof result.then === 'function') {
|
|
1967
|
-
return result.catch(
|
|
1967
|
+
return result.catch(_error => {
|
|
1968
1968
|
if (debug)
|
|
1969
|
-
console.
|
|
1970
|
-
throw
|
|
1969
|
+
console._error(`Async action ${actionName} failed:`, _error);
|
|
1970
|
+
throw _error;
|
|
1971
1971
|
});
|
|
1972
1972
|
}
|
|
1973
1973
|
return result;
|
|
1974
1974
|
}
|
|
1975
|
-
catch (
|
|
1975
|
+
catch (_error) {
|
|
1976
1976
|
if (debug)
|
|
1977
|
-
console.
|
|
1978
|
-
throw
|
|
1977
|
+
console._error(`Action ${actionName} failed:`, _error);
|
|
1978
|
+
throw _error;
|
|
1979
1979
|
}
|
|
1980
1980
|
};
|
|
1981
1981
|
});
|
|
@@ -2027,7 +2027,7 @@ export const withStateUtils = {
|
|
|
2027
2027
|
}
|
|
2028
2028
|
return (WrappedComponent) => {
|
|
2029
2029
|
const sharedContainer = sharedStates.get(sharedKey);
|
|
2030
|
-
function SharedStateComponent(props, globalState,
|
|
2030
|
+
function SharedStateComponent(props, globalState, context) {
|
|
2031
2031
|
const currentState = sharedContainer.getState();
|
|
2032
2032
|
const enhancedProps = {
|
|
2033
2033
|
...props,
|
|
@@ -2036,7 +2036,7 @@ export const withStateUtils = {
|
|
|
2036
2036
|
subscribe: sharedContainer.subscribe.bind(sharedContainer)
|
|
2037
2037
|
};
|
|
2038
2038
|
return typeof WrappedComponent === 'function' ?
|
|
2039
|
-
WrappedComponent(enhancedProps, globalState,
|
|
2039
|
+
WrappedComponent(enhancedProps, globalState, context) :
|
|
2040
2040
|
WrappedComponent;
|
|
2041
2041
|
}
|
|
2042
2042
|
SharedStateComponent.displayName = `withSharedState(${getComponentName(WrappedComponent)})`;
|
|
@@ -2065,7 +2065,7 @@ export const withStateUtils = {
|
|
|
2065
2065
|
}
|
|
2066
2066
|
}),
|
|
2067
2067
|
/**
|
|
2068
|
-
* State with loading/
|
|
2068
|
+
* State with loading/_error handling
|
|
2069
2069
|
*/
|
|
2070
2070
|
withLoading: async (initialState) => withState({
|
|
2071
2071
|
...initialState,
|
|
@@ -2077,8 +2077,8 @@ export const withStateUtils = {
|
|
|
2077
2077
|
setLoading: (state, setState, { args: [loading] }) => {
|
|
2078
2078
|
setState({ _loading: loading });
|
|
2079
2079
|
},
|
|
2080
|
-
setError: (state, setState, { args: [
|
|
2081
|
-
setState({ _error:
|
|
2080
|
+
setError: (state, setState, { args: [_error] }) => {
|
|
2081
|
+
setState({ _error: _error, _loading: false });
|
|
2082
2082
|
},
|
|
2083
2083
|
clearError: (state, setState) => {
|
|
2084
2084
|
setState({ _error: null });
|
|
@@ -2090,9 +2090,9 @@ export const withStateUtils = {
|
|
|
2090
2090
|
setState({ _loading: false });
|
|
2091
2091
|
return result;
|
|
2092
2092
|
}
|
|
2093
|
-
catch (
|
|
2094
|
-
setState({ _loading: false, _error:
|
|
2095
|
-
throw
|
|
2093
|
+
catch (_error) {
|
|
2094
|
+
setState({ _loading: false, _error: _error });
|
|
2095
|
+
throw _error;
|
|
2096
2096
|
}
|
|
2097
2097
|
}
|
|
2098
2098
|
}
|
package/dist/core/html-utils.js
CHANGED
|
@@ -44,9 +44,9 @@ export function isVoidElement(tagName) {
|
|
|
44
44
|
]);
|
|
45
45
|
return voidElements.has(tagName.toLowerCase());
|
|
46
46
|
}
|
|
47
|
-
export function formatAttributes(
|
|
47
|
+
export function formatAttributes(props) {
|
|
48
48
|
let formatted = '';
|
|
49
|
-
for (const key in
|
|
49
|
+
for (const key in props) {
|
|
50
50
|
if (props.hasOwnProperty(key)) {
|
|
51
51
|
let value = props[key];
|
|
52
52
|
// Convert className to class for HTML output
|
|
@@ -109,10 +109,10 @@ export function formatAttributes(_props) {
|
|
|
109
109
|
try {
|
|
110
110
|
value = value();
|
|
111
111
|
}
|
|
112
|
-
catch (
|
|
112
|
+
catch (_error) {
|
|
113
113
|
console.warn(`Error executing function for attribute '${key}':`, {
|
|
114
|
-
|
|
115
|
-
stack:
|
|
114
|
+
_error: _error.message,
|
|
115
|
+
stack: _error.stack,
|
|
116
116
|
attributeKey: key,
|
|
117
117
|
});
|
|
118
118
|
// Consider different fallback strategies based on attribute type
|