@lark.js/mvc 0.0.15 → 0.0.17

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 (62) hide show
  1. package/README.md +324 -215
  2. package/dist/chunk-OGPBFCIK.js +105 -0
  3. package/dist/client.d.cts +63 -0
  4. package/dist/client.d.ts +10 -34
  5. package/dist/compiler.cjs +15534 -15854
  6. package/dist/compiler.d.cts +1 -1
  7. package/dist/compiler.d.ts +1 -1
  8. package/dist/compiler.js +15519 -15851
  9. package/dist/devtool.cjs +2617 -4152
  10. package/dist/devtool.d.cts +1 -2
  11. package/dist/devtool.d.ts +1 -2
  12. package/dist/devtool.js +2543 -4159
  13. package/dist/index.cjs +4128 -6008
  14. package/dist/index.d.cts +571 -1291
  15. package/dist/index.d.ts +571 -1291
  16. package/dist/index.js +4058 -5976
  17. package/dist/rspack.cjs +15648 -15935
  18. package/dist/rspack.d.cts +8 -45
  19. package/dist/rspack.d.ts +8 -45
  20. package/dist/rspack.js +15641 -15934
  21. package/dist/runtime.cjs +79 -79
  22. package/dist/runtime.js +19 -85
  23. package/dist/vite.cjs +15841 -15957
  24. package/dist/vite.d.cts +6 -7
  25. package/dist/vite.d.ts +6 -7
  26. package/dist/vite.js +15834 -15955
  27. package/dist/webpack.cjs +15648 -15985
  28. package/dist/webpack.d.cts +5 -33
  29. package/dist/webpack.d.ts +5 -33
  30. package/dist/webpack.js +15641 -15984
  31. package/package.json +3 -4
  32. package/dist/apply-style.d.ts +0 -9
  33. package/dist/cache.d.ts +0 -69
  34. package/dist/common.d.ts +0 -64
  35. package/dist/compiler/compile-template.d.ts +0 -16
  36. package/dist/compiler/compile-to-vdom-function.d.ts +0 -13
  37. package/dist/compiler/extract-global-vars.d.ts +0 -17
  38. package/dist/compiler/template-syntax.d.ts +0 -61
  39. package/dist/cross-site.d.ts +0 -29
  40. package/dist/dom.d.ts +0 -45
  41. package/dist/event-delegator.d.ts +0 -28
  42. package/dist/event-emitter.d.ts +0 -38
  43. package/dist/frame.d.ts +0 -143
  44. package/dist/framework.d.ts +0 -9
  45. package/dist/hmr.d.ts +0 -53
  46. package/dist/index.amd.js +0 -6285
  47. package/dist/index.umd.js +0 -6272
  48. package/dist/mark.d.ts +0 -26
  49. package/dist/module-loader.d.ts +0 -20
  50. package/dist/router.d.ts +0 -14
  51. package/dist/runtime.amd.js +0 -94
  52. package/dist/runtime.umd.js +0 -98
  53. package/dist/service.d.ts +0 -173
  54. package/dist/state.d.ts +0 -8
  55. package/dist/store.d.ts +0 -60
  56. package/dist/types.d.ts +0 -1259
  57. package/dist/updater.d.ts +0 -90
  58. package/dist/url-state.d.ts +0 -32
  59. package/dist/utils.d.ts +0 -90
  60. package/dist/vdom.d.ts +0 -45
  61. package/dist/view-registry.d.ts +0 -20
  62. package/dist/view.d.ts +0 -214
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark.js/mvc",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "description": "@lark.js/mvc - TypeScript MVC framework",
5
5
  "keywords": [
6
6
  "framework",
@@ -97,8 +97,7 @@
97
97
  "build": "pnpm build:tsup",
98
98
  "build:rollup": "rollup -c rollup.config.mjs",
99
99
  "build:tsup": "tsup",
100
- "clean": "rm -rf dist",
101
- "format": "prettier -w ./ --experimental-cli",
100
+ "format": "oxfmt --write ./",
102
101
  "typecheck": "tsc -p tsconfig.build.json --noEmit",
103
102
  "test": "vitest run",
104
103
  "test:watch": "vitest",
@@ -111,9 +110,9 @@
111
110
  },
