@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.
Files changed (47) hide show
  1. package/dist/app.js +7 -3
  2. package/dist/app.js.map +3 -3
  3. package/dist/components/builtin.js +7 -3
  4. package/dist/components/builtin.js.map +3 -3
  5. package/dist/discovery.js +8 -7
  6. package/dist/discovery.js.map +4 -4
  7. package/dist/engine.browser.js.map +2 -2
  8. package/dist/engine.js +3 -7
  9. package/dist/engine.js.map +3 -3
  10. package/dist/index.browser.js +242 -371
  11. package/dist/index.browser.js.map +8 -9
  12. package/dist/index.js +546 -656
  13. package/dist/index.js.map +12 -13
  14. package/dist/remote/client.js.map +1 -1
  15. package/dist/remote/index.js +336 -336
  16. package/dist/remote/index.js.map +8 -8
  17. package/dist/remote/server.js +219 -219
  18. package/dist/remote/server.js.map +7 -7
  19. package/dist/renderer.js.map +1 -1
  20. package/dist/resolver.js +31 -4
  21. package/dist/resolver.js.map +3 -3
  22. package/package.json +7 -1
  23. package/src/app.ts +14 -2
  24. package/src/discovery.ts +3 -1
  25. package/src/engine.browser.ts +4 -32
  26. package/src/engine.ts +8 -44
  27. package/src/index.browser.ts +6 -4
  28. package/src/index.ts +6 -6
  29. package/src/managed-router.ts +195 -0
  30. package/src/module-registry.ts +76 -0
  31. package/src/remote/client.ts +1 -1
  32. package/src/remote/index.ts +2 -2
  33. package/src/remote/server.ts +1 -1
  34. package/src/remote/types.ts +1 -1
  35. package/src/renderer.ts +1 -1
  36. package/src/resolver.ts +56 -9
  37. package/src/types.ts +38 -0
  38. package/wasm-browser/README.md +7 -1
  39. package/wasm-browser/hypen_engine.d.ts +1 -0
  40. package/wasm-browser/hypen_engine.js +1 -0
  41. package/wasm-browser/hypen_engine_bg.wasm +0 -0
  42. package/wasm-browser/package.json +1 -1
  43. package/wasm-node/README.md +7 -1
  44. package/wasm-node/hypen_engine.d.ts +1 -0
  45. package/wasm-node/hypen_engine.js +1 -0
  46. package/wasm-node/hypen_engine_bg.wasm +0 -0
  47. package/wasm-node/package.json +1 -1
@@ -44,7 +44,7 @@ import type {
44
44
  Session,
45
45
  SessionConfig,
46
46
  } from "./types.js";
47
- import type { Patch } from "../engine.js";
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";
@@ -2,7 +2,7 @@
2
2
  * Remote UI Protocol Types
3
3
  */
4
4
 
5
- import type { Patch } from "../engine.js";
5
+ import type { Patch } from "../types.js";
6
6
 
7
7
  export type RemoteMessage =
8
8
  | InitialTreeMessage
package/src/renderer.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * (DOM, Canvas, Native, etc.)
6
6
  */
7
7
 
8
- import type { Patch } from "./engine.js";
8
+ import type { Patch } from "./types.js";
9
9
  import { frameworkLoggers } from "./logger.js";
10
10
 
11
11
  const log = frameworkLoggers.renderer;
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
- // For local paths, we expect the build system to have already
95
- // processed them into the generated components file
96
- // This is a fallback for dynamic resolution
97
- throw new Error(
98
- `Dynamic local component resolution not yet implemented: ${path}\n` +
99
- `Please use the build-components.ts script to generate component imports.`
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;
@@ -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
@@ -22,6 +22,7 @@ export class WasmEngine {
22
22
  constructor();
23
23
  /**
24
24
  * Parse and render Hypen DSL source code
25
+ * Supports documents with import statements - imports are resolved via the component resolver
25
26
  */
26
27
  renderSource(source: string): void;
27
28
  /**
@@ -282,6 +282,7 @@ export class WasmEngine {
282
282
  }
283
283
  /**
284
284
  * Parse and render Hypen DSL source code
285
+ * Supports documents with import statements - imports are resolved via the component resolver
285
286
  * @param {string} source
286
287
  */
287
288
  renderSource(source) {
Binary file
@@ -5,7 +5,7 @@
5
5
  "Hypen Contributors"
6
6
  ],
7
7
  "description": "A Rust implementation of the Hypen engine",
8
- "version": "0.3.3",
8
+ "version": "0.4.0",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
@@ -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
@@ -22,6 +22,7 @@ export class WasmEngine {
22
22
  constructor();
23
23
  /**
24
24
  * Parse and render Hypen DSL source code
25
+ * Supports documents with import statements - imports are resolved via the component resolver
25
26
  */
26
27
  renderSource(source: string): void;
27
28
  /**
@@ -276,6 +276,7 @@ class WasmEngine {
276
276
  }
277
277
  /**
278
278
  * Parse and render Hypen DSL source code
279
+ * Supports documents with import statements - imports are resolved via the component resolver
279
280
  * @param {string} source
280
281
  */
281
282
  renderSource(source) {
Binary file
@@ -4,7 +4,7 @@
4
4
  "Hypen Contributors"
5
5
  ],
6
6
  "description": "A Rust implementation of the Hypen engine",
7
- "version": "0.3.3",
7
+ "version": "0.4.0",
8
8
  "license": "MIT",
9
9
  "repository": {
10
10
  "type": "git",