@lark.js/mvc 0.0.11 → 0.0.13

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.d.cts CHANGED
@@ -63,26 +63,6 @@ declare function mark(host: object, key: string): () => boolean;
63
63
  */
64
64
  declare function unmark(host: object): void;
65
65
 
66
- /**
67
- * Safeguard: Proxy-based debug protection for data objects.
68
- *
69
- * In DEBUG mode, wraps data objects with Proxy to:
70
- * 1. Warn when data is read from a different page than where it was set
71
- * 2. Prevent direct mutation (forces use of State.set/digest)
72
- * 3. Track access patterns for debugging
73
- */
74
- /**
75
- * Wrap data with a Proxy for debug-mode protection.
76
- * Only active when window.__lark_Debug is true and Proxy is available.
77
- *
78
- * @param data - Data to wrap
79
- * @param getter - Optional callback when properties are read
80
- * @param setter - Optional callback when properties are written
81
- * @param isRoot - Whether this is the root data object
82
- * @returns Proxied data or original data if debug mode is off
83
- */
84
- declare function safeguard<T>(data: T, getter?: ((key: string) => void) | null, setter?: ((path: string, value: unknown) => void) | null, isRoot?: boolean): T;
85
-
86
66
  /**
87
67
  * Multi-cast event emitter class.
88
68
  *
@@ -121,6 +101,34 @@ declare class EventEmitter<T = unknown> implements EventEmitterInterface<T> {
121
101
  fire(event: string, data?: Record<string, unknown>, remove?: boolean, lastToFirst?: boolean): this;
122
102
  }
123
103
 
104
+ /**
105
+ * Minimal HMR context interface.
106
+ * Compatible with Vite's `import.meta.hot` and webpack's `module.hot`.
107
+ * Defined here to avoid depending on bundler-specific type packages.
108
+ */
109
+ interface HotContext {
110
+ /** Accept a self-update. The callback receives the new module namespace. */
111
+ accept(cb?: (mod: {
112
+ default?: unknown;
113
+ } | undefined) => void): void;
114
+ /** Register a cleanup callback that runs before this module is replaced. */
115
+ dispose(cb: (data: unknown) => void): void;
116
+ /** Force a full page reload (fallback when HMR cannot handle the update). */
117
+ invalidate(): void;
118
+ }
119
+ /**
120
+ * Find all currently mounted frames whose viewPath matches the given path,
121
+ * and re-mount them.
122
+ *
123
+ * After a new View class is registered via `registerViewClass`, calling this
124
+ * function triggers `frame.mountView()` on each matching frame. Since the new
125
+ * class is already in the registry, `Frame.mountView` takes the synchronous
126
+ * path (`getViewClass` returns the class immediately).
127
+ *
128
+ * @param viewPath - The view path to match (e.g. 'home', 'components/list')
129
+ */
130
+ declare function reloadViews(viewPath: string): void;
131
+
124
132
  /**
125
133
  * Base View class.
126
134
  * Views are created via View.extend() and mounted by Frame.
@@ -274,6 +282,37 @@ declare class View implements ViewInterface {
274
282
  * Merge mixins into View prototype.
275
283
  */
276
284
  static merge(this: typeof View, ...mixins: Record<string, unknown>[]): typeof View;
285
+ /**
286
+ * Set up HMR accept handler for this view module.
287
+ *
288
+ * When the module is hot-replaced, the new View class is extracted from
289
+ * the new module, registered in the view registry, and all currently
290
+ * mounted frames using this viewPath are re-mounted.
291
+ *
292
+ * No-op when `hot` is undefined (production / non-HMR environment).
293
+ *
294
+ * ```ts
295
+ * if (import.meta.hot) {
296
+ * HomeView.accept(import.meta.hot, 'home');
297
+ * }
298
+ * ```
299
+ */
300
+ static accept(hot: HotContext | undefined, viewPath: string): void;
301
+ /**
302
+ * Set up HMR dispose handler for this view module.
303
+ *
304
+ * When the module is about to be replaced, the old View class is removed
305
+ * from the registry so subsequent lookups don't return the stale class.
306
+ *
307
+ * No-op when `hot` is undefined (production / non-HMR environment).
308
+ *
309
+ * ```ts
310
+ * if (import.meta.hot) {
311
+ * HomeView.dispose(import.meta.hot, 'home');
312
+ * }
313
+ * ```
314
+ */
315
+ static dispose(hot: HotContext | undefined, viewPath: string): void;
277
316
  }