112
111
  "devDependencies": {
113
112
  "@rollup/plugin-commonjs": "^29.0.3",
114
- "@rspack/core": "^2.0.8",
115
113
  "@rollup/plugin-node-resolve": "^16.0.3",
116
114
  "@rollup/plugin-typescript": "^12.3.0",
115
+ "@rspack/core": "^2.1.1",
117
116
  "@types/node": "^24.13.2",
118
117
  "@vitest/coverage-v8": "4.1.6",
119
118
  "rollup": "^4.62.2",
@@ -1,9 +0,0 @@
1
- /**
2
- * Dynamically inject CSS styles into the document head.
3
- * Returns a cleanup function to remove the injected styles.
4
- *
5
- * @param styleIdOrPairs - Style ID string or array of [id, content] pairs
6
- * @param css - CSS content string (only used when first arg is string)
7
- * @returns Cleanup function to remove the styles
8
- */
9
- export declare function applyStyle(styleIdOrPairs: string | string[], css?: string): () => void;
package/dist/cache.d.ts DELETED
@@ -1,69 +0,0 @@
1
- import type { CacheInterface, CacheOptions } from "./types";
2
- /**
3
- * Cache class with LFU-style eviction.
4
- * Keys are prefixed with SPLITTER for namespace isolation.
5
- *
6
- * @example
7
- * const cache = new Cache({ maxSize: 20, bufferSize: 5 });
8
- * cache.set('user', { name: 'Alice' });
9
- * const user = cache.get('user');
10
- * cache.has('user'); // true
11
- * cache.del('user');
12
- */
13
- export declare class Cache<T = unknown> implements CacheInterface<T> {
14
- /** Cache entries array */
15
- private entries;
16
- /** Fast lookup: prefixed key -> entry */
17
- private lookup;
18
- /** Buffer size for eviction */
19
- private readonly bufferSize;
20
- /** Maximum cache size */
21
- private readonly maxSize;
22
- /** Total capacity (maxSize + bufferSize) */
23
- private readonly capacity;
24
- /** Callback when entry is removed */
25
- private readonly onRemove?;
26
- /** Sort comparator */
27
- private readonly comparator;
28
- constructor(options?: CacheOptions<T>);
29
- /** Prefix a key with SPLITTER for namespace isolation */
30
- private prefixKey;
31
- /**
32
- * Get a cached value by key.
33
- * Updates frequency and timestamp for cache sorting.
34
- */
35
- get(key: string): T | undefined;
36
- /**
37
- * Iterate all cached values.
38
- */
39
- forEach(callback: (value: T | undefined) => void): void;
40
- /**
41
- * Set or update a cached value.
42
- * If key already exists, updates value and increments frequency.
43
- * If cache exceeds capacity, triggers eviction.
44
- */
45
- set(key: string, value: T): void;
46
- /**
47
- * Delete a cached entry. Removes it immediately from both the lookup map
48
- * and the entries array so the GC can reclaim the value without waiting
49
- * for the next eviction sweep.
50
- */
51
- del(key: string): void;
52
- /**
53
- * Check if a key exists in cache.
54
- */
55
- has(key: string): boolean;
56
- /** Get current cache size */
57
- get size(): number;
58
- /** Clear all entries */
59
- clear(): void;
60
- /**
61
- * Evict the `bufferSize` worst entries from the cache.
62
- *
63
- * Uses single-pass partial selection (O(n·k)) instead of sorting the entire
64
- * `entries` array (O(n log n)). For the typical `bufferSize = 5` this is
65
- * effectively a linear scan with at most 5 in-bucket comparisons per
66
- * iteration — and it avoids mutating the rest of `entries`.
67
- */
68
- private evictEntries;
69
- }
package/dist/common.d.ts DELETED
@@ -1,64 +0,0 @@
1
- /**
2
- * Lark framework constants.
3
- */
4
- /** Internal splitter character (U+001E Record Separator, invisible, used as namespace separator).
5
- * Uses String.fromCharCode to survive bundlers that strip control-char literals. */
6
- export declare const SPLITTER: string;
7
- export declare const RouterEvents: {
8
- CHANGE: string;
9
- CHANGED: string;
10
- PAGE_UNLOAD: string;
11
- };
12
- /** Attribute name: v-lark */
13
- export declare const LARK_VIEW = "v-lark";
14
- /** View event method regex: e.g. "app\x1eclickHandler(click)" or "clickHandler()"
15
- * Group 1: optional frame ID (before SPLITTER)
16
- * Group 2: handler name
17
- * Group 3: params string
18
- */
19
- export declare const EVENT_METHOD_REGEXP: RegExp;
20
- /** View event method name regex: e.g. "name<click,mousedown>" or "$selector<click>" */
21
- export declare const VIEW_EVENT_METHOD_REGEXP: RegExp;
22
- /** URL query/hash trim regexp */
23
- export declare const URL_TRIM_HASH_REGEXP: RegExp;
24
- /** URL trim query regexp (before hash) */
25
- export declare const URL_TRIM_QUERY_REGEXP: RegExp;
26
- /** URL param key-value regexp */
27
- export declare const URL_PARAM_REGEXP: RegExp;
28
- /** URL params test regexp */
29
- export declare const IS_URL_PARAMS: RegExp;
30
- /** URL query/hash trim regexp for path extraction */
31
- export declare const URL_QUERY_HASH_REGEXP: RegExp;
32
- /** SVG namespace */
33
- export declare const SVG_NS = "http://www.w3.org/2000/svg";
34
- /** MathML namespace */
35
- export declare const MATH_NS = "http://www.w3.org/1998/Math/MathML";
36
- /** Tag name regexp for I_GetNode */
37
- export declare const TAG_NAME_REGEXP: RegExp;
38
- /** Async task break time (ms) */
39
- export declare const CALL_BREAK_TIME = 48;
40
- /** VDOM text node tag value (number 0, falsy, distinct from string tags) */
41
- export declare const V_TEXT_NODE = 0;
42
- /** Namespace map for SVG/MathML element creation in VDOM mode */
43
- export declare const VDOM_NS_MAP: Record<string, string>;
44
- /** Increment global counter and return new value */
45
- export declare function nextCounter(): number;
46
- /** Null-safe String conversion */
47
- export declare function strSafe(v: unknown): string;
48
- /** HTML entity encoding for safe output */
49
- export declare function encodeHTML(v: unknown): string;
50
- /** URI-encode with extra character encoding */
51
- export declare function encodeURIExtra(v: unknown): string;
52
- /** Quote-encode for attribute values */
53
- export declare function encodeQuote(v: unknown): string;
54
- /**
55
- * Template reference function for creating stable keys for objects.
56
- * Stores objects in refData with SPLITTER-prefixed keys.
57
- */
58
- export declare function refFn(ref: Record<string, unknown>, value: unknown, key: string): string;
59
- /**
60
- * Check if a string is a refData reference token: SPLITTER followed by
61
- * one or more ASCII decimal digits. Used by utils.ts translateData and
62
- * updater.ts translate.
63
- */
64
- export declare function isRefToken(s: string): boolean;
@@ -1,16 +0,0 @@
1
- import type { CompileOptions } from "@/types";
2
- /**
3
- * Compile an HTML template string into a JS module string.
4
- * This is the main entry point for both Vite and Webpack loaders.
5
- *
6
- * The output is an ES module that exports a function with the signature:
7
- * (data, viewId, refData) => string
8
- *
9
- * Internally it calls the compiled template function with the standard
10
- * signature: ($data,$viewId,$refAlt,$encHtml,$strSafe,$encUri,$refFn,$encQuote)
11
- *
12
- * @param source - The raw HTML template content
13
- * @param options - Compilation options
14
- * @returns ES module source code exporting the compiled template function
15
- */
16
- export declare function compileTemplate(source: string, options?: CompileOptions): Promise<string>;
@@ -1,13 +0,0 @@
1
- /**
2
- * Compile the internal `<% %>` syntax to a VDOM template function string.
3
- *
4
- * Uses htmlparser2 for robust HTML parsing:
5
- * 1. Extract `<% %>` blocks into a store, replace with `\x00N\x00` placeholders
6
- * 2. Parse the protected source with `parseDocument`
7
- * 3. Walk the DOM tree recursively, emitting `$c()` (vdomCreate) calls
8
- *
9
- * Output is an arrow function:
10
- * `($data,$viewId,$refAlt,$n,$refFn,$encUri,$encQuote)=>{...}`
11
- * that returns the root VDomNode.
12
- */
13
- export declare function compileToVDomFunction(source: string, debug: boolean, file?: string): string;
@@ -1,17 +0,0 @@
1
- /**
2
- * Extract global variable names from a template source using AST analysis.
3
- *
4
- * 1. Convert template commands (<% %> blocks) into a form parseable by an AST parser
5
- * 2. Walk the AST to find all Identifier nodes
6
- * 3. Track variable declarations (VariableDeclarator, FunctionDeclaration) as local vars
7
- * 4. Track function parameters as local vars
8
- * 5. Remaining identifiers that are not local and not in the exclusion list are "global" —
9
- * they must be passed in as part of the data context ($$)
10
- *
11
- * This replaces the old regex-based `extractVariables()` with proper scope analysis,
12
- * eliminating false positives from local template variables and function parameters.
13
- *
14
- * @param source - The raw HTML template content (with {{ }} syntax)
15
- * @returns Array of global variable names found in the template
16
- */
17
- export declare function extractGlobalVars(source: string): Promise<string[]>;
@@ -1,61 +0,0 @@
1
- /**
2
- * @lark.js/mvc Template Compiler
3
- *
4
- * convertArtSyntax() ({{}} → <% %>)
5
- * processViewEvents() (@event prefix + param encoding)
6
- * compileToFunction() (<% %> → JS template function)
7
- * extractGlobalVars() (AST-based global var analysis via @babel/parser)
8
- *
9
- * - All template operators: = (escape), ! (raw), @ (ref lookup), : (binding)
10
- * - @event attribute processing with $splitter prefix + \x1e separator
11
- * - $strSafe (null-safe toString), $encHtml (HTML entity encode), $encUri (URI encode), $encQuote (quote encode), $refFn (ref lookup)
12
- * - Debug mode with line tracking ($dbgExpr/$dbgArt/$dbgLine) and try-catch error wrapper
13
- * - View ID injection (\x1f → '+$viewId+')
14
- * - Post-processing cleanup of empty concatenations
15
- * - 0 configuration: auto-extract variables via AST analysis
16
- *
17
- * Template syntax:
18
- * {{=variable}} → escaped output
19
- * {{:variable}} → two-way binding (same as = for rendering)
20
- * {{!variable}} → raw output (no HTML escaping)
21
- * {{@variable}} → reference lookup for component data passing
22
- * {{forOf list as item}} → loop
23
- * {{forOf list as item idx}} → loop with index
24
- * {{forIn obj as val key}} → object iteration
25
- * {{for(let i=0;i<n;i++)}} → generic for loop
26
- * {{if condition}} → conditional
27
- * {{else if condition}} → else-if
28
- * {{else}} → else
29
- * {{/if}} / {{/forOf}} / {{/forIn}} / {{/for}} → close blocks
30
- * {{set a = b}} → variable declaration
31
- */
32
- /** Protected comment store — used internally by protectComments */
33
- /**
34
- * Preserve HTML comments to prevent template syntax inside comments from being converted.
35
- */
36
- export declare function protectComments(source: string): {
37
- protectedSource: string;
38
- comments: string[];
39
- };
40
- /**
41
- * Restore previously protected HTML comments.
42
- */
43
- export declare function restoreComments(source: string, comments: string[]): string;
44
- /**
45
- * Process @event attributes.
46
- *
47
- * 1. Add \x1f (VIEW_ID_PLACEHOLDER, becomes $viewId at render time) prefix + \x1e separator
48
- * 2. Convert JS object literal params to URL query params
49
- *
50
- * @click="handlerName({key: 'value'})" → @click="\x1f\x1ehandlerName(key=value)"
51
- * @click="handlerName()" → @click="\x1f\x1ehandlerName()"
52
- * @click="goHome" → unchanged (no parens = not an event handler)
53
- */
54
- export declare function processViewEvents(source: string): string;
55
- /**
56
- * Convert {{=}}/{{:}}/{{!}}/{{@}} and control flow syntax to internal <% %> syntax.
57
- *
58
- * In debug mode, adds \x11-delimited line tracking markers:
59
- * <%'lineNo\x11code\x11'%> before forOf art expression
60
- */
61
- export declare function convertArtSyntax(source: string, debug: boolean): string;
@@ -1,29 +0,0 @@
1
- /**
2
- * CrossSite: Micro-frontend bridge View for cross-project view loading.
3
- *
4
- * For Lark + Webpack Module Federation.
5
- * Provides skeleton rendering, prepare preloading, assign reuse, and remote view mounting.
6
- *
7
- * Usage (in host project):
8
- * 1. Register CrossSite as the bridge view for cross-site paths:
9
- * registerViewClass('cross-site', CrossSite);
10
- * 2. Use v-lark="cross-site?view=remote-app/views/home&param=1" in template
11
- * 3. CrossSite loads the remote project's prepare module, then mounts the actual view
12
- */
13
- import { View } from "./view";
14
- /**
15
- * Reset the projects map cache (useful when crossConfigs change at runtime).
16
- */
17
- export declare function resetProjectsMap(): void;
18
- /**
19
- * CrossSite bridge View for micro-frontend integration.
20
- *
21
- * Flow:
22
- * 1. CrossSite is mounted as a regular view (registered as "cross-site")
23
- * 2. render() shows skeleton template with a child container
24
- * 3. updateView() loads the remote project's prepare module
25
- * 4. Once loaded, mounts the actual remote view into the child container
26
- * 5. On re-assign (same view path), calls assign on the remote view instead of re-mounting
27
- */
28
- declare const CrossSite: typeof View;
29
- export default CrossSite;
package/dist/dom.d.ts DELETED
@@ -1,45 +0,0 @@
1
- import type { DomRef, DomOp, FrameInterface } from "./types";
2
- /**
3
- * Unmount frames within a DOM node.
4
- */
5
- export declare function domUnmountFrames(frame: FrameInterface, node: ChildNode): void;
6
- /**
7
- * Parse HTML string into a DOM element.
8
- * Handles special elements (table, SVG, MathML) with wrapper elements.
9
- */
10
- export declare function domGetNode(html: string, refNode: Element): Element;
11
- /**
12
- * Get compare key for a DOM node (for keyed diff).
13
- * Uses id or v-lark path.
14
- */
15
- export declare function domGetCompareKey(node: ChildNode): string | undefined;
16
- /**
17
- * Special diff for form elements (value, checked, selected).
18
- * Form elements carry state on the DOM node (e.g. `input.value`) that isn't
19
- * reflected in attributes, so we have to sync those properties separately.
20
- */
21
- export declare function domSpecialDiff(oldNode: ChildNode, newNode: ChildNode): number;
22
- /**
23
- * Set attributes from new element onto old element, tracking changes in ref.
24
- */
25
- export declare function domSetAttributes(oldNode: Element, newNode: Element, ref: DomRef, keepId?: boolean): void;
26
- /**
27
- * Set child nodes from new parent onto old parent using keyed diff algorithm.
28
- */
29
- export declare function domSetChildNodes(oldParent: Element, newParent: Element, ref: DomRef, frame: FrameInterface, keys_?: ReadonlySet<string>): void;
30
- /**
31
- * Diff two DOM nodes and apply changes.
32
- */
33
- export declare function domSetNode(oldNode: ChildNode, newNode: ChildNode, oldParent: Element, ref: DomRef, frame: FrameInterface, keys_?: ReadonlySet<string>): void;
34
- /**
35
- * Create an empty DomRef for tracking diff operations.
36
- */
37
- export declare function createDomRef(): DomRef;
38
- /**
39
- * Apply DOM diff operations to the DOM.
40
- */
41
- export declare function applyDomOps(ops: DomOp[]): void;
42
- /**
43
- * Apply ID updates from DOM diff.
44
- */
45
- export declare function applyIdUpdates(updates: [Element, string][]): void;
@@ -1,28 +0,0 @@
1
- import type { FrameInterface } from "./types";
2
- /**
3
- * DOM event delegation system.
4
- * Delegates events to document body for performance.
5
- *
6
- */
7
- export declare const EventDelegator: {
8
- /**
9
- * Bind a DOM event type to document body.
10
- */
11
- bind(eventType: string, hasSelector?: boolean): void;
12
- /**
13
- * Unbind a DOM event type from document body.
14
- */
15
- unbind(eventType: string, hasSelector?: boolean): void;
16
- /**
17
- * Clean up range events for a destroyed view.
18
- */
19
- clearRangeEvents(viewId: string): void;
20
- /**
21
- * Set the frame getter function (called by Framework.boot).
22
- */
23
- setFrameGetter(getter: (id: string) => FrameInterface | undefined): void;
24
- /**
25
- * Get next element GUID.
26
- */
27
- nextElementGuid(): number;
28
- };
@@ -1,38 +0,0 @@
1
- import type { AnyFunc, ChangeEvent, EventEmitterInterface, EventListenerEntry } from "./types";
2
- /**
3
- * Multi-cast event emitter class.
4
- *
5
- * @example
6
- * const emitter = new EventEmitter();
7
- * emitter.on('change', (data) => console.log(data));
8
- * emitter.fire('change', { key: 'value' });
9
- */
10
- export declare class EventEmitter<T = unknown> implements EventEmitterInterface<T> {
11
- /** Event listeners: prefixed key -> listener array */
12
- listeners: Map<string, EventListenerEntry[]>;
13
- /** Number of `fire()` calls currently on the stack (re-entrancy depth). */
14
- private firingDepth;
15
- /** Keys whose listener list needs compaction after firing settles. */
16
- private pendingCompaction;
17
- /**
18
- * Bind event listener.
19
- */
20
- on(event: string, handler: (this: T, e: ChangeEvent) => void): this;
21
- /**
22
- * Unbind event listener.
23
- * If handler is provided, removes only that handler.
24
- * If no handler, removes all handlers for the event.
25
- */
26
- off(event: string, handler?: AnyFunc): this;
27
- /**
28
- * Fire event, execute all bound handlers. Safe for re-entrant `off()` calls
29
- * during dispatch: removed handlers are replaced with noop and compacted
30
- * after the outermost fire returns.
31
- *
32
- * @param event - Event name
33
- * @param data - Event data (type property added automatically)
34
- * @param remove - Whether to remove all handlers after firing
35
- * @param lastToFirst - Whether to execute handlers in reverse order
36
- */
37
- fire(event: string, data?: Record<string, unknown>, remove?: boolean, lastToFirst?: boolean): this;
38
- }
package/dist/frame.d.ts DELETED
@@ -1,143 +0,0 @@
1
- import { EventEmitter } from "./event-emitter";
2
- import { View } from "./view";
3
- import type { AnyFunc, FrameInterface, FrameInvokeEntry, ViewInterface } from "./types";
4
- /**
5
- * Frame (View Frame) class for view lifecycle management.
6
- * Each frame owns a view and manages child frames.
7
- *
8
- */
9
- export declare class Frame extends EventEmitter implements FrameInterface {
10
- /** Frame ID (same as owner DOM element ID) */
11
- readonly id: string;
12
- /** Parent Frame ID */
13
- private _parentId;
14
- get parentId(): string | undefined;
15
- /** Children map: id -> id */
16
- childrenMap: Record<string, string>;
17
- /** Children count */
18
- childrenCount: number;
19
- /** Ready count (children that have fired 'created') */
20
- readyCount: number;
21
- /** Set of child frame IDs that have fired 'created' */
22
- readyMap: Set<string>;
23
- /** View instance */
24
- viewInstance?: ViewInterface;
25
- /** Get view instance (read-only) */
26
- get view(): ViewInterface | undefined;
27
- /** Invoke list for deferred method calls */
28
- invokeList: FrameInvokeEntry[];
29
- /** Signature for async operation tracking */
30
- signature: number;
31
- /** Whether view has altered */
32
- hasAltered: number;
33
- /** Whether view is destroyed */
34
- destroyed: number;
35
- /** View path (v-lark attribute value) */
36
- viewPath?: string;
37
- /** Original template before mount */
38
- originalTemplate?: string;
39
- /** Hold fire created flag */
40
- holdFireCreated: number;
41
- /** Children created flag */
42
- childrenCreated: number;
43
- /** Children alter flag */
44
- childrenAlter: number;
45
- constructor(id: string, parentId?: string);
46
- /**
47
- * Mount a view to this frame.
48
- *
49
- * Complete flow:
50
- * 1. Parse viewPath, translate query params from parent
51
- * 2. Unmount current view
52
- * 3. Load View class (via require or provided ViewClass)
53
- * 4. View_Prepare (scan event methods)
54
- * 5. Create View instance
55
- * 6. View_DelegateEvents (bind DOM events)
56
- * 7. Call view.init()
57
- * 8. If view has template, call render via Updater
58
- * 9. If no template, call endUpdate directly
59
- */
60
- mountView(viewPath: string, viewInitParams?: Record<string, unknown>): void;
61
- /**
62
- * Internal: actually mount the view after class is loaded.
63
- */
64
- doMountView(ViewClass: typeof View, params: Record<string, unknown>, node: HTMLElement, sign: number): void;
65
- /**
66
- * Unmount current view.
67
- */
68
- unmountView(): void;
69
- /**
70
- * Mount a child frame.
71
- */
72
- mountFrame(frameId: string, viewPath: string, viewInitParams?: Record<string, unknown>): FrameInterface;
73
- /**
74
- * Unmount a child frame.
75
- */
76
- unmountFrame(id?: string): void;
77
- /**
78
- * Mount all views in a zone.
79
- */
80
- mountZone(zoneId?: string): void;
81
- /**
82
- * Unmount all views in a zone.
83
- */
84
- unmountZone(zoneId?: string): void;
85
- /**
86
- * Get all child frame IDs.
87
- */
88
- children(): string[];
89
- /**
90
- * Get parent frame at given level.
91
- * @param level - How many levels up (default 1)
92
- */
93
- parent(level?: number): Frame | undefined;
94
- /**
95
- * Invoke a method on the view.
96
- */
97
- invoke(name: string, args?: unknown[]): unknown;
98
- /**
99
- * Type-safe variant of `invoke`.
100
- *
101
- * `invoke()` accepts any string and any args, which silently hides
102
- * mismatched call sites when a method gets renamed. `invokeTyped` carries
103
- * the view's method signature through TypeScript so the compiler catches
104
- * those mistakes:
105
- *
106
- * ```ts
107
- * type Home = View & { loadData(id: string): Promise<void> };
108
- * frame.invokeTyped<Home, "loadData">("loadData", ["user-1"]);
109
- * ```
110
- *
111
- * Behavior is identical to `invoke` at runtime — same defer / direct-call
112
- * paths — so it's a drop-in safer overload.
113
- */
114
- invokeTyped<V extends Record<string, unknown>, K extends keyof V & string>(name: K, args: V[K] extends (...a: infer A) => unknown ? A : never[]): V[K] extends (...a: never[]) => infer R ? R | undefined : unknown;
115
- /** Get frame by ID */
116
- static get(id: string): Frame | undefined;
117
- /** Get all frames */
118
- static getAll(): Map<string, Frame>;
119
- /**
120
- * Returns the existing root frame, or `undefined` if none has been created.
121
- * Pure getter — never creates a Frame, never touches the DOM.
122
- *
123
- * Use `Frame.createRoot(id)` to create the root explicitly during framework
124
- * boot. For Micro-Frontend hosts that own multiple independent containers,
125
- * use `new Frame(containerId)` directly so each MF mount has its own root.
126
- */
127
- static getRoot(): Frame | undefined;
128
- /**
129
- * Create (or return) the singleton root frame for this app.
130
- *
131
- * Idempotent: subsequent calls always return the original root regardless
132
- * of `rootId` — so passing a different id later is silently ignored.
133
- * `Framework.boot()` is the canonical caller; user code rarely needs this.
134
- */
135
- static createRoot(rootId?: string): Frame;
136
- /** Bind event listener (static) */
137
- static on(event: string, handler: AnyFunc): typeof Frame;
138
- /** Unbind event listener (static) */
139
- static off(event: string, handler?: AnyFunc): typeof Frame;
140
- /** Fire event (static) */
141
- static fire(event: string, data?: Record<string, unknown>): void;
142
- }
143
- export { registerViewClass, invalidateViewClass, getViewClassRegistry, } from "./view-registry";
@@ -1,9 +0,0 @@
1
- import type { FrameworkInterface } from "./types";
2
- /** Wait result: OK = rendered, TIMEOUT_OR_NOT_FOUND = not rendered */
3
- export declare const WAIT_OK = 1;
4
- export declare const WAIT_TIMEOUT_OR_NOT_FOUND = 0;
5
- /**
6
- * Main framework object.
7
- * Provides boot, config, and all global utility methods.
8
- */
9
- export declare const Framework: FrameworkInterface;
package/dist/hmr.d.ts DELETED
@@ -1,53 +0,0 @@
1
- /**
2
- * Minimal HMR context interface.
3
- * Compatible with Vite's `import.meta.hot` and webpack's `module.hot`.
4
- * Defined here to avoid depending on bundler-specific type packages.
5
- */
6
- export interface HotContext {
7
- /** Accept a self-update. The callback receives the new module namespace. */
8
- accept(cb?: (mod: {
9
- default?: unknown;
10
- } | undefined) => void): void;
11
- /** Register a cleanup callback that runs before this module is replaced. */
12
- dispose(cb: (data: unknown) => void): void;
13
- /** Force a full page reload (fallback when HMR cannot handle the update). */
14
- invalidate(): void;
15
- }
16
- /**
17
- * Find all currently mounted frames whose viewPath matches the given path,
18
- * and re-mount them.
19
- *
20
- * After a new View class is registered via `registerViewClass`, calling this
21
- * function triggers `frame.mountView()` on each matching frame. Since the new
22
- * class is already in the registry, `Frame.mountView` takes the synchronous
23
- * path (`getViewClass` returns the class immediately).
24
- *
25
- * @param viewPath - The view path to match (e.g. 'home', 'components/list')
26
- */
27
- export declare function reloadViews(viewPath: string): void;
28
- /**
29
- * Set up the HMR accept handler for a view module.
30
- *
31
- * When the module is updated:
32
- * 1. Extracts the new View class from the new module (default export or module itself)
33
- * 2. Registers the new class in the view registry
34
- * 3. Re-mounts all frames currently using this viewPath
35
- *
36
- * If the new module doesn't export a valid View class, falls back to
37
- * `hot.invalidate()` which triggers a full page reload.
38
- *
39
- * @param hot - The HMR context (import.meta.hot)
40
- * @param viewPath - The view path identifier (e.g. 'home')
41
- */
42
- export declare function acceptView(hot: HotContext, viewPath: string): void;
43
- /**
44
- * Set up the HMR dispose handler for a view module.
45
- *
46
- * When the module is about to be replaced, removes the old View class
47
- * from the registry so that subsequent `getViewClass` calls don't return
48
- * the stale class.
49
- *
50
- * @param hot - The HMR context (import.meta.hot)
51
- * @param viewPath - The view path identifier (e.g. 'home')
52
- */
53
- export declare function disposeView(hot: HotContext, viewPath: string): void;