@hypen-space/core 0.3.12 → 0.4.0
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/app.js +7 -3
- package/dist/app.js.map +3 -3
- package/dist/components/builtin.js +7 -3
- package/dist/components/builtin.js.map +3 -3
- package/dist/discovery.js +8 -7
- package/dist/discovery.js.map +4 -4
- package/dist/engine.browser.js.map +2 -2
- package/dist/engine.js +3 -7
- package/dist/engine.js.map +3 -3
- package/dist/index.browser.js +242 -371
- package/dist/index.browser.js.map +8 -9
- package/dist/index.js +546 -656
- package/dist/index.js.map +12 -13
- package/dist/remote/client.js.map +1 -1
- package/dist/remote/index.js +336 -336
- package/dist/remote/index.js.map +8 -8
- package/dist/remote/server.js +219 -219
- package/dist/remote/server.js.map +7 -7
- package/dist/renderer.js.map +1 -1
- package/dist/resolver.js +31 -4
- package/dist/resolver.js.map +3 -3
- package/package.json +7 -1
- package/src/app.ts +14 -2
- package/src/discovery.ts +3 -1
- package/src/engine.browser.ts +4 -32
- package/src/engine.ts +8 -44
- package/src/index.browser.ts +6 -4
- package/src/index.ts +6 -6
- package/src/managed-router.ts +195 -0
- package/src/module-registry.ts +76 -0
- package/src/remote/client.ts +1 -1
- package/src/remote/index.ts +2 -2
- package/src/remote/server.ts +1 -1
- package/src/remote/types.ts +1 -1
- package/src/renderer.ts +1 -1
- package/src/resolver.ts +56 -9
- package/src/types.ts +38 -0
- package/wasm-browser/README.md +7 -1
- package/wasm-browser/hypen_engine.d.ts +1 -0
- package/wasm-browser/hypen_engine.js +1 -0
- package/wasm-browser/hypen_engine_bg.wasm +0 -0
- package/wasm-browser/package.json +1 -1
- package/wasm-node/README.md +7 -1
- package/wasm-node/hypen_engine.d.ts +1 -0
- package/wasm-node/hypen_engine.js +1 -0
- package/wasm-node/hypen_engine_bg.wasm +0 -0
- package/wasm-node/package.json +1 -1
package/src/remote/server.ts
CHANGED
|
@@ -44,7 +44,7 @@ import type {
|
|
|
44
44
|
Session,
|
|
45
45
|
SessionConfig,
|
|
46
46
|
} from "./types.js";
|
|
47
|
-
import type { Patch } from "../
|
|
47
|
+
import type { Patch } from "../types.js";
|
|
48
48
|
import type { ServerWebSocket } from "bun";
|
|
49
49
|
import { SessionManager } from "./session.js";
|
|
50
50
|
import { frameworkLoggers } from "../logger.js";
|
package/src/remote/types.ts
CHANGED
package/src/renderer.ts
CHANGED
package/src/resolver.ts
CHANGED
|
@@ -39,6 +39,12 @@ export interface ResolverOptions {
|
|
|
39
39
|
* Useful for adding authentication, custom headers, etc.
|
|
40
40
|
*/
|
|
41
41
|
customFetch?: (url: string) => Promise<string>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Module registry for looking up pre-registered module definitions.
|
|
45
|
+
* When set, the resolver will check the registry before doing file I/O.
|
|
46
|
+
*/
|
|
47
|
+
moduleRegistry?: { has: (name: string) => boolean; get: (name: string) => any };
|
|
42
48
|
}
|
|
43
49
|
|
|
44
50
|
/**
|
|
@@ -47,22 +53,48 @@ export interface ResolverOptions {
|
|
|
47
53
|
*/
|
|
48
54
|
export class ComponentResolver {
|
|
49
55
|
private cache = new Map<string, ComponentDefinition>();
|
|
50
|
-
private options: Required<ResolverOptions>;
|
|
56
|
+
private options: Required<Pick<ResolverOptions, 'baseDir' | 'cache' | 'customFetch'>> & Pick<ResolverOptions, 'moduleRegistry'>;
|
|
57
|
+
|
|
58
|
+
private moduleRegistry?: { has: (name: string) => boolean; get: (name: string) => any };
|
|
51
59
|
|
|
52
60
|
constructor(options: ResolverOptions = {}) {
|
|
53
61
|
this.options = {
|
|
54
62
|
baseDir: options.baseDir || process.cwd(),
|
|
55
63
|
cache: options.cache ?? true,
|
|
56
64
|
customFetch: options.customFetch || this.defaultFetch.bind(this),
|
|
65
|
+
moduleRegistry: options.moduleRegistry,
|
|
57
66
|
};
|
|
67
|
+
this.moduleRegistry = options.moduleRegistry;
|
|
58
68
|
}
|
|
59
69
|
|
|
60
70
|
/**
|
|
61
|
-
* Resolve a component from an import statement
|
|
71
|
+
* Resolve a component from an import statement.
|
|
72
|
+
* Checks the module registry first (if available), then falls back to file I/O.
|
|
62
73
|
*/
|
|
63
74
|
async resolve(
|
|
64
75
|
importStmt: ImportStatement
|
|
65
76
|
): Promise<Record<string, ComponentDefinition>> {
|
|
77
|
+
// Check module registry first — if a component is pre-registered,
|
|
78
|
+
// use its template directly (it will be mounted as a full module)
|
|
79
|
+
if (this.moduleRegistry) {
|
|
80
|
+
const names = importStmt.clause.type === "named"
|
|
81
|
+
? importStmt.clause.names
|
|
82
|
+
: [importStmt.clause.name];
|
|
83
|
+
|
|
84
|
+
const allFound = names.every(name => this.moduleRegistry!.has(name));
|
|
85
|
+
if (allFound) {
|
|
86
|
+
const result: Record<string, ComponentDefinition> = {};
|
|
87
|
+
for (const name of names) {
|
|
88
|
+
const def = this.moduleRegistry!.get(name);
|
|
89
|
+
result[name] = {
|
|
90
|
+
module: def,
|
|
91
|
+
template: def?.template || "",
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
66
98
|
const sourcePath = this.getSourcePath(importStmt.source);
|
|
67
99
|
|
|
68
100
|
// Check cache first
|
|
@@ -91,13 +123,28 @@ export class ComponentResolver {
|
|
|
91
123
|
* Resolve a component from a local file path
|
|
92
124
|
*/
|
|
93
125
|
private async resolveLocal(path: string): Promise<ComponentDefinition> {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
)
|
|
126
|
+
const { resolve, join } = await import("path");
|
|
127
|
+
const { readFile } = await import("fs/promises");
|
|
128
|
+
|
|
129
|
+
const basePath = resolve(this.options.baseDir, path);
|
|
130
|
+
|
|
131
|
+
// Try .hypen extension
|
|
132
|
+
const hypenPath = basePath.endsWith(".hypen")
|
|
133
|
+
? basePath
|
|
134
|
+
: `${basePath}.hypen`;
|
|
135
|
+
|
|
136
|
+
const template = await readFile(hypenPath, "utf-8");
|
|
137
|
+
|
|
138
|
+
// Try loading sibling .ts module (stateless components have no module)
|
|
139
|
+
const modulePath = hypenPath.replace(/\.hypen$/, ".ts");
|
|
140
|
+
let module = {};
|
|
141
|
+
try {
|
|
142
|
+
module = await import(modulePath);
|
|
143
|
+
} catch {
|
|
144
|
+
// Stateless component — no module file
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return { module, template };
|
|
101
148
|
}
|
|
102
149
|
|
|
103
150
|
/**
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types shared across the engine and runtime.
|
|
3
|
+
*
|
|
4
|
+
* These types are intentionally decoupled from the WASM engine so that
|
|
5
|
+
* packages can import them without pulling in any WASM code.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export type Patch = {
|
|
9
|
+
type: "create" | "setProp" | "setText" | "insert" | "move" | "remove" | "attachEvent" | "detachEvent";
|
|
10
|
+
id?: string;
|
|
11
|
+
elementType?: string;
|
|
12
|
+
props?: Record<string, any>;
|
|
13
|
+
name?: string;
|
|
14
|
+
value?: any;
|
|
15
|
+
text?: string;
|
|
16
|
+
parentId?: string;
|
|
17
|
+
beforeId?: string;
|
|
18
|
+
eventName?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type Action = {
|
|
22
|
+
name: string;
|
|
23
|
+
payload?: any;
|
|
24
|
+
sender?: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type RenderCallback = (patches: Patch[]) => void;
|
|
28
|
+
export type ActionHandler = (action: Action) => void | Promise<void>;
|
|
29
|
+
|
|
30
|
+
export type ResolvedComponent = {
|
|
31
|
+
source: string;
|
|
32
|
+
path: string;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export type ComponentResolver = (
|
|
36
|
+
componentName: string,
|
|
37
|
+
contextPath: string | null
|
|
38
|
+
) => ResolvedComponent | null;
|
package/wasm-browser/README.md
CHANGED
|
@@ -583,6 +583,12 @@ pub use state::StateChange;
|
|
|
583
583
|
|
|
584
584
|
## Related Documentation
|
|
585
585
|
|
|
586
|
+
- [Documentation Index](./docs/README.md) - Full documentation index
|
|
587
|
+
- [Control Flow Components](./docs/control-flow.md) - ForEach, When/If, Map usage guide
|
|
588
|
+
- [Router](./docs/router.md) - Declarative routing and navigation
|
|
589
|
+
- [Architecture Internals](./docs/architecture.md) - Reactive system, reconciliation, IR
|
|
590
|
+
- [Advanced SDK Usage](./docs/advanced-sdk-usage.md) - Custom renderers, component resolvers, Remote UI
|
|
591
|
+
- [Glossary](./docs/glossary.md) - Key terms and binding syntax reference
|
|
592
|
+
- [Browser Compatibility](./docs/browser-compatibility.md) - Browser, platform, and WASM target support
|
|
586
593
|
- [BUILD_WASM.md](./BUILD_WASM.md) - Detailed WASM build instructions
|
|
587
594
|
- [../parser/README.md](../parser/README.md) - Hypen parser documentation
|
|
588
|
-
- [../hypen-render-bun/README.md](../hypen-render-bun/README.md) - Bun renderer implementation
|
|
Binary file
|
package/wasm-node/README.md
CHANGED
|
@@ -583,6 +583,12 @@ pub use state::StateChange;
|
|
|
583
583
|
|
|
584
584
|
## Related Documentation
|
|
585
585
|
|
|
586
|
+
- [Documentation Index](./docs/README.md) - Full documentation index
|
|
587
|
+
- [Control Flow Components](./docs/control-flow.md) - ForEach, When/If, Map usage guide
|
|
588
|
+
- [Router](./docs/router.md) - Declarative routing and navigation
|
|
589
|
+
- [Architecture Internals](./docs/architecture.md) - Reactive system, reconciliation, IR
|
|
590
|
+
- [Advanced SDK Usage](./docs/advanced-sdk-usage.md) - Custom renderers, component resolvers, Remote UI
|
|
591
|
+
- [Glossary](./docs/glossary.md) - Key terms and binding syntax reference
|
|
592
|
+
- [Browser Compatibility](./docs/browser-compatibility.md) - Browser, platform, and WASM target support
|
|
586
593
|
- [BUILD_WASM.md](./BUILD_WASM.md) - Detailed WASM build instructions
|
|
587
594
|
- [../parser/README.md](../parser/README.md) - Hypen parser documentation
|
|
588
|
-
- [../hypen-render-bun/README.md](../hypen-render-bun/README.md) - Bun renderer implementation
|
|
Binary file
|