278
317
  /**
279
318
  * Type-safe wrapper around `View.extend()`.
@@ -689,7 +728,7 @@ interface VDomNode {
689
728
  hasSpecials?: Record<string, string> | undefined;
690
729
  /** Child VDomNode array (undefined for text/raw/self-closing) */
691
730
  children?: VDomNode[] | undefined;
692
- /** Diff key: from id, _, #, or v-lark path */
731
+ /** Diff key: from id, #, or v-lark path */
693
732
  compareKey?: string | undefined;
694
733
  /** Keyed children count map (compareKey -> count) */
695
734
  reused?: Record<string, number> | undefined;
@@ -1426,8 +1465,9 @@ interface FrameworkInterface {
1426
1465
  * @param fns Function or function array
1427
1466
  * @param args Arguments array passed to functions
1428
1467
  * @param context `this` binding during function execution
1468
+ * @param configError Optional error callback, receives the caught exception
1429
1469
  */
1430
- toTry(fns: AnyFunc | AnyFunc[], args?: unknown[], context?: unknown): unknown;
1470
+ toTry(fns: AnyFunc | AnyFunc[], args?: unknown[], context?: unknown, configError?: (e: unknown) => void): unknown;
1431
1471
  /**
1432
1472
  * Convert path and params to URL string.
1433
1473
  * Example: `Framework.toUrl('/xxx/', {a:'b',c:'d'})` => `/xxx/?a=b&c=d`
@@ -1447,7 +1487,7 @@ interface FrameworkInterface {
1447
1487
  * @param target Target object
1448
1488
  * @param sources One or more source objects
1449
1489
  */
1450
- mix<T extends object>(target: T, ...sources: Partial<T>[]): T;
1490
+ mix<T extends object>(target: T, ...sources: Record<string, unknown>[]): T;
1451
1491
  /**
1452
1492
  * Check if object has specified own property (safe hasOwnProperty).
1453
1493
  * @param owner Object to check, supports undefined/null
@@ -1484,13 +1524,6 @@ interface FrameworkInterface {
1484
1524
  * @param callback Callback after modules are loaded
1485
1525
  */
1486
1526
  use(names: string | string[], callback?: (...modules: unknown[]) => void): void;
1487
- /**
1488
- * Protect object from direct modification in debug mode.
1489
- * Wraps data object with Proxy, intercepts read/write operations, warns to use State.set/digest for state management.
1490
- * Only effective when `window.__lark_Debug` is true.
1491
- * @param o Object to protect
1492
- */
1493
- guard<T extends object>(o: T): T;
1494
1527
  /**
1495
1528
  * Dynamically inject CSS styles into page. Returns cleanup function to remove injected styles.
1496
1529
  * Supports single and batch injection.
@@ -2271,4 +2304,4 @@ declare function create<T>(name: string, creator: StateCreator<T>): StoreApi<T>;
2271
2304
  */
2272
2305
  declare function bindStore<T>(view: unknown, store: StoreApi<T>, selector?: (state: T) => Record<string, unknown>): () => void;
2273
2306
 
2274
- export { type AnyFunc, CALL_BREAK_TIME, Cache, type CacheEntry, type CacheInterface, type CacheOptions, type ChangeEvent, type CompileOptions, CrossSite, type CrossSiteConfig, type DomElement, type DomOp, type DomRef, EVENT_METHOD_REGEXP, EventDelegator, EventEmitter, type EventEmitterInterface, type EventListenerEntry, Frame, type FrameBoundElement, type FrameInterface, type FrameInvokeEntry, type FrameStaticEvent, Framework, type FrameworkConfig, type FrameworkInterface, LARK_VIEW, type Location, type LocationDiff, type MixinEventHandler, type ParamDiff, type ParsedUri, Payload, type PayloadInterface, type PendingCacheEntry, RouterEvents as ROUTER_EVENTS, type RouteChangeEvent, type RouteChangedEvent, type RouteViewConfig, Router, type RouterInterface, SPLITTER, Service, type ServiceCacheInfo, type ServiceEvent, type ServiceMetaEntry, type ServiceOptions, State, type StateInterface, type StoreApi, TAG_NAME_REGEXP, Updater, type UpdaterInterface, type VDomCreateFn, type VDomNode, type VDomRef, type VDomTemplate, VIEW_EVENT_METHOD_REGEXP, View, type ViewEvent, type ViewEventSelectorEntry, type ViewGlobalEventEntry, type ViewInterface, type ViewLocationObserved, type ViewObserveLocation, type ViewResourceEntry, type ViewTemplate, type VoidFunc, applyStyle, bindStore, computed, create, createVDomRef, defineView, config as frameworkConfig, getRouteMode, invalidateViewClass, mark, markBooted, markRouterBooted, nextCounter, registerViewClass, resetProjectsMap, safeguard, unmark, use, useUrlState, vdomCreate };
2307
+ export { type AnyFunc, CALL_BREAK_TIME, Cache, type CacheEntry, type CacheInterface, type CacheOptions, type ChangeEvent, type CompileOptions, CrossSite, type CrossSiteConfig, type DomElement, type DomOp, type DomRef, EVENT_METHOD_REGEXP, EventDelegator, EventEmitter, type EventEmitterInterface, type EventListenerEntry, Frame, type FrameBoundElement, type FrameInterface, type FrameInvokeEntry, type FrameStaticEvent, Framework, type FrameworkConfig, type FrameworkInterface, type HotContext, LARK_VIEW, type Location, type LocationDiff, type MixinEventHandler, type ParamDiff, type ParsedUri, Payload, type PayloadInterface, type PendingCacheEntry, RouterEvents as ROUTER_EVENTS, type RouteChangeEvent, type RouteChangedEvent, type RouteViewConfig, Router, type RouterInterface, SPLITTER, Service, type ServiceCacheInfo, type ServiceEvent, type ServiceMetaEntry, type ServiceOptions, State, type StateInterface, type StoreApi, TAG_NAME_REGEXP, Updater, type UpdaterInterface, type VDomCreateFn, type VDomNode, type VDomRef, type VDomTemplate, VIEW_EVENT_METHOD_REGEXP, View, type ViewEvent, type ViewEventSelectorEntry, type ViewGlobalEventEntry, type ViewInterface, type ViewLocationObserved, type ViewObserveLocation, type ViewResourceEntry, type ViewTemplate, type VoidFunc, applyStyle, bindStore, computed, create, createVDomRef, defineView, config as frameworkConfig, getRouteMode, invalidateViewClass, mark, markBooted, markRouterBooted, nextCounter, registerViewClass, reloadViews, resetProjectsMap, unmark, use, useUrlState, vdomCreate };
package/dist/index.d.ts CHANGED
@@ -63,26 +63,6 @@ declare function mark(host: object, key: string): () => boolean;
63
63
  */
64
64
  declare function unmark(host: object): void;
65
65
 
66
- /**
67
- * Safeguard: Proxy-based debug protection for data objects.
68
- *
69
- * In DEBUG mode, wraps data objects with Proxy to:
70
- * 1. Warn when data is read from a different page than where it was set
71
- * 2. Prevent direct mutation (forces use of State.set/digest)
72
- * 3. Track access patterns for debugging
73
- */
74
- /**
75
- * Wrap data with a Proxy for debug-mode protection.
76
- * Only active when window.__lark_Debug is true and Proxy is available.
77
- *
78
- * @param data - Data to wrap
79
- * @param getter - Optional callback when properties are read
80
- * @param setter - Optional callback when properties are written
81
- * @param isRoot - Whether this is the root data object
82
- * @returns Proxied data or original data if debug mode is off
83
- */
84
- declare function safeguard<T>(data: T, getter?: ((key: string) => void) | null, setter?: ((path: string, value: unknown) => void) | null, isRoot?: boolean): T;
85
-
86
66
  /**
87
67
  * Multi-cast event emitter class.
88
68
  *
@@ -121,6 +101,34 @@ declare class EventEmitter<T = unknown> implements EventEmitterInterface<T> {
121
101
  fire(event: string, data?: Record<string, unknown>, remove?: boolean, lastToFirst?: boolean): this;
122
102
  }
123
103
 
104
+ /**
105
+ * Minimal HMR context interface.
106
+ * Compatible with Vite's `import.meta.hot` and webpack's `module.hot`.
107
+ * Defined here to avoid depending on bundler-specific type packages.
108
+ */
109
+ interface HotContext {
110
+ /** Accept a self-update. The callback receives the new module namespace. */
111
+ accept(cb?: (mod: {
112
+ default?: unknown;
113
+ } | undefined) => void): void;
114
+ /** Register a cleanup callback that runs before this module is replaced. */
115
+ dispose(cb: (data: unknown) => void): void;
116
+ /** Force a full page reload (fallback when HMR cannot handle the update). */
117
+ invalidate(): void;
118
+ }
119
+ /**
120
+ * Find all currently mounted frames whose viewPath matches the given path,
121
+ * and re-mount them.
122
+ *
123
+ * After a new View class is registered via `registerViewClass`, calling this
124
+ * function triggers `frame.mountView()` on each matching frame. Since the new
125
+ * class is already in the registry, `Frame.mountView` takes the synchronous
126
+ * path (`getViewClass` returns the class immediately).
127
+ *
128
+ * @param viewPath - The view path to match (e.g. 'home', 'components/list')
129
+ */
130
+ declare function reloadViews(viewPath: string): void;
131
+
124
132
  /**
125
133
  * Base View class.
126
134
  * Views are created via View.extend() and mounted by Frame.
@@ -274,6 +282,37 @@ declare class View implements ViewInterface {
274
282
  * Merge mixins into View prototype.
275
283
  */
276
284
  static merge(this: typeof View, ...mixins: Record<string, unknown>[]): typeof View;
285
+ /**
286
+ * Set up HMR accept handler for this view module.
287
+ *
288
+ * When the module is hot-replaced, the new View class is extracted from
289
+ * the new module, registered in the view registry, and all currently
290
+ * mounted frames using this viewPath are re-mounted.
291
+ *
292
+ * No-op when `hot` is undefined (production / non-HMR environment).
293
+ *
294
+ * ```ts
295
+ * if (import.meta.hot) {
296
+ * HomeView.accept(import.meta.hot, 'home');
297
+ * }
298
+ * ```
299
+ */
300
+ static accept(hot: HotContext | undefined, viewPath: string): void;
301
+ /**
302
+ * Set up HMR dispose handler for this view module.
303
+ *
304
+ * When the module is about to be replaced, the old View class is removed
305
+ * from the registry so subsequent lookups don't return the stale class.
306
+ *
307
+ * No-op when `hot` is undefined (production / non-HMR environment).
308
+ *
309
+ * ```ts
310
+ * if (import.meta.hot) {
311
+ * HomeView.dispose(import.meta.hot, 'home');
312
+ * }
313
+ * ```
314
+ */
315
+ static dispose(hot: HotContext | undefined, viewPath: string): void;
277
316
  }
278
317
  /**
279
318
  * Type-safe wrapper around `View.extend()`.
@@ -689,7 +728,7 @@ interface VDomNode {
689
728
  hasSpecials?: Record<string, string> | undefined;
690
729
  /** Child VDomNode array (undefined for text/raw/self-closing) */
691
730
  children?: VDomNode[] | undefined;
692
- /** Diff key: from id, _, #, or v-lark path */
731
+ /** Diff key: from id, #, or v-lark path */
693
732
  compareKey?: string | undefined;
694
733
  /** Keyed children count map (compareKey -> count) */
695
734
  reused?: Record<string, number> | undefined;
@@ -1426,8 +1465,9 @@ interface FrameworkInterface {
1426
1465
  * @param fns Function or function array
1427
1466
  * @param args Arguments array passed to functions
1428
1467
  * @param context `this` binding during function execution
1468
+ * @param configError Optional error callback, receives the caught exception
1429
1469
  */
1430
- toTry(fns: AnyFunc | AnyFunc[], args?: unknown[], context?: unknown): unknown;
1470
+ toTry(fns: AnyFunc | AnyFunc[], args?: unknown[], context?: unknown, configError?: (e: unknown) => void): unknown;
1431
1471
  /**
1432
1472
  * Convert path and params to URL string.
1433
1473
  * Example: `Framework.toUrl('/xxx/', {a:'b',c:'d'})` => `/xxx/?a=b&c=d`
@@ -1447,7 +1487,7 @@ interface FrameworkInterface {
1447
1487
  * @param target Target object
1448
1488
  * @param sources One or more source objects
1449
1489
  */
1450
- mix<T extends object>(target: T, ...sources: Partial<T>[]): T;
1490
+ mix<T extends object>(target: T, ...sources: Record<string, unknown>[]): T;
1451
1491
  /**
1452
1492
  * Check if object has specified own property (safe hasOwnProperty).
1453
1493
  * @param owner Object to check, supports undefined/null
@@ -1484,13 +1524,6 @@ interface FrameworkInterface {
1484
1524
  * @param callback Callback after modules are loaded
1485
1525
  */
1486
1526
  use(names: string | string[], callback?: (...modules: unknown[]) => void): void;
1487
- /**
1488
- * Protect object from direct modification in debug mode.
1489
- * Wraps data object with Proxy, intercepts read/write operations, warns to use State.set/digest for state management.
1490
- * Only effective when `window.__lark_Debug` is true.
1491
- * @param o Object to protect
1492
- */
1493
- guard<T extends object>(o: T): T;
1494
1527
  /**
1495
1528
  * Dynamically inject CSS styles into page. Returns cleanup function to remove injected styles.
1496
1529
  * Supports single and batch injection.
@@ -2271,4 +2304,4 @@ declare function create<T>(name: string, creator: StateCreator<T>): StoreApi<T>;
2271
2304
  */
2272
2305
  declare function bindStore<T>(view: unknown, store: StoreApi<T>, selector?: (state: T) => Record<string, unknown>): () => void;
2273
2306
 
2274
- export { type AnyFunc, CALL_BREAK_TIME, Cache, type CacheEntry, type CacheInterface, type CacheOptions, type ChangeEvent, type CompileOptions, CrossSite, type CrossSiteConfig, type DomElement, type DomOp, type DomRef, EVENT_METHOD_REGEXP, EventDelegator, EventEmitter, type EventEmitterInterface, type EventListenerEntry, Frame, type FrameBoundElement, type FrameInterface, type FrameInvokeEntry, type FrameStaticEvent, Framework, type FrameworkConfig, type FrameworkInterface, LARK_VIEW, type Location, type LocationDiff, type MixinEventHandler, type ParamDiff, type ParsedUri, Payload, type PayloadInterface, type PendingCacheEntry, RouterEvents as ROUTER_EVENTS, type RouteChangeEvent, type RouteChangedEvent, type RouteViewConfig, Router, type RouterInterface, SPLITTER, Service, type ServiceCacheInfo, type ServiceEvent, type ServiceMetaEntry, type ServiceOptions, State, type StateInterface, type StoreApi, TAG_NAME_REGEXP, Updater, type UpdaterInterface, type VDomCreateFn, type VDomNode, type VDomRef, type VDomTemplate, VIEW_EVENT_METHOD_REGEXP, View, type ViewEvent, type ViewEventSelectorEntry, type ViewGlobalEventEntry, type ViewInterface, type ViewLocationObserved, type ViewObserveLocation, type ViewResourceEntry, type ViewTemplate, type VoidFunc, applyStyle, bindStore, computed, create, createVDomRef, defineView, config as frameworkConfig, getRouteMode, invalidateViewClass, mark, markBooted, markRouterBooted, nextCounter, registerViewClass, resetProjectsMap, safeguard, unmark, use, useUrlState, vdomCreate };
2307
+ export { type AnyFunc, CALL_BREAK_TIME, Cache, type CacheEntry, type CacheInterface, type CacheOptions, type ChangeEvent, type CompileOptions, CrossSite, type CrossSiteConfig, type DomElement, type DomOp, type DomRef, EVENT_METHOD_REGEXP, EventDelegator, EventEmitter, type EventEmitterInterface, type EventListenerEntry, Frame, type FrameBoundElement, type FrameInterface, type FrameInvokeEntry, type FrameStaticEvent, Framework, type FrameworkConfig, type FrameworkInterface, type HotContext, LARK_VIEW, type Location, type LocationDiff, type MixinEventHandler, type ParamDiff, type ParsedUri, Payload, type PayloadInterface, type PendingCacheEntry, RouterEvents as ROUTER_EVENTS, type RouteChangeEvent, type RouteChangedEvent, type RouteViewConfig, Router, type RouterInterface, SPLITTER, Service, type ServiceCacheInfo, type ServiceEvent, type ServiceMetaEntry, type ServiceOptions, State, type StateInterface, type StoreApi, TAG_NAME_REGEXP, Updater, type UpdaterInterface, type VDomCreateFn, type VDomNode, type VDomRef, type VDomTemplate, VIEW_EVENT_METHOD_REGEXP, View, type ViewEvent, type ViewEventSelectorEntry, type ViewGlobalEventEntry, type ViewInterface, type ViewLocationObserved, type ViewObserveLocation, type ViewResourceEntry, type ViewTemplate, type VoidFunc, applyStyle, bindStore, computed, create, createVDomRef, defineView, config as frameworkConfig, getRouteMode, invalidateViewClass, mark, markBooted, markRouterBooted, nextCounter, registerViewClass, reloadViews, resetProjectsMap, unmark, use, useUrlState, vdomCreate };