@coherent.js/client 1.0.0-beta.8 → 1.0.0-rc.2
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/index.js +2122 -931
- package/dist/index.js.map +4 -4
- package/package.json +2 -6
- package/src/index.js +1 -10
- package/types/index.d.ts +0 -53
- package/dist/client/hmr.d.ts +0 -1
- package/dist/client/hmr.d.ts.map +0 -1
- package/dist/client/hmr.js +0 -107
- package/dist/client/hmr.js.map +0 -1
- package/dist/client/hydration.d.ts +0 -55
- package/dist/client/hydration.d.ts.map +0 -1
- package/dist/client/hydration.js +0 -1593
- package/dist/client/hydration.js.map +0 -1
- package/types/hydration.d.ts +0 -66
package/types/index.d.ts
CHANGED
|
@@ -690,56 +690,6 @@ export function hydrate(
|
|
|
690
690
|
options?: HydrationOptions
|
|
691
691
|
): HydrateControl;
|
|
692
692
|
|
|
693
|
-
/**
|
|
694
|
-
* Hydrate a single element (legacy API).
|
|
695
|
-
* @deprecated Use the clean hydrate() API instead.
|
|
696
|
-
*/
|
|
697
|
-
export function legacyHydrate(
|
|
698
|
-
element: HTMLElement,
|
|
699
|
-
component: CoherentComponent,
|
|
700
|
-
props?: Record<string, any>,
|
|
701
|
-
options?: { initialState?: SerializableState }
|
|
702
|
-
): HydratedInstance | null;
|
|
703
|
-
|
|
704
|
-
/** Hydrate multiple elements */
|
|
705
|
-
export function hydrateAll(
|
|
706
|
-
elements: HTMLElement[],
|
|
707
|
-
components: CoherentComponent[],
|
|
708
|
-
propsArray?: Array<Record<string, any>>
|
|
709
|
-
): Array<HydratedInstance | null>;
|
|
710
|
-
|
|
711
|
-
export function hydrateBySelector(
|
|
712
|
-
selector: string,
|
|
713
|
-
component: CoherentComponent,
|
|
714
|
-
props?: Record<string, any>
|
|
715
|
-
): Array<HydratedInstance | null>;
|
|
716
|
-
|
|
717
|
-
export function enableClientEvents(rootElement?: Document | HTMLElement): void;
|
|
718
|
-
|
|
719
|
-
export function makeHydratable<T extends CoherentComponent>(
|
|
720
|
-
component: T,
|
|
721
|
-
options?: MakeHydratableOptions
|
|
722
|
-
): T & {
|
|
723
|
-
isHydratable: true;
|
|
724
|
-
hydrationOptions: MakeHydratableOptions;
|
|
725
|
-
autoHydrate(componentRegistry?: Record<string, any>): void;
|
|
726
|
-
getHydrationData(props?: Record<string, any>, state?: SerializableState | null): {
|
|
727
|
-
componentName: string;
|
|
728
|
-
props: Record<string, any>;
|
|
729
|
-
initialState?: SerializableState;
|
|
730
|
-
hydrationAttributes: Record<string, string | null>;
|
|
731
|
-
};
|
|
732
|
-
renderWithHydration(props?: Record<string, any>): CoherentNode;
|
|
733
|
-
};
|
|
734
|
-
|
|
735
|
-
/** Auto-hydrate elements on DOM ready */
|
|
736
|
-
export function autoHydrate(componentRegistry?: Record<string, CoherentComponent>): void;
|
|
737
|
-
|
|
738
|
-
export function registerEventHandler<S = any, E extends Event = Event>(
|
|
739
|
-
id: string,
|
|
740
|
-
handler: StateAwareHandler<S, E>
|
|
741
|
-
): void;
|
|
742
|
-
|
|
743
693
|
/** Register a component for auto-hydration */
|
|
744
694
|
declare function registerComponent(
|
|
745
695
|
name: string,
|
|
@@ -934,9 +884,6 @@ declare const coherentClient: {
|
|
|
934
884
|
// Hydration
|
|
935
885
|
extractInitialState: typeof extractInitialState;
|
|
936
886
|
hydrate: typeof hydrate;
|
|
937
|
-
legacyHydrate: typeof legacyHydrate;
|
|
938
|
-
hydrateAll: typeof hydrateAll;
|
|
939
|
-
autoHydrate: typeof autoHydrate;
|
|
940
887
|
|
|
941
888
|
// Component registration
|
|
942
889
|
registerComponent: typeof registerComponent;
|
package/dist/client/hmr.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=hmr.d.ts.map
|
package/dist/client/hmr.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hmr.d.ts","sourceRoot":"","sources":["../../../../src/client/hmr.js"],"names":[],"mappings":""}
|
package/dist/client/hmr.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Coherent.js HMR Client
|
|
4
|
-
* Auto-connects to the dev server and applies updates.
|
|
5
|
-
*/
|
|
6
|
-
(function initHMR() {
|
|
7
|
-
if (typeof window === 'undefined')
|
|
8
|
-
return;
|
|
9
|
-
if (window.__coherent_hmr_initialized)
|
|
10
|
-
return;
|
|
11
|
-
window.__coherent_hmr_initialized = true;
|
|
12
|
-
const log = (...args) => console.log('[Coherent HMR]', ...args);
|
|
13
|
-
const warn = (...args) => console.warn('[Coherent HMR]', ...args);
|
|
14
|
-
const _error = (...args) => console.error('[Coherent HMR]', ...args);
|
|
15
|
-
let hadDisconnect = false;
|
|
16
|
-
function connect() {
|
|
17
|
-
try {
|
|
18
|
-
const protocol = location.protocol === 'https:' ? 'wss' : 'ws';
|
|
19
|
-
const wsUrl = `${protocol}://${location.host}`;
|
|
20
|
-
const ws = new WebSocket(wsUrl);
|
|
21
|
-
ws.addEventListener('open', () => {
|
|
22
|
-
log('connected');
|
|
23
|
-
ws.send(JSON.stringify({ type: 'connected' }));
|
|
24
|
-
// If the server was restarted, ensure the page HTML is refreshed automatically
|
|
25
|
-
if (hadDisconnect) {
|
|
26
|
-
log('reconnected, reloading page');
|
|
27
|
-
setTimeout(() => location.reload(), 200);
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
ws.addEventListener('close', () => {
|
|
32
|
-
hadDisconnect = true;
|
|
33
|
-
warn('disconnected, retrying in 1s...');
|
|
34
|
-
setTimeout(connect, 1000);
|
|
35
|
-
});
|
|
36
|
-
ws.addEventListener('error', (e) => {
|
|
37
|
-
error('socket error', e);
|
|
38
|
-
try {
|
|
39
|
-
ws.close();
|
|
40
|
-
}
|
|
41
|
-
catch { }
|
|
42
|
-
});
|
|
43
|
-
ws.addEventListener('message', async (evt) => {
|
|
44
|
-
let data;
|
|
45
|
-
try {
|
|
46
|
-
data = JSON.parse(evt.data);
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
log('message', data.type, data.filePath || data.webPath || '');
|
|
52
|
-
switch (data.type) {
|
|
53
|
-
case 'connected':
|
|
54
|
-
break;
|
|
55
|
-
case 'hmr-full-reload':
|
|
56
|
-
case 'reload':
|
|
57
|
-
warn('server requested full reload');
|
|
58
|
-
location.reload();
|
|
59
|
-
return;
|
|
60
|
-
case 'preview-update':
|
|
61
|
-
// No-op here; dashboard uses this for live preview panes
|
|
62
|
-
break;
|
|
63
|
-
case 'hmr-component-update':
|
|
64
|
-
case 'hmr-update':
|
|
65
|
-
await handleUpdate(data);
|
|
66
|
-
break;
|
|
67
|
-
default:
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
catch {
|
|
73
|
-
// Ignore errors in non-browser environments
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
async function handleUpdate(msg) {
|
|
77
|
-
const filePath = msg.webPath || msg.filePath || '';
|
|
78
|
-
const ts = Date.now();
|
|
79
|
-
// Try to re-import changed module to refresh side effects/registrations
|
|
80
|
-
try {
|
|
81
|
-
// Prefer absolute path from dev-server, otherwise attempt as-is
|
|
82
|
-
const importPath = filePath.startsWith('/') ? filePath : `/${filePath}`;
|
|
83
|
-
await import(`${importPath}?t=${ts}`);
|
|
84
|
-
log('updated', msg.updateType || 'module', filePath);
|
|
85
|
-
}
|
|
86
|
-
catch (err) {
|
|
87
|
-
warn('module re-import failed, attempting soft hydrate', filePath, err);
|
|
88
|
-
}
|
|
89
|
-
// Attempt to re-hydrate if available
|
|
90
|
-
try {
|
|
91
|
-
const { autoHydrate } = await import('/src/client/hydration.js');
|
|
92
|
-
// If examples register a component registry on window, prefer targeted hydrate
|
|
93
|
-
if (window.componentRegistry) {
|
|
94
|
-
autoHydrate(window.componentRegistry);
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
autoHydrate();
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
catch {
|
|
101
|
-
warn('autoHydrate failed; falling back to full reload');
|
|
102
|
-
location.reload();
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
connect();
|
|
106
|
-
})();
|
|
107
|
-
//# sourceMappingURL=hmr.js.map
|
package/dist/client/hmr.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hmr.js","sourceRoot":"","sources":["../../../../src/client/hmr.js"],"names":[],"mappings":";AAAA;;;GAGG;AAEH,CAAC,SAAS,OAAO;IACf,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO;IAC1C,IAAI,MAAM,CAAC,0BAA0B;QAAE,OAAO;IAC9C,MAAM,CAAC,0BAA0B,GAAG,IAAI,CAAC;IAEzC,MAAM,GAAG,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,GAAG,IAAI,CAAC,CAAC;IAChE,MAAM,IAAI,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,GAAG,IAAI,CAAC,CAAC;IAClE,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,gBAAgB,EAAE,GAAG,IAAI,CAAC,CAAC;IAEpE,IAAI,aAAa,GAAG,KAAK,CAAC;IAE1B,SAAS,OAAO;QACd,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;YAC/D,MAAM,KAAK,GAAG,GAAG,QAAQ,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YAC/C,MAAM,EAAE,GAAG,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC;YAEhC,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E,IAAI,MAAM,CAAC,iBAAiB,EAAE,CAAC;gBAC7B,WAAW,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;YACxC,CAAC;iBAAM,CAAC;gBACN,WAAW,EAAE,CAAC;YAChB,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,IAAI,CAAC,iDAAiD,CAAC,CAAC;YACxD,QAAQ,CAAC,MAAM,EAAE,CAAC;QACpB,CAAC;IACH,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC,EAAE,CAAC"}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Register an event handler for later use
|
|
3
|
-
* @param {string} id - Unique identifier for the event handler
|
|
4
|
-
* @param {Function} handler - The event handler function
|
|
5
|
-
*/
|
|
6
|
-
export function registerEventHandler(id: string, handler: Function): void;
|
|
7
|
-
/**
|
|
8
|
-
* Hydrate a DOM element with a Coherent component
|
|
9
|
-
*
|
|
10
|
-
* @param {HTMLElement} element - The DOM element to hydrate
|
|
11
|
-
* @param {Function} component - The Coherent component function
|
|
12
|
-
* @param {Object} props - The props to pass to the component
|
|
13
|
-
* @param {Object} options - Hydration options
|
|
14
|
-
* @returns {Object} The hydrated component instance
|
|
15
|
-
*/
|
|
16
|
-
export function hydrate(element: HTMLElement, component: Function, props?: Object, options?: Object): Object;
|
|
17
|
-
/**
|
|
18
|
-
* Hydrate multiple elements with their corresponding components
|
|
19
|
-
*
|
|
20
|
-
* @param {Array} elements - Array of DOM elements to hydrate
|
|
21
|
-
* @param {Array} components - Array of Coherent component functions
|
|
22
|
-
* @param {Array} propsArray - Array of props for each component
|
|
23
|
-
* @returns {Array} Array of hydrated component instances
|
|
24
|
-
*/
|
|
25
|
-
export function hydrateAll(elements: any[], components: any[], propsArray?: any[]): any[];
|
|
26
|
-
/**
|
|
27
|
-
* Find and hydrate elements by CSS selector
|
|
28
|
-
*
|
|
29
|
-
* @param {string} selector - CSS selector to find elements
|
|
30
|
-
* @param {Function} component - The Coherent component function
|
|
31
|
-
* @param {Object} props - The props to pass to the component
|
|
32
|
-
* @returns {Array} Array of hydrated component instances
|
|
33
|
-
*/
|
|
34
|
-
export function hydrateBySelector(selector: string, component: Function, props?: Object): any[];
|
|
35
|
-
/**
|
|
36
|
-
* Enable client-side interactivity for event handlers
|
|
37
|
-
*
|
|
38
|
-
* @param {HTMLElement} rootElement - The root element to enable events on
|
|
39
|
-
*/
|
|
40
|
-
export function enableClientEvents(rootElement?: HTMLElement): void;
|
|
41
|
-
/**
|
|
42
|
-
* Create a hydratable component
|
|
43
|
-
*
|
|
44
|
-
* @param {Function} component - The Coherent component function
|
|
45
|
-
* @param {Object} options - Hydration options
|
|
46
|
-
* @returns {Function} A component that can be hydrated
|
|
47
|
-
*/
|
|
48
|
-
export function makeHydratable(component: Function, options?: Object): Function;
|
|
49
|
-
/**
|
|
50
|
-
* Auto-hydrate all components on page load
|
|
51
|
-
*
|
|
52
|
-
* @param {Object} componentRegistry - Registry of component functions
|
|
53
|
-
*/
|
|
54
|
-
export function autoHydrate(componentRegistry?: Object): void;
|
|
55
|
-
//# sourceMappingURL=hydration.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hydration.d.ts","sourceRoot":"","sources":["../../../../src/client/hydration.js"],"names":[],"mappings":"AAomBA;;;;GAIG;AACH,yCAHW,MAAM,2BAKhB;AA/hBD;;;;;;;;GAQG;AACH,iCANW,WAAW,+BAEX,MAAM,YACN,MAAM,GACJ,MAAM,CA4gBlB;AA44BD;;;;;;;GAOG;AACH,0FAUC;AAED;;;;;;;GAOG;AACH,4CALW,MAAM,+BAEN,MAAM,SAUhB;AAED;;;;GAIG;AACH,iDAFW,WAAW,QAUrB;AAED;;;;;;GAMG;AACH,8DAHW,MAAM,YAsIhB;AAED;;;;GAIG;AACH,gDAFW,MAAM,QAgFhB"}
|