@coherent.js/client 1.0.0-beta.6 → 1.0.0-beta.7

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.
@@ -11,7 +11,7 @@
11
11
  window.__coherent_hmr_initialized = true;
12
12
  const log = (...args) => console.log('[Coherent HMR]', ...args);
13
13
  const warn = (...args) => console.warn('[Coherent HMR]', ...args);
14
- const _error = (...args) => console._error('[Coherent HMR]', ...args);
14
+ const _error = (...args) => console.error('[Coherent HMR]', ...args);
15
15
  let hadDisconnect = false;
16
16
  function connect() {
17
17
  try {
@@ -33,8 +33,8 @@
33
33
  warn('disconnected, retrying in 1s...');
34
34
  setTimeout(connect, 1000);
35
35
  });
36
- ws.addEventListener('_error', (e) => {
37
- _error('socket _error', e);
36
+ ws.addEventListener('error', (e) => {
37
+ error('socket error', e);
38
38
  try {
39
39
  ws.close();
40
40
  }
@@ -58,8 +58,8 @@ function extractInitialState(element, options = {}) {
58
58
  }
59
59
  return hasState ? state : null;
60
60
  }
61
- catch (_error) {
62
- console.warn('Error extracting initial state:', _error);
61
+ catch (error) {
62
+ console.warn('Error extracting initial state:', error);
63
63
  return options.initialState || null;
64
64
  }
65
65
  }
@@ -107,8 +107,8 @@ function hydrate(element, component, props = {}, options = {}) {
107
107
  // Always use the fallback patching method to preserve hydration
108
108
  this.fallbackRerender();
109
109
  }
110
- catch (_error) {
111
- console._error('Error during component re-render:', _error);
110
+ catch (error) {
111
+ console.error('Error during component re-render:', error);
112
112
  }
113
113
  },
114
114
  // Fallback re-render method using existing patching
@@ -129,8 +129,8 @@ function hydrate(element, component, props = {}, options = {}) {
129
129
  this.previousVirtualElement = newVirtualElement;
130
130
  // Component re-rendered successfully with fallback
131
131
  }
132
- catch (_error) {
133
- console._error('Error during component re-render (fallback):', _error);
132
+ catch (error) {
133
+ console.error('Error during component re-render (fallback):', error);
134
134
  }
135
135
  },
136
136
  // Create virtual element representation from existing DOM
@@ -316,9 +316,9 @@ function hydrate(element, component, props = {}, options = {}) {
316
316
  (node.nodeType === Node.TEXT_NODE && node.textContent && node.textContent.trim());
317
317
  });
318
318
  }
319
- catch (_error) {
319
+ catch (error) {
320
320
  // Fallback to empty array if Array.from fails
321
- console.warn('Failed to convert childNodes to array:', _error);
321
+ console.warn('Failed to convert childNodes to array:', error);
322
322
  domChildren = [];
323
323
  }
324
324
  }
@@ -366,7 +366,7 @@ function hydrate(element, component, props = {}, options = {}) {
366
366
  const props = vNode[tagName] || {};
367
367
  const element = document.createElement(tagName);
368
368
  // Set attributes
369
- Object.keys(props).forEach(key => {
369
+ Object.keys(_props).forEach(key => {
370
370
  if (key === 'children' || key === 'text')
371
371
  return;
372
372
  const value = props[key];
@@ -411,7 +411,7 @@ function hydrate(element, component, props = {}, options = {}) {
411
411
  // Build attributes
412
412
  let attributes = '';
413
413
  const children = [];
414
- Object.keys(props).forEach(key => {
414
+ Object.keys(_props).forEach(key => {
415
415
  if (key === 'children') {
416
416
  if (Array.isArray(props.children)) {
417
417
  children.push(...props.children);
@@ -571,8 +571,8 @@ if (typeof window !== 'undefined') {
571
571
  // Call the handler function with the element as context and pass event, state, setState
572
572
  handlerFunc.call(element, event, state, setState);
573
573
  }
574
- catch (_error) {
575
- console.warn(`Error executing coherent event handler:`, _error);
574
+ catch (error) {
575
+ console.warn(`Error executing coherent event handler:`, error);
576
576
  }
577
577
  }
578
578
  else {
@@ -580,8 +580,8 @@ if (typeof window !== 'undefined') {
580
580
  try {
581
581
  handlerFunc.call(element, event);
582
582
  }
583
- catch (_error) {
584
- console.warn(`Error executing coherent event handler (no component context):`, _error);
583
+ catch (error) {
584
+ console.warn(`Error executing coherent event handler (no component _context):`, error);
585
585
  }
586
586
  }
587
587
  }
@@ -630,7 +630,7 @@ function renderVirtualDOMToElement(vdom, container) {
630
630
  const element = document.createElement(tagName);
631
631
  const props = vdom[tagName] || {};
632
632
  // Set attributes and properties
633
- Object.keys(props).forEach(key => {
633
+ Object.keys(_props).forEach(key => {
634
634
  if (key === 'children') {
635
635
  // Handle children
636
636
  const children = props.children;
@@ -984,8 +984,8 @@ function attachFunctionEventListeners(rootElement, virtualElement, instance, opt
984
984
  const result = handler.call(domElement, event, currentState, currentSetState);
985
985
  return result;
986
986
  }
987
- catch (_error) {
988
- console._error(`Error in ${eventName} handler:`, _error);
987
+ catch (error) {
988
+ console.error(`Error in ${eventName} handler:`, error);
989
989
  }
990
990
  };
991
991
  // Remove any existing onclick attributes that might interfere
@@ -1106,8 +1106,8 @@ function attachEventListeners(element, instance) {
1106
1106
  const func = new Function('event', 'state', 'setState', 'element', eventAttr);
1107
1107
  func.call(elementWithEvent, e, state, setState, elementWithEvent);
1108
1108
  }
1109
- catch (_error) {
1110
- console.warn(`Error executing ${eventName} handler:`, _error);
1109
+ catch (error) {
1110
+ console.warn(`Error executing ${eventName} handler:`, error);
1111
1111
  }
1112
1112
  };
1113
1113
  if (typeof elementWithEvent.addEventListener === 'function') {
@@ -1165,8 +1165,8 @@ function attachEventListeners(element, instance) {
1165
1165
  handlerFunc.call(actionElement, e);
1166
1166
  }
1167
1167
  }
1168
- catch (_error) {
1169
- console.warn(`Error executing action handler for ${actionId}:`, _error);
1168
+ catch (error) {
1169
+ console.warn(`Error executing action handler for ${actionId}:`, error);
1170
1170
  }
1171
1171
  };
1172
1172
  if (typeof actionElement.addEventListener === 'function') {
@@ -1211,8 +1211,8 @@ function attachEventListeners(element, instance) {
1211
1211
  // Bind the function to the element and call it with the event
1212
1212
  handlerFunc.call(elementWithCoherentEvent, e, state, setState);
1213
1213
  }
1214
- catch (_error) {
1215
- console.warn(`Error executing coherent event handler:`, _error);
1214
+ catch (error) {
1215
+ console.warn(`Error executing coherent event handler:`, error);
1216
1216
  }
1217
1217
  };
1218
1218
  if (typeof elementWithCoherentEvent.addEventListener === 'function') {
@@ -1230,8 +1230,8 @@ function attachEventListeners(element, instance) {
1230
1230
  }
1231
1231
  });
1232
1232
  }
1233
- catch (_error) {
1234
- console.warn('Error attaching event listeners:', _error);
1233
+ catch (error) {
1234
+ console.warn('Error attaching event listeners:', error);
1235
1235
  }
1236
1236
  }
1237
1237
  /**
@@ -1324,8 +1324,8 @@ function handleComponentAction(event, action, target, instance) {
1324
1324
  // Call the custom method on the instance
1325
1325
  instance[action](event, target);
1326
1326
  }
1327
- catch (_error) {
1328
- console.warn(`Error executing custom action ${action}:`, _error);
1327
+ catch (error) {
1328
+ console.warn(`Error executing custom action ${action}:`, error);
1329
1329
  }
1330
1330
  }
1331
1331
  else {
@@ -1339,8 +1339,8 @@ function handleComponentAction(event, action, target, instance) {
1339
1339
  // Call the handler function with event, state, and setState
1340
1340
  handlerFunc(event, state, setState);
1341
1341
  }
1342
- catch (_error) {
1343
- console.warn(`Error executing action handler ${action}:`, _error);
1342
+ catch (error) {
1343
+ console.warn(`Error executing action handler ${action}:`, error);
1344
1344
  }
1345
1345
  }
1346
1346
  else {
@@ -1365,7 +1365,7 @@ function hydrateAll(elements, components, propsArray = []) {
1365
1365
  return elements.map((element, index) => {
1366
1366
  const component = components[index];
1367
1367
  const props = propsArray[index] || {};
1368
- return hydrate(element, component, props);
1368
+ return hydrate(element, component, _props);
1369
1369
  });
1370
1370
  }
1371
1371
  /**
@@ -1381,7 +1381,7 @@ function hydrateBySelector(selector, component, props = {}) {
1381
1381
  return [];
1382
1382
  }
1383
1383
  const elements = document.querySelectorAll(selector);
1384
- return Array.from(elements).map(element => hydrate(element, component, props));
1384
+ return Array.from(elements).map(element => hydrate(element, component, _props));
1385
1385
  }
1386
1386
  /**
1387
1387
  * Enable client-side interactivity for event handlers
@@ -1408,7 +1408,7 @@ function makeHydratable(component, options = {}) {
1408
1408
  const componentName = options.componentName || component.name || 'AnonymousComponent';
1409
1409
  // Create a new function that wraps the original component
1410
1410
  const hydratableComponent = function (props = {}) {
1411
- return component(props);
1411
+ return component(_props);
1412
1412
  };
1413
1413
  // Set the component name on the hydratable component function
1414
1414
  Object.defineProperty(hydratableComponent, 'name', {
@@ -1477,13 +1477,13 @@ function makeHydratable(component, options = {}) {
1477
1477
  hydrationAttributes: {
1478
1478
  'data-coherent-component': componentName,
1479
1479
  'data-coherent-state': state ? JSON.stringify(state) : (options.initialState ? JSON.stringify(options.initialState) : null),
1480
- 'data-coherent-props': Object.keys(props).length > 0 ? JSON.stringify(props) : null
1480
+ 'data-coherent-props': Object.keys(_props).length > 0 ? JSON.stringify(_props) : null
1481
1481
  }
1482
1482
  };
1483
1483
  };
1484
1484
  // Add a method to render with hydration data
1485
1485
  hydratableComponent.renderWithHydration = function (props = {}) {
1486
- const result = hydratableComponent(props);
1486
+ const result = hydratableComponent(_props);
1487
1487
  // Try to extract state from the component if it's a withState wrapped component
1488
1488
  let state = null;
1489
1489
  if (hydratableComponent.__wrappedComponent && hydratableComponent.__stateContainer) {
@@ -1552,7 +1552,7 @@ function autoHydrate(componentRegistry = {}) {
1552
1552
  }
1553
1553
  }
1554
1554
  if (!component) {
1555
- console._error(`❌ Component ${componentName} not found in registry`);
1555
+ console.error(`❌ Component ${componentName} not found in registry`);
1556
1556
  return; // Skip this element
1557
1557
  }
1558
1558
  if (component) {
@@ -1572,8 +1572,8 @@ function autoHydrate(componentRegistry = {}) {
1572
1572
  console.warn(`❌ Failed to hydrate component: ${componentName}`);
1573
1573
  }
1574
1574
  }
1575
- catch (_error) {
1576
- console._error(`❌ Failed to auto-hydrate component ${componentName}:`, _error);
1575
+ catch (error) {
1576
+ console.error(`❌ Failed to auto-hydrate component ${componentName}:`, error);
1577
1577
  }
1578
1578
  }
1579
1579
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coherent.js/client",
3
- "version": "1.0.0-beta.6",
3
+ "version": "1.0.0-beta.7",
4
4
  "description": "Client-side hydration/HMR utilities for Coherent.js",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -43,6 +43,10 @@
43
43
  "type": "git",
44
44
  "url": "git+https://github.com/Tomdrouv1/coherent.js.git"
45
45
  },
46
+ "homepage": "https://github.com/Tomdrouv1/coherent.js",
47
+ "bugs": {
48
+ "url": "https://github.com/Tomdrouv1/coherent.js/issues"
49
+ },
46
50
  "publishConfig": {
47
51
  "access": "public",
48
52
  "registry": "https://registry.npmjs.org/"