@kithinji/orca 1.0.4 → 1.0.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.
@@ -2737,7 +2737,7 @@ var OSC = class {
2737
2737
  vnode.setId(jsx2.id);
2738
2738
  }
2739
2739
  parent.addChild(vnode);
2740
- this.loadClientComponent(path, name, jsx2.props, container, vnode);
2740
+ this.loadClientComponent(path, name, jsx2.props, container);
2741
2741
  return { domNode: container, vnode };
2742
2742
  }
2743
2743
  buildPendingReference(jsx2, parent) {
@@ -2862,43 +2862,44 @@ var OSC = class {
2862
2862
  dom.removeAttribute(key);
2863
2863
  }
2864
2864
  }
2865
- async loadClientComponent(path, name, props, container, vnode) {
2865
+ async loadClientComponent(path, name, props, container) {
2866
2866
  try {
2867
+ let register2 = function(Cls, injector2) {
2868
+ if (seen.has(Cls))
2869
+ return;
2870
+ seen.add(Cls);
2871
+ injector2.addProvider({
2872
+ provide: Cls,
2873
+ useClass: Cls,
2874
+ scope: "transient"
2875
+ });
2876
+ const paramDeps = Reflect.getMetadata(DESIGN_PARAMTYPES, Cls) ?? [];
2877
+ const explicitDeps = Reflect.getMetadata(COMPONENT_DEPS, Cls) ?? [];
2878
+ paramDeps.filter((d) => d && d !== Object).forEach((d) => injector2.addProvider(d));
2879
+ explicitDeps.forEach((deps) => register2(deps, injector2));
2880
+ };
2881
+ var register = register2;
2867
2882
  const module = await import(path);
2868
2883
  const ComponentClass = module[name];
2869
- const params = Reflect.getMetadata(DESIGN_PARAMTYPES, ComponentClass) || [];
2870
- const deps = Reflect.getMetadata(COMPONENT_DEPS, ComponentClass) || [];
2871
- const injector = getCurrentInjector();
2872
- if (injector == null) {
2873
- throw new Error(`Couldn't find an injector`);
2874
- }
2875
2884
  if (!ComponentClass) {
2876
2885
  throw new Error(`Component ${name} not found in ${path}`);
2877
2886
  }
2878
- injector.addProvider({
2879
- provide: ComponentClass,
2880
- useClass: ComponentClass,
2881
- scope: "transient"
2882
- });
2883
- deps.forEach(
2884
- (depClass) => injector.addProvider({
2885
- provide: depClass,
2886
- useClass: depClass,
2887
- scope: "transient"
2888
- })
2889
- );
2890
- params.forEach((p) => injector.addProvider(p));
2887
+ const injector = getCurrentInjector();
2888
+ if (injector == null) {
2889
+ throw new Error("Couldn't find an injector");
2890
+ }
2891
+ const seen = /* @__PURE__ */ new Set();
2892
+ register2(ComponentClass, injector);
2891
2893
  const cleanProps = { ...props };
2892
2894
  delete cleanProps.__clientComponent;
2893
- const componentInstance = injector.resolve(ComponentClass);
2894
- componentInstance.__injector = injector;
2895
- componentInstance.props = cleanProps;
2896
- if (typeof componentInstance.build === "function") {
2897
- const rendered = componentInstance.build();
2898
- container.parentNode?.replaceChild(rendered, container);
2899
- } else {
2900
- throw new Error(`Component ${name} does not have a build method`);
2895
+ const instance = injector.resolve(ComponentClass);
2896
+ instance.__injector = injector;
2897
+ instance.props = cleanProps;
2898
+ if (typeof instance.build !== "function") {
2899
+ throw new Error(`Component ${name} does not implement build()`);
2901
2900
  }
2901
+ const rendered = instance.build();
2902
+ container.replaceWith(rendered);
2902
2903
  } catch (error) {
2903
2904
  console.error(`Failed to load client component ${name}:`, error);
2904
2905
  container.textContent = `Error loading component: ${name}`;