revojs 0.0.52 → 0.0.54

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.
@@ -61,7 +61,7 @@ export interface ComponentConstructor<TEvents extends Events, TAttributes extend
61
61
  $events: TEvents;
62
62
  $attributes: TAttributes;
63
63
  $styles: Array<string>;
64
- new (input?: Input<TEvents, TAttributes>, scope?: Scope): Component<TEvents, TAttributes>;
64
+ new (input?: Input<TEvents, TAttributes>, parentScope?: Scope): Component<TEvents, TAttributes>;
65
65
  }
66
66
  export interface CustomElement<TEvents extends Events, TAttributes extends Attributes> extends HTMLElement {
67
67
  readonly component: Component<TEvents, TAttributes>;
package/dist/index.js CHANGED
@@ -110,9 +110,9 @@ var StopEvent = class extends Event {
110
110
  var Scope = class extends EventTarget {
111
111
  parentScope;
112
112
  context;
113
- constructor(scope) {
113
+ constructor(parentScope) {
114
114
  super();
115
- this.parentScope = scope;
115
+ this.parentScope = parentScope;
116
116
  this.context = new Map();
117
117
  }
118
118
  getContext(input) {
@@ -366,8 +366,8 @@ const defineComponent = (options) => {
366
366
  events;
367
367
  attributes;
368
368
  shadowRoot;
369
- constructor(input, scope) {
370
- this.scope = new Scope(scope);
369
+ constructor(input, parentScope) {
370
+ this.scope = new Scope(parentScope);
371
371
  this.events = Object.keys(options.events ?? {}).reduce((output, name) => {
372
372
  Reflect.set(output, name, input?.[name], output);
373
373
  return output;
@@ -386,18 +386,22 @@ const defineComponent = (options) => {
386
386
  const toCustomElement = (Component) => {
387
387
  return class extends HTMLElement {
388
388
  static formAssociated = true;
389
- component = new Component();
390
- internals = this.attachInternals();
391
- async connectedCallback() {
392
- let rootNode = this;
389
+ component;
390
+ internals;
391
+ constructor() {
392
+ super();
393
393
  const findParent = (node) => {
394
394
  if (node) {
395
395
  if ("component" in node) return node;
396
+ if (node instanceof ShadowRoot) return findParent(node.host);
396
397
  return findParent(node.parentNode);
397
398
  }
398
399
  };
399
- const parentNode = findParent(this.parentNode);
400
- if (parentNode) this.component.scope.parentScope = parentNode.component.scope;
400
+ this.component = new Component(void 0, findParent(this.parentNode)?.component.scope);
401
+ this.internals = this.attachInternals();
402
+ }
403
+ async connectedCallback() {
404
+ let rootNode = this;
401
405
  if (this.component.shadowRoot) rootNode = this.shadowRoot ?? this.attachShadow(this.component.shadowRoot);
402
406
  for (const [name, event] of Object.entries(Component.$events)) Reflect.set(this.component.events, name, (value) => {
403
407
  if (value instanceof Event) return;
@@ -1,4 +1,4 @@
1
- import { RUNTIME_CONTEXT, Scope } from "./runtime-CnZe26-A.js";
1
+ import { RUNTIME_CONTEXT, Scope } from "./runtime-C9LNWVm0.js";
2
2
  import { runtime } from "#virtual/runtime";
3
3
  import { serve } from "bun";
4
4
 
@@ -1,4 +1,4 @@
1
- import { RUNTIME_CONTEXT, Scope } from "./runtime-CnZe26-A.js";
1
+ import { RUNTIME_CONTEXT, Scope } from "./runtime-C9LNWVm0.js";
2
2
  import { runtime } from "#virtual/runtime";
3
3
 
4
4
  //#region src/presets/cloudflare.ts
@@ -7,9 +7,9 @@ var StopEvent = class extends Event {
7
7
  var Scope = class extends EventTarget {
8
8
  parentScope;
9
9
  context;
10
- constructor(scope) {
10
+ constructor(parentScope) {
11
11
  super();
12
- this.parentScope = scope;
12
+ this.parentScope = parentScope;
13
13
  this.context = new Map();
14
14
  }
15
15
  getContext(input) {
@@ -10,9 +10,9 @@ export declare class StopEvent extends Event {
10
10
  constructor();
11
11
  }
12
12
  export declare class Scope extends EventTarget {
13
- parentScope?: Scope;
13
+ readonly parentScope?: Scope;
14
14
  readonly context: Map<string, unknown>;
15
- constructor(scope?: Scope);
15
+ constructor(parentScope?: Scope);
16
16
  getContext<T>(input: Descriptor<T>): T;
17
17
  setContext<T>(input: Descriptor<T>, value: T): void;
18
18
  onStop(input: (event: StopEvent) => void): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "revojs",
3
- "version": "0.0.52",
3
+ "version": "0.0.54",
4
4
  "type": "module",
5
5
  "repository": "coverbase/revojs",
6
6
  "license": "MIT",