@constela/start 0.1.2 → 0.2.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.
@@ -1,8 +1,41 @@
1
+ import { CompiledProgram } from '@constela/compiler';
2
+ import { AppInstance } from '@constela/runtime';
3
+
1
4
  /**
2
5
  * Client-side entry point for Constela applications
3
- * Handles hydration and client-side routing
6
+ * Handles hydration and Escape Hatch mechanism for external library integration.
7
+ */
8
+
9
+ /**
10
+ * Context provided to EscapeHandler mount functions
11
+ */
12
+ interface EscapeContext {
13
+ appInstance: AppInstance;
14
+ getState: (name: string) => unknown;
15
+ setState: (name: string, value: unknown) => void;
16
+ subscribe: (name: string, fn: (value: unknown) => void) => () => void;
17
+ }
18
+ /**
19
+ * Handler for escape hatch elements
20
+ */
21
+ interface EscapeHandler {
22
+ name: string;
23
+ mount: (element: HTMLElement, ctx: EscapeContext) => () => void;
24
+ }
25
+ /**
26
+ * Options for initializing the client application
27
+ */
28
+ interface InitClientOptions {
29
+ program: CompiledProgram;
30
+ container: HTMLElement;
31
+ escapeHandlers?: EscapeHandler[];
32
+ }
33
+ /**
34
+ * Initialize the client application with hydration and escape hatch support.
35
+ *
36
+ * @param options - Configuration options
37
+ * @returns AppInstance for controlling the application
4
38
  */
5
- declare function hydrate(): void;
6
- declare function mount(_element: HTMLElement): void;
39
+ declare function initClient(options: InitClientOptions): AppInstance;
7
40
 
8
- export { hydrate, mount };
41
+ export { type EscapeContext, type EscapeHandler, type InitClientOptions, initClient };
@@ -1,11 +1,58 @@
1
1
  // src/runtime/entry-client.ts
2
- function hydrate() {
3
- throw new Error("hydrate is not yet implemented");
4
- }
5
- function mount(_element) {
6
- throw new Error("mount is not yet implemented");
2
+ import { hydrateApp } from "@constela/runtime";
3
+ function initClient(options) {
4
+ const { program, container, escapeHandlers = [] } = options;
5
+ const appInstance = hydrateApp({ program, container });
6
+ const escapeElements = container.querySelectorAll(
7
+ "[data-constela-escape]"
8
+ );
9
+ const handlerMap = /* @__PURE__ */ new Map();
10
+ for (const handler of escapeHandlers) {
11
+ handlerMap.set(handler.name, handler);
12
+ }
13
+ const cleanupFns = [];
14
+ for (const element of escapeElements) {
15
+ const escapeName = element.getAttribute("data-constela-escape") ?? "";
16
+ const handler = handlerMap.get(escapeName);
17
+ if (!handler) {
18
+ continue;
19
+ }
20
+ const escapeContext = {
21
+ appInstance,
22
+ getState: (name) => appInstance.getState(name),
23
+ setState: (name, value) => appInstance.setState(name, value),
24
+ subscribe: (name, fn) => {
25
+ if (typeof appInstance.subscribe === "function") {
26
+ return appInstance.subscribe(name, fn);
27
+ }
28
+ return () => {
29
+ };
30
+ }
31
+ };
32
+ try {
33
+ const cleanup = handler.mount(element, escapeContext);
34
+ cleanupFns.push(cleanup);
35
+ } catch {
36
+ }
37
+ }
38
+ let destroyed = false;
39
+ return {
40
+ destroy() {
41
+ if (destroyed) return;
42
+ destroyed = true;
43
+ for (const cleanup of cleanupFns) {
44
+ cleanup();
45
+ }
46
+ appInstance.destroy();
47
+ },
48
+ setState(name, value) {
49
+ appInstance.setState(name, value);
50
+ },
51
+ getState(name) {
52
+ return appInstance.getState(name);
53
+ }
54
+ };
7
55
  }
8
56
  export {
9
- hydrate,
10
- mount
57
+ initClient
11
58
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constela/start",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Meta-framework for Constela applications",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -34,10 +34,15 @@
34
34
  "vite": "^6.0.0",
35
35
  "commander": "^12.0.0",
36
36
  "fast-glob": "^3.3.0",
37
+ "unified": "^11.0.0",
38
+ "remark-parse": "^11.0.0",
39
+ "remark-mdx": "^3.0.0",
40
+ "remark-gfm": "^4.0.0",
41
+ "gray-matter": "^4.0.0",
42
+ "@constela/runtime": "0.7.0",
43
+ "@constela/router": "4.0.0",
37
44
  "@constela/compiler": "0.4.0",
38
- "@constela/server": "0.1.2",
39
- "@constela/router": "3.0.0",
40
- "@constela/runtime": "0.6.0"
45
+ "@constela/server": "0.1.2"
41
46
  },
42
47
  "devDependencies": {
43
48
  "typescript": "^5.3.0",