@coherent.js/web-components 1.0.0-beta.5 → 1.0.0-beta.6
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 +2 -2
- package/types/index.d.ts +247 -29
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coherent.js/web-components",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.6",
|
|
4
4
|
"description": "Web Components integration for Coherent.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"author": "Coherent.js Team",
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@coherent.js/core": "1.0.0-beta.
|
|
19
|
+
"@coherent.js/core": "1.0.0-beta.6"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"vitest": "^3.2.4"
|
package/types/index.d.ts
CHANGED
|
@@ -3,19 +3,51 @@
|
|
|
3
3
|
* @module @coherent.js/web-components
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
import type { CoherentNode, CoherentComponent, ComponentState, ComponentProps } from '@coherent.js/core';
|
|
7
7
|
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Web Component Configuration
|
|
10
|
+
// ============================================================================
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Property type constructors
|
|
14
|
+
*/
|
|
15
|
+
export type PropertyType =
|
|
16
|
+
| StringConstructor
|
|
17
|
+
| NumberConstructor
|
|
18
|
+
| BooleanConstructor
|
|
19
|
+
| ObjectConstructor
|
|
20
|
+
| ArrayConstructor;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Property definition for web components
|
|
24
|
+
*/
|
|
25
|
+
export interface PropertyDefinition {
|
|
26
|
+
/** Property type */
|
|
27
|
+
type?: PropertyType;
|
|
28
|
+
/** Default value */
|
|
29
|
+
default?: unknown;
|
|
30
|
+
/** Whether property is required */
|
|
31
|
+
required?: boolean;
|
|
32
|
+
/** Custom validator */
|
|
33
|
+
validator?: (value: unknown) => boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Component options for web component registration
|
|
38
|
+
*/
|
|
8
39
|
export interface ComponentOptions {
|
|
40
|
+
/** Use shadow DOM */
|
|
9
41
|
shadow?: boolean;
|
|
42
|
+
/** Shadow root mode */
|
|
10
43
|
mode?: 'open' | 'closed';
|
|
44
|
+
/** Delegates focus to shadow root */
|
|
11
45
|
delegatesFocus?: boolean;
|
|
46
|
+
/** Attributes to observe */
|
|
12
47
|
observedAttributes?: string[];
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
required?: boolean;
|
|
17
|
-
validator?: (value: any) => boolean;
|
|
18
|
-
}>;
|
|
48
|
+
/** Property definitions */
|
|
49
|
+
props?: Record<string, PropertyDefinition>;
|
|
50
|
+
/** Lifecycle hooks */
|
|
19
51
|
lifecycle?: {
|
|
20
52
|
connected?: () => void;
|
|
21
53
|
disconnected?: () => void;
|
|
@@ -24,19 +56,85 @@ export interface ComponentOptions {
|
|
|
24
56
|
};
|
|
25
57
|
}
|
|
26
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Web component configuration
|
|
61
|
+
*/
|
|
62
|
+
export interface WebComponentConfig {
|
|
63
|
+
/** Custom element tag name (must contain hyphen) */
|
|
64
|
+
tagName: string;
|
|
65
|
+
/** Coherent.js component */
|
|
66
|
+
component: CoherentComponent;
|
|
67
|
+
/** Attributes to observe */
|
|
68
|
+
observedAttributes?: string[];
|
|
69
|
+
/** Use shadow DOM */
|
|
70
|
+
shadow?: boolean | ShadowRootInit;
|
|
71
|
+
/** Styles to apply */
|
|
72
|
+
styles?: string | string[];
|
|
73
|
+
/** Adopted style sheets */
|
|
74
|
+
adoptedStyleSheets?: CSSStyleSheet[];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// ============================================================================
|
|
78
|
+
// Coherent Web Component
|
|
79
|
+
// ============================================================================
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Coherent element constructor
|
|
83
|
+
*/
|
|
27
84
|
export interface CoherentElementConstructor {
|
|
28
85
|
new (): CoherentElement;
|
|
29
86
|
prototype: CoherentElement;
|
|
30
87
|
}
|
|
31
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Coherent web component element interface
|
|
91
|
+
*/
|
|
32
92
|
export interface CoherentElement extends HTMLElement {
|
|
33
|
-
component
|
|
93
|
+
/** The wrapped component */
|
|
94
|
+
component: CoherentComponent;
|
|
95
|
+
/** Component options */
|
|
34
96
|
options: ComponentOptions;
|
|
97
|
+
|
|
98
|
+
/** Render the component */
|
|
35
99
|
render(): void;
|
|
36
|
-
|
|
37
|
-
|
|
100
|
+
|
|
101
|
+
/** Update with new props */
|
|
102
|
+
update(props?: Record<string, unknown>): void;
|
|
103
|
+
|
|
104
|
+
/** Hydrate with server data */
|
|
105
|
+
hydrate(data?: unknown): void;
|
|
38
106
|
}
|
|
39
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Extended coherent web component interface
|
|
110
|
+
*/
|
|
111
|
+
export interface CoherentWebComponent extends HTMLElement {
|
|
112
|
+
/** Component instance reference */
|
|
113
|
+
readonly componentInstance: unknown;
|
|
114
|
+
/** Current props */
|
|
115
|
+
props: Record<string, unknown>;
|
|
116
|
+
/** Current state */
|
|
117
|
+
state: ComponentState;
|
|
118
|
+
|
|
119
|
+
/** Called when element is added to DOM */
|
|
120
|
+
connectedCallback(): void;
|
|
121
|
+
/** Called when element is removed from DOM */
|
|
122
|
+
disconnectedCallback(): void;
|
|
123
|
+
/** Called when an observed attribute changes */
|
|
124
|
+
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
125
|
+
/** Called when element is moved to a new document */
|
|
126
|
+
adoptedCallback(): void;
|
|
127
|
+
|
|
128
|
+
/** Update component state */
|
|
129
|
+
setState(updates: Partial<ComponentState>): void;
|
|
130
|
+
/** Force a re-render */
|
|
131
|
+
forceUpdate(): void;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// ============================================================================
|
|
135
|
+
// Registration Functions
|
|
136
|
+
// ============================================================================
|
|
137
|
+
|
|
40
138
|
/**
|
|
41
139
|
* Define a Coherent.js component as a custom element
|
|
42
140
|
*
|
|
@@ -53,14 +151,14 @@ export interface CoherentElement extends HTMLElement {
|
|
|
53
151
|
*/
|
|
54
152
|
export function defineComponent(
|
|
55
153
|
name: string,
|
|
56
|
-
component:
|
|
154
|
+
component: CoherentComponent | CoherentNode,
|
|
57
155
|
options?: ComponentOptions
|
|
58
156
|
): CoherentElementConstructor;
|
|
59
157
|
|
|
60
158
|
/**
|
|
61
|
-
*
|
|
159
|
+
* Define a web component with full configuration
|
|
62
160
|
*/
|
|
63
|
-
export function
|
|
161
|
+
export function defineWebComponent(config: WebComponentConfig): typeof CoherentWebComponent;
|
|
64
162
|
|
|
65
163
|
/**
|
|
66
164
|
* Register multiple components at once
|
|
@@ -73,7 +171,30 @@ export function integrateWithWebComponents(runtime: any): void;
|
|
|
73
171
|
* });
|
|
74
172
|
* ```
|
|
75
173
|
*/
|
|
76
|
-
export function registerComponents(
|
|
174
|
+
export function registerComponents(
|
|
175
|
+
components: Record<string, CoherentComponent | CoherentNode>,
|
|
176
|
+
options?: ComponentOptions
|
|
177
|
+
): void;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Register web components with full configuration
|
|
181
|
+
*/
|
|
182
|
+
export function registerWebComponents(
|
|
183
|
+
components: Record<string, WebComponentConfig>
|
|
184
|
+
): void;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Create a custom element class from a component
|
|
188
|
+
*/
|
|
189
|
+
export function createCustomElement(
|
|
190
|
+
component: CoherentComponent,
|
|
191
|
+
options?: Partial<WebComponentConfig>
|
|
192
|
+
): typeof CoherentWebComponent;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Integration utilities for web components runtime
|
|
196
|
+
*/
|
|
197
|
+
export function integrateWithWebComponents(runtime: unknown): void;
|
|
77
198
|
|
|
78
199
|
/**
|
|
79
200
|
* Check if a custom element is defined
|
|
@@ -93,19 +214,31 @@ export function upgradeElement(element: Element): void;
|
|
|
93
214
|
/**
|
|
94
215
|
* Create a Coherent.js component from a custom element
|
|
95
216
|
*/
|
|
96
|
-
export function fromCustomElement(element: HTMLElement):
|
|
217
|
+
export function fromCustomElement(element: HTMLElement): CoherentNode;
|
|
218
|
+
|
|
219
|
+
// ============================================================================
|
|
220
|
+
// Property Decorators
|
|
221
|
+
// ============================================================================
|
|
97
222
|
|
|
98
223
|
/**
|
|
99
|
-
*
|
|
224
|
+
* Property declaration for decorators
|
|
100
225
|
*/
|
|
101
226
|
export interface PropertyDeclaration {
|
|
102
|
-
|
|
227
|
+
/** Property type */
|
|
228
|
+
type?: PropertyType;
|
|
229
|
+
/** Sync with attribute */
|
|
103
230
|
attribute?: boolean | string;
|
|
231
|
+
/** Reflect to attribute */
|
|
104
232
|
reflect?: boolean;
|
|
105
|
-
converter
|
|
106
|
-
|
|
233
|
+
/** Custom converter from attribute string */
|
|
234
|
+
converter?: (value: string) => unknown;
|
|
235
|
+
/** Default value */
|
|
236
|
+
default?: unknown;
|
|
107
237
|
}
|
|
108
238
|
|
|
239
|
+
/**
|
|
240
|
+
* Create a property definition
|
|
241
|
+
*/
|
|
109
242
|
export function createProperty(declaration: PropertyDeclaration): PropertyDecorator;
|
|
110
243
|
|
|
111
244
|
/**
|
|
@@ -120,56 +253,141 @@ export function property(declaration?: PropertyDeclaration): PropertyDecorator;
|
|
|
120
253
|
*/
|
|
121
254
|
export function customElement(tagName: string): ClassDecorator;
|
|
122
255
|
|
|
123
|
-
//
|
|
256
|
+
// ============================================================================
|
|
257
|
+
// Event System
|
|
258
|
+
// ============================================================================
|
|
124
259
|
|
|
260
|
+
/**
|
|
261
|
+
* Custom event options
|
|
262
|
+
*/
|
|
125
263
|
export interface EventOptions {
|
|
264
|
+
/** Whether event bubbles */
|
|
126
265
|
bubbles?: boolean;
|
|
266
|
+
/** Whether event is composed (crosses shadow boundary) */
|
|
127
267
|
composed?: boolean;
|
|
268
|
+
/** Whether event is cancelable */
|
|
128
269
|
cancelable?: boolean;
|
|
129
|
-
detail
|
|
270
|
+
/** Event detail data */
|
|
271
|
+
detail?: unknown;
|
|
130
272
|
}
|
|
131
273
|
|
|
274
|
+
/**
|
|
275
|
+
* Create a custom event
|
|
276
|
+
*/
|
|
132
277
|
export function createEvent(type: string, options?: EventOptions): CustomEvent;
|
|
133
|
-
export function dispatchCustomEvent(element: Element, type: string, options?: EventOptions): boolean;
|
|
134
278
|
|
|
135
|
-
|
|
279
|
+
/**
|
|
280
|
+
* Dispatch a custom event on an element
|
|
281
|
+
*/
|
|
282
|
+
export function dispatchCustomEvent(
|
|
283
|
+
element: Element,
|
|
284
|
+
type: string,
|
|
285
|
+
options?: EventOptions
|
|
286
|
+
): boolean;
|
|
136
287
|
|
|
288
|
+
// ============================================================================
|
|
289
|
+
// Slot Utilities
|
|
290
|
+
// ============================================================================
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Slot change event interface
|
|
294
|
+
*/
|
|
137
295
|
export interface SlotChangeEvent extends Event {
|
|
138
296
|
target: HTMLSlotElement;
|
|
139
297
|
}
|
|
140
298
|
|
|
299
|
+
/**
|
|
300
|
+
* Get slotted content
|
|
301
|
+
*/
|
|
141
302
|
export function getSlotContent(element: Element, slotName?: string): Node[];
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Check if slot has content
|
|
306
|
+
*/
|
|
142
307
|
export function hasSlotContent(element: Element, slotName?: string): boolean;
|
|
143
|
-
export function onSlotChange(element: Element, callback: (event: SlotChangeEvent) => void, slotName?: string): () => void;
|
|
144
308
|
|
|
145
|
-
|
|
309
|
+
/**
|
|
310
|
+
* Listen for slot changes
|
|
311
|
+
*/
|
|
312
|
+
export function onSlotChange(
|
|
313
|
+
element: Element,
|
|
314
|
+
callback: (event: SlotChangeEvent) => void,
|
|
315
|
+
slotName?: string
|
|
316
|
+
): () => void;
|
|
146
317
|
|
|
318
|
+
// ============================================================================
|
|
319
|
+
// Shadow DOM Utilities
|
|
320
|
+
// ============================================================================
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Shadow root initialization options
|
|
324
|
+
*/
|
|
147
325
|
export interface ShadowRootInit {
|
|
326
|
+
/** Shadow mode */
|
|
148
327
|
mode: 'open' | 'closed';
|
|
328
|
+
/** Delegates focus */
|
|
149
329
|
delegatesFocus?: boolean;
|
|
330
|
+
/** Slot assignment mode */
|
|
150
331
|
slotAssignment?: 'manual' | 'named';
|
|
151
332
|
}
|
|
152
333
|
|
|
334
|
+
/**
|
|
335
|
+
* Create a shadow root
|
|
336
|
+
*/
|
|
153
337
|
export function createShadowRoot(element: Element, init: ShadowRootInit): ShadowRoot;
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Adopt styles into a shadow root
|
|
341
|
+
*/
|
|
154
342
|
export function adoptStyles(shadowRoot: ShadowRoot, styles: string | CSSStyleSheet[]): void;
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Get an element's shadow root
|
|
346
|
+
*/
|
|
155
347
|
export function getShadowRoot(element: Element): ShadowRoot | null;
|
|
156
348
|
|
|
157
|
-
//
|
|
349
|
+
// ============================================================================
|
|
350
|
+
// Template Utilities
|
|
351
|
+
// ============================================================================
|
|
158
352
|
|
|
353
|
+
/**
|
|
354
|
+
* Create a template element from HTML
|
|
355
|
+
*/
|
|
159
356
|
export function createTemplate(html: string): HTMLTemplateElement;
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Clone a template's content
|
|
360
|
+
*/
|
|
160
361
|
export function cloneTemplate(template: HTMLTemplateElement): DocumentFragment;
|
|
161
|
-
export function renderToTemplate(component: any): HTMLTemplateElement;
|
|
162
362
|
|
|
163
|
-
|
|
363
|
+
/**
|
|
364
|
+
* Render a component to a template
|
|
365
|
+
*/
|
|
366
|
+
export function renderToTemplate(component: CoherentNode): HTMLTemplateElement;
|
|
367
|
+
|
|
368
|
+
// ============================================================================
|
|
369
|
+
// Lifecycle Hooks
|
|
370
|
+
// ============================================================================
|
|
164
371
|
|
|
372
|
+
/**
|
|
373
|
+
* Lifecycle hook definitions
|
|
374
|
+
*/
|
|
165
375
|
export interface LifecycleHooks {
|
|
376
|
+
/** Called when element is added to DOM */
|
|
166
377
|
onConnected?: () => void;
|
|
378
|
+
/** Called when element is removed from DOM */
|
|
167
379
|
onDisconnected?: () => void;
|
|
380
|
+
/** Called when element is moved to new document */
|
|
168
381
|
onAdopted?: () => void;
|
|
382
|
+
/** Called when observed attribute changes */
|
|
169
383
|
onAttributeChanged?: (name: string, oldValue: string | null, newValue: string | null) => void;
|
|
170
|
-
|
|
384
|
+
/** Called when a property changes */
|
|
385
|
+
onPropertyChanged?: (name: string, oldValue: unknown, newValue: unknown) => void;
|
|
171
386
|
}
|
|
172
387
|
|
|
388
|
+
/**
|
|
389
|
+
* Create a lifecycle manager
|
|
390
|
+
*/
|
|
173
391
|
export function createLifecycleManager(hooks: LifecycleHooks): {
|
|
174
392
|
connected(): void;
|
|
175
393
|
disconnected(): void;
|