@webjsdev/core 0.7.41 → 0.7.42

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webjsdev/core",
3
- "version": "0.7.41",
3
+ "version": "0.7.42",
4
4
  "type": "module",
5
5
  "description": "webjs core runtime - html/css tags, WebComponent base, isomorphic renderers",
6
6
  "types": "./index.d.ts",
@@ -72,25 +72,15 @@ export interface ReactiveController {
72
72
  * See the Editor Setup doc for tooling that gives attribute/tag
73
73
  * intelligence inside `html\`…\`` templates.
74
74
  */
75
- abstract class WebComponentBase extends HTMLElement {
76
- static shadow: boolean;
77
- static hydrate: 'visible' | undefined;
78
- /** @internal Populated by the `WebComponent({ … })` factory, not by hand. */
79
- static properties: Record<string, PropertyDeclaration>;
80
- static styles: CSSResult | CSSResult[] | null;
81
- static lazy?: boolean;
82
- /**
83
- * Force this component to ship (hydrate) even when the elision analyser would
84
- * drop it as display-only. The escape hatch for interactivity the analyser
85
- * cannot see statically: a dynamically-computed tag string, or a `:defined`
86
- * rule in an external stylesheet outside the module graph. Leave unset for
87
- * the automatic verdict.
88
- */
89
- static interactive?: boolean;
90
- /** Register this class as a custom element under `tag`. Tag must contain a hyphen. */
91
- static register(tag: string): void;
92
- static readonly observedAttributes: string[];
93
-
75
+ // An INTERFACE, not an `abstract class`, on purpose. A class is a value as well
76
+ // as a type, and a non-exported class referenced from exported positions
77
+ // (`new (): WebComponentBase`, `export type WebComponent = WebComponentBase`)
78
+ // still leaks into the module's VALUE namespace, so `import { WebComponentBase }
79
+ // from '@webjsdev/core'` type-checks and then crashes at load because the runtime
80
+ // never exports it (#1032). An interface has no value meaning, so it describes the
81
+ // instance shape without becoming a phantom export. The static surface lives on
82
+ // `WebComponentStatics` / `WebComponentConstructor` below.
83
+ interface WebComponentBase extends HTMLElement {
94
84
  /**
95
85
  * Schedule a re-render. Optionally record a property change so lifecycle
96
86
  * hooks can branch on what changed via `changedProperties`.
@@ -167,6 +157,14 @@ interface WebComponentStatics {
167
157
  properties: Record<string, PropertyDeclaration>;
168
158
  styles: CSSResult | CSSResult[] | null;
169
159
  lazy?: boolean;
160
+ /**
161
+ * Force this component to ship (hydrate) even when the elision analyser would
162
+ * drop it as display-only. The escape hatch for interactivity the analyser
163
+ * cannot see statically: a dynamically-computed tag string, or a `:defined`
164
+ * rule in an external stylesheet outside the module graph. Leave unset for
165
+ * the automatic verdict.
166
+ */
167
+ interactive?: boolean;
170
168
  register(tag: string): void;
171
169
  readonly observedAttributes: string[];
172
170
  }
@@ -181,6 +179,21 @@ export interface WebComponentConstructor extends WebComponentStatics {
181
179
  };
182
180
  }
183
181
 
182
+ /**
183
+ * A constructor for a registered component: the static surface plus a plain
184
+ * `new ()`, WITHOUT the factory call signature that `WebComponentConstructor`
185
+ * carries. That call signature is what the `WebComponent` const needs (it is
186
+ * both a class and a factory), but it means no ordinary component class is
187
+ * assignable to `WebComponentConstructor` (a plain class is not callable as a
188
+ * factory). So the standalone `register(tag, cls)` / `lookup` / `tagOf` surface
189
+ * types against THIS instead, and a user's `class X extends WebComponent({…})`
190
+ * satisfies it (#1033).
191
+ */
192
+ export interface WebComponentInstanceConstructor extends WebComponentStatics {
193
+ new (): WebComponentBase;
194
+ prototype: WebComponentBase;
195
+ }
196
+
184
197
  export declare const WebComponent: WebComponentConstructor;
185
198
 
186
199
  export declare function prop<C extends PropertyConstructor<any>>(
package/src/registry.d.ts CHANGED
@@ -1,11 +1,17 @@
1
- import type { WebComponent } from './component.js';
1
+ import type { WebComponentConstructor, WebComponentInstanceConstructor } from './component.js';
2
2
 
3
- export type WebComponentConstructor = typeof WebComponent;
3
+ // Re-exported for `@webjsdev/core/registry` consumers; it is the type of the
4
+ // `WebComponent` const itself (class + factory dual).
5
+ export type { WebComponentConstructor };
4
6
 
5
- export function register(tag: string, cls: WebComponentConstructor): void;
7
+ // `register` / `lookup` / `tagOf` deal in ordinary component classes, which are
8
+ // NOT assignable to the class+factory `WebComponentConstructor` (a plain class is
9
+ // not callable as a factory). They type against the instance-constructor shape so
10
+ // a user's `class X extends WebComponent({…})` is accepted (#1033).
11
+ export function register(tag: string, cls: WebComponentInstanceConstructor): void;
6
12
  export function primeModuleUrl(tag: string, moduleUrl: string): void;
7
- export function lookup(tag: string): WebComponentConstructor | undefined;
13
+ export function lookup(tag: string): WebComponentInstanceConstructor | undefined;
8
14
  export function lookupModuleUrl(tag: string): string | undefined;
9
15
  export function isLazy(tag: string): boolean;
10
- export function tagOf(cls: WebComponentConstructor): string | undefined;
16
+ export function tagOf(cls: WebComponentInstanceConstructor): string | undefined;
11
17
  export function allTags(): string[];