@hypen-space/web 0.4.3 → 0.4.5

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/client.js CHANGED
@@ -2351,7 +2351,58 @@ var eventHandlers = {
2351
2351
  onFocus: createEventHandler("focus", { extractPayload: focusPayload }),
2352
2352
  onBlur: createEventHandler("blur", { extractPayload: focusPayload }),
2353
2353
  onMouseEnter: createEventHandler("mouseenter", { extractPayload: mousePayload }),
2354
- onMouseLeave: createEventHandler("mouseleave", { extractPayload: mousePayload })
2354
+ onMouseLeave: createEventHandler("mouseleave", { extractPayload: mousePayload }),
2355
+ bind: (element, value) => {
2356
+ const bindPath = typeof value === "string" ? value : null;
2357
+ if (!bindPath)
2358
+ return;
2359
+ const disposables = getElementDisposables2(element);
2360
+ const eventKey = `bind:${bindPath}`;
2361
+ if (getRegisteredEvents(element).has(eventKey))
2362
+ return;
2363
+ registerEvent(element, eventKey);
2364
+ const hypenType = element.dataset?.hypenType;
2365
+ if (hypenType === "checkbox" || hypenType === "switch") {
2366
+ const input = element.querySelector('input[type="checkbox"]');
2367
+ if (!input)
2368
+ return;
2369
+ const listener = () => {
2370
+ const engine = getEngine(element);
2371
+ if (engine) {
2372
+ engine.dispatchAction("__hypen_bind", {
2373
+ path: bindPath,
2374
+ value: input.checked
2375
+ });
2376
+ }
2377
+ };
2378
+ disposables.add(disposableListener(input, "change", listener, { passive: true }));
2379
+ } else if (element instanceof HTMLSelectElement) {
2380
+ const listener = () => {
2381
+ const engine = getEngine(element);
2382
+ if (engine) {
2383
+ engine.dispatchAction("__hypen_bind", {
2384
+ path: bindPath,
2385
+ value: element.value
2386
+ });
2387
+ }
2388
+ };
2389
+ disposables.add(disposableListener(element, "change", listener, { passive: true }));
2390
+ } else if (element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement) {
2391
+ const listener = () => {
2392
+ const engine = getEngine(element);
2393
+ if (engine) {
2394
+ engine.dispatchAction("__hypen_bind", {
2395
+ path: bindPath,
2396
+ value: element.value
2397
+ });
2398
+ }
2399
+ };
2400
+ disposables.add(disposableListener(element, "input", listener, { passive: true }));
2401
+ } else {
2402
+ return;
2403
+ }
2404
+ disposables.addCallback(() => unregisterEvent(element, eventKey));
2405
+ }
2355
2406
  };
2356
2407
 
2357
2408
  // src/dom/applicators/typography.ts
@@ -3320,7 +3371,7 @@ class DOMRenderer {
3320
3371
  applicators;
3321
3372
  engine;
3322
3373
  currentState = {};
3323
- routerContext = null;
3374
+ router = null;
3324
3375
  globalContext = null;
3325
3376
  componentInstances = new Map;
3326
3377
  debugTracker;
@@ -3335,8 +3386,8 @@ class DOMRenderer {
3335
3386
  this.applicators.register(name, handler);
3336
3387
  }
3337
3388
  }
3338
- setContext(routerContext, globalContext) {
3339
- this.routerContext = routerContext;
3389
+ setContext(router, globalContext) {
3390
+ this.router = router;
3340
3391
  this.globalContext = globalContext;
3341
3392
  }
3342
3393
  applyPatches(patches) {
@@ -3568,7 +3619,6 @@ class Hypen {
3568
3619
  componentLoader.register("Router", Router, "");
3569
3620
  componentLoader.register("Route", Route, "");
3570
3621
  componentLoader.register("Link", Link, "");
3571
- this.globalContext.__router = this.router;
3572
3622
  this.globalContext.__hypenEngine = this;
3573
3623
  }
3574
3624
  async init() {
@@ -3615,13 +3665,9 @@ class Hypen {
3615
3665
  log6.debug(`Applying ${patches.length} patches`);
3616
3666
  this.renderer.applyPatches(patches);
3617
3667
  });
3618
- const routerContext = {
3619
- root: this.router,
3620
- current: this.router
3621
- };
3622
- this.renderer.setContext(routerContext, this.globalContext);
3668
+ this.renderer.setContext(this.router, this.globalContext);
3623
3669
  const moduleId = this.extractModuleId(componentName, component.template);
3624
- this.moduleInstance = new HypenModuleInstance(this.engine, component.module, routerContext, this.globalContext);
3670
+ this.moduleInstance = new HypenModuleInstance(this.engine, component.module, this.router, this.globalContext);
3625
3671
  this.globalContext.registerModule(moduleId, this.moduleInstance);
3626
3672
  this.moduleInstances.set(moduleId, this.moduleInstance);
3627
3673
  this.moduleInstance.onStateChange(() => {
@@ -3689,11 +3735,7 @@ class Hypen {
3689
3735
  }
3690
3736
  if (component.module && !this.moduleInstances.has(componentName)) {
3691
3737
  const moduleId = this.extractModuleId(componentName, template);
3692
- const routerContext = {
3693
- root: this.router,
3694
- current: this.router
3695
- };
3696
- const moduleInstance = new HypenModuleInstance(this.engine, component.module, routerContext, this.globalContext);
3738
+ const moduleInstance = new HypenModuleInstance(this.engine, component.module, this.router, this.globalContext);
3697
3739
  this.globalContext.registerModule(moduleId, moduleInstance);
3698
3740
  this.moduleInstances.set(componentName, moduleInstance);
3699
3741
  moduleInstance.onStateChange(() => {
@@ -3720,12 +3762,8 @@ class Hypen {
3720
3762
  return componentName;
3721
3763
  }
3722
3764
  createNestedModuleInstances() {
3723
- const routerContext = {
3724
- root: this.router,
3725
- current: this.router
3726
- };
3727
3765
  if (Router && !this.moduleInstances.has("Router")) {
3728
- const routerInstance = new HypenModuleInstance(this.engine, Router, routerContext, this.globalContext);
3766
+ const routerInstance = new HypenModuleInstance(this.engine, Router, this.router, this.globalContext);
3729
3767
  this.globalContext.registerModule("Router", routerInstance);
3730
3768
  this.moduleInstances.set("Router", routerInstance);
3731
3769
  routerInstance.onStateChange(() => {
@@ -3744,7 +3782,7 @@ class Hypen {
3744
3782
  continue;
3745
3783
  }
3746
3784
  log6.debug(`Creating nested module instance for: ${name}`);
3747
- const moduleInstance = new HypenModuleInstance(this.engine, comp.module, routerContext, this.globalContext);
3785
+ const moduleInstance = new HypenModuleInstance(this.engine, comp.module, this.router, this.globalContext);
3748
3786
  this.globalContext.registerModule(name, moduleInstance);
3749
3787
  this.moduleInstances.set(name, moduleInstance);
3750
3788
  moduleInstance.onStateChange(() => {
@@ -3841,4 +3879,4 @@ export {
3841
3879
  Hypen
3842
3880
  };
3843
3881
 
3844
- //# debugId=12790505428577C564756E2164756E21
3882
+ //# debugId=20E08544CB23F9AF64756E2164756E21