@miurajs/miura-render 0.1.0 → 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.
- package/README.md +6 -6
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/src/binding-manager/binding-manager.d.ts +30 -0
- package/dist/src/binding-manager/binding-manager.d.ts.map +1 -0
- package/dist/src/binding-manager/binding-manager.js +245 -0
- package/dist/src/binding-manager/binding-manager.js.map +1 -0
- package/dist/src/binding-manager/binding-type.d.ts +24 -0
- package/dist/src/binding-manager/binding-type.d.ts.map +1 -0
- package/dist/src/binding-manager/binding-type.js +25 -0
- package/dist/src/binding-manager/binding-type.js.map +1 -0
- package/dist/src/binding-manager/bindings/async-binding.d.ts +23 -0
- package/dist/src/binding-manager/bindings/async-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/async-binding.js +67 -0
- package/dist/src/binding-manager/bindings/async-binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/attribute-binding.d.ts +41 -0
- package/dist/src/binding-manager/bindings/attribute-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/attribute-binding.js +79 -0
- package/dist/src/binding-manager/bindings/attribute-binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/bind-binding.d.ts +30 -0
- package/dist/src/binding-manager/bindings/bind-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/bind-binding.js +81 -0
- package/dist/src/binding-manager/bindings/bind-binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/binding.d.ts +6 -0
- package/dist/src/binding-manager/bindings/binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/binding.js +2 -0
- package/dist/src/binding-manager/bindings/binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/boolean-binding.d.ts +18 -0
- package/dist/src/binding-manager/bindings/boolean-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/boolean-binding.js +65 -0
- package/dist/src/binding-manager/bindings/boolean-binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/class-binding.d.ts +10 -0
- package/dist/src/binding-manager/bindings/class-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/class-binding.js +68 -0
- package/dist/src/binding-manager/bindings/class-binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/directive-binding.d.ts +15 -0
- package/dist/src/binding-manager/bindings/directive-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/directive-binding.js +70 -0
- package/dist/src/binding-manager/bindings/directive-binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/event-binding.d.ts +14 -0
- package/dist/src/binding-manager/bindings/event-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/event-binding.js +73 -0
- package/dist/src/binding-manager/bindings/event-binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/node-binding.d.ts +36 -0
- package/dist/src/binding-manager/bindings/node-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/node-binding.js +235 -0
- package/dist/src/binding-manager/bindings/node-binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/object-class-binding.d.ts +16 -0
- package/dist/src/binding-manager/bindings/object-class-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/object-class-binding.js +42 -0
- package/dist/src/binding-manager/bindings/object-class-binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/object-style-binding.d.ts +16 -0
- package/dist/src/binding-manager/bindings/object-style-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/object-style-binding.js +38 -0
- package/dist/src/binding-manager/bindings/object-style-binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/property-binding.d.ts +12 -0
- package/dist/src/binding-manager/bindings/property-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/property-binding.js +44 -0
- package/dist/src/binding-manager/bindings/property-binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/reference-binding.d.ts +14 -0
- package/dist/src/binding-manager/bindings/reference-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/reference-binding.js +44 -0
- package/dist/src/binding-manager/bindings/reference-binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/spread-binding.d.ts +16 -0
- package/dist/src/binding-manager/bindings/spread-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/spread-binding.js +40 -0
- package/dist/src/binding-manager/bindings/spread-binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/style-binding.d.ts +10 -0
- package/dist/src/binding-manager/bindings/style-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/style-binding.js +44 -0
- package/dist/src/binding-manager/bindings/style-binding.js.map +1 -0
- package/dist/src/compiler/code-factory.d.ts +45 -0
- package/dist/src/compiler/code-factory.d.ts.map +1 -0
- package/dist/src/compiler/code-factory.js +211 -0
- package/dist/src/compiler/code-factory.js.map +1 -0
- package/dist/src/compiler/compiler.d.ts +77 -0
- package/dist/src/compiler/compiler.d.ts.map +1 -0
- package/dist/src/compiler/compiler.js +77 -0
- package/dist/src/compiler/compiler.js.map +1 -0
- package/dist/src/compiler/constants.d.ts +5 -0
- package/dist/src/compiler/constants.d.ts.map +1 -0
- package/dist/src/compiler/constants.js +9 -0
- package/dist/src/compiler/constants.js.map +1 -0
- package/dist/src/css-result.d.ts +27 -0
- package/dist/src/css-result.d.ts.map +1 -0
- package/dist/src/css-result.js +56 -0
- package/dist/src/css-result.js.map +1 -0
- package/dist/src/css.d.ts +26 -0
- package/dist/src/css.d.ts.map +1 -0
- package/dist/src/css.js +62 -0
- package/dist/src/css.js.map +1 -0
- package/dist/src/directives/animate.directive.d.ts +42 -0
- package/dist/src/directives/animate.directive.d.ts.map +1 -0
- package/dist/src/directives/animate.directive.js +349 -0
- package/dist/src/directives/animate.directive.js.map +1 -0
- package/dist/src/directives/await.d.ts +68 -0
- package/dist/src/directives/await.d.ts.map +1 -0
- package/dist/src/directives/await.js +70 -0
- package/dist/src/directives/await.js.map +1 -0
- package/dist/src/directives/choose.d.ts +28 -0
- package/dist/src/directives/choose.d.ts.map +1 -0
- package/dist/src/directives/choose.js +30 -0
- package/dist/src/directives/choose.js.map +1 -0
- package/dist/src/directives/decorator-example.d.ts +8 -0
- package/dist/src/directives/decorator-example.d.ts.map +1 -0
- package/dist/src/directives/decorator-example.js +32 -0
- package/dist/src/directives/decorator-example.js.map +1 -0
- package/dist/src/directives/decorators.d.ts +3 -0
- package/dist/src/directives/decorators.d.ts.map +1 -0
- package/dist/src/directives/decorators.js +17 -0
- package/dist/src/directives/decorators.js.map +1 -0
- package/dist/src/directives/directive-manager.d.ts +26 -0
- package/dist/src/directives/directive-manager.d.ts.map +1 -0
- package/dist/src/directives/directive-manager.js +114 -0
- package/dist/src/directives/directive-manager.js.map +1 -0
- package/dist/src/directives/directive.d.ts +38 -0
- package/dist/src/directives/directive.d.ts.map +1 -0
- package/dist/src/directives/directive.js +18 -0
- package/dist/src/directives/directive.js.map +1 -0
- package/dist/src/directives/focus.directive.d.ts +16 -0
- package/dist/src/directives/focus.directive.d.ts.map +1 -0
- package/dist/src/directives/focus.directive.js +29 -0
- package/dist/src/directives/focus.directive.js.map +1 -0
- package/dist/src/directives/gesture.directive.d.ts +58 -0
- package/dist/src/directives/gesture.directive.d.ts.map +1 -0
- package/dist/src/directives/gesture.directive.js +331 -0
- package/dist/src/directives/gesture.directive.js.map +1 -0
- package/dist/src/directives/index.d.ts +34 -0
- package/dist/src/directives/index.d.ts.map +1 -0
- package/dist/src/directives/index.js +35 -0
- package/dist/src/directives/index.js.map +1 -0
- package/dist/src/directives/intersection.directive.d.ts +18 -0
- package/dist/src/directives/intersection.directive.d.ts.map +1 -0
- package/dist/src/directives/intersection.directive.js +50 -0
- package/dist/src/directives/intersection.directive.js.map +1 -0
- package/dist/src/directives/keyed-diff.d.ts +30 -0
- package/dist/src/directives/keyed-diff.d.ts.map +1 -0
- package/dist/src/directives/keyed-diff.js +185 -0
- package/dist/src/directives/keyed-diff.js.map +1 -0
- package/dist/src/directives/lazy-setup.d.ts +3 -0
- package/dist/src/directives/lazy-setup.d.ts.map +1 -0
- package/dist/src/directives/lazy-setup.js +55 -0
- package/dist/src/directives/lazy-setup.js.map +1 -0
- package/dist/src/directives/lazy.directive.d.ts +19 -0
- package/dist/src/directives/lazy.directive.d.ts.map +1 -0
- package/dist/src/directives/lazy.directive.js +73 -0
- package/dist/src/directives/lazy.directive.js.map +1 -0
- package/dist/src/directives/media.directive.d.ts +31 -0
- package/dist/src/directives/media.directive.d.ts.map +1 -0
- package/dist/src/directives/media.directive.js +105 -0
- package/dist/src/directives/media.directive.js.map +1 -0
- package/dist/src/directives/mutation.directive.d.ts +11 -0
- package/dist/src/directives/mutation.directive.d.ts.map +1 -0
- package/dist/src/directives/mutation.directive.js +56 -0
- package/dist/src/directives/mutation.directive.js.map +1 -0
- package/dist/src/directives/repeat.d.ts +50 -0
- package/dist/src/directives/repeat.d.ts.map +1 -0
- package/dist/src/directives/repeat.js +47 -0
- package/dist/src/directives/repeat.js.map +1 -0
- package/dist/src/directives/resize.directive.d.ts +14 -0
- package/dist/src/directives/resize.directive.d.ts.map +1 -0
- package/dist/src/directives/resize.directive.js +81 -0
- package/dist/src/directives/resize.directive.js.map +1 -0
- package/dist/src/directives/setup.d.ts +9 -0
- package/dist/src/directives/setup.d.ts.map +1 -0
- package/dist/src/directives/setup.js +9 -0
- package/dist/src/directives/setup.js.map +1 -0
- package/dist/src/directives/structural/async.directive.d.ts +39 -0
- package/dist/src/directives/structural/async.directive.d.ts.map +1 -0
- package/dist/src/directives/structural/async.directive.js +115 -0
- package/dist/src/directives/structural/async.directive.js.map +1 -0
- package/dist/src/directives/structural/for.directive.d.ts +37 -0
- package/dist/src/directives/structural/for.directive.d.ts.map +1 -0
- package/dist/src/directives/structural/for.directive.js +209 -0
- package/dist/src/directives/structural/for.directive.js.map +1 -0
- package/dist/src/directives/structural/if.directive.d.ts +54 -0
- package/dist/src/directives/structural/if.directive.d.ts.map +1 -0
- package/dist/src/directives/structural/if.directive.js +210 -0
- package/dist/src/directives/structural/if.directive.js.map +1 -0
- package/dist/src/directives/structural/structural.directive.d.ts +11 -0
- package/dist/src/directives/structural/structural.directive.d.ts.map +1 -0
- package/dist/src/directives/structural/structural.directive.js +29 -0
- package/dist/src/directives/structural/structural.directive.js.map +1 -0
- package/dist/src/directives/structural/switch.directive.d.ts +12 -0
- package/dist/src/directives/structural/switch.directive.d.ts.map +1 -0
- package/dist/src/directives/structural/switch.directive.js +69 -0
- package/dist/src/directives/structural/switch.directive.js.map +1 -0
- package/dist/src/directives/structural/virtual-scroll.directive.d.ts +50 -0
- package/dist/src/directives/structural/virtual-scroll.directive.d.ts.map +1 -0
- package/dist/src/directives/structural/virtual-scroll.directive.js +165 -0
- package/dist/src/directives/structural/virtual-scroll.directive.js.map +1 -0
- package/dist/src/directives/utils.d.ts +61 -0
- package/dist/src/directives/utils.d.ts.map +1 -0
- package/dist/src/directives/utils.js +121 -0
- package/dist/src/directives/utils.js.map +1 -0
- package/dist/src/directives/validate.directive.d.ts +41 -0
- package/dist/src/directives/validate.directive.d.ts.map +1 -0
- package/dist/src/directives/validate.directive.js +161 -0
- package/dist/src/directives/validate.directive.js.map +1 -0
- package/dist/src/directives/virtual-scroll.d.ts +91 -0
- package/dist/src/directives/virtual-scroll.d.ts.map +1 -0
- package/dist/src/directives/virtual-scroll.js +78 -0
- package/dist/src/directives/virtual-scroll.js.map +1 -0
- package/dist/src/directives/when.d.ts +24 -0
- package/dist/src/directives/when.d.ts.map +1 -0
- package/dist/src/directives/when.js +25 -0
- package/dist/src/directives/when.js.map +1 -0
- package/dist/src/html.d.ts +23 -0
- package/dist/src/html.d.ts.map +1 -0
- package/dist/src/html.js +37 -0
- package/dist/src/html.js.map +1 -0
- package/dist/src/modifiers/capture-modifier.d.ts +6 -0
- package/dist/src/modifiers/capture-modifier.d.ts.map +1 -0
- package/dist/src/modifiers/capture-modifier.js +14 -0
- package/dist/src/modifiers/capture-modifier.js.map +1 -0
- package/dist/src/modifiers/event-modifiers.d.ts +38 -0
- package/dist/src/modifiers/event-modifiers.d.ts.map +1 -0
- package/dist/src/modifiers/event-modifiers.js +90 -0
- package/dist/src/modifiers/event-modifiers.js.map +1 -0
- package/dist/src/modifiers/key-modifiers.d.ts +8 -0
- package/dist/src/modifiers/key-modifiers.d.ts.map +1 -0
- package/dist/src/modifiers/key-modifiers.js +29 -0
- package/dist/src/modifiers/key-modifiers.js.map +1 -0
- package/dist/src/modifiers/mouse-modifiers.d.ts +8 -0
- package/dist/src/modifiers/mouse-modifiers.d.ts.map +1 -0
- package/dist/src/modifiers/mouse-modifiers.js +15 -0
- package/dist/src/modifiers/mouse-modifiers.js.map +1 -0
- package/dist/src/modifiers/once-modifier.d.ts +6 -0
- package/dist/src/modifiers/once-modifier.d.ts.map +1 -0
- package/dist/src/modifiers/once-modifier.js +11 -0
- package/dist/src/modifiers/once-modifier.js.map +1 -0
- package/dist/src/modifiers/passive-modifier.d.ts +6 -0
- package/dist/src/modifiers/passive-modifier.d.ts.map +1 -0
- package/dist/src/modifiers/passive-modifier.js +14 -0
- package/dist/src/modifiers/passive-modifier.js.map +1 -0
- package/dist/src/processor/parser.d.ts +74 -0
- package/dist/src/processor/parser.d.ts.map +1 -0
- package/dist/src/processor/parser.js +345 -0
- package/dist/src/processor/parser.js.map +1 -0
- package/dist/src/processor/processor.d.ts +68 -0
- package/dist/src/processor/processor.d.ts.map +1 -0
- package/dist/src/processor/processor.js +138 -0
- package/dist/src/processor/processor.js.map +1 -0
- package/dist/src/processor/template-result.d.ts +74 -0
- package/dist/src/processor/template-result.d.ts.map +1 -0
- package/dist/src/processor/template-result.js +53 -0
- package/dist/src/processor/template-result.js.map +1 -0
- package/dist/src/processor/types.d.ts +16 -0
- package/dist/src/processor/types.d.ts.map +1 -0
- package/dist/src/processor/types.js +13 -0
- package/dist/src/processor/types.js.map +1 -0
- package/dist/src/utils/debug.d.ts +7 -0
- package/dist/src/utils/debug.d.ts.map +1 -0
- package/dist/src/utils/debug.js +7 -0
- package/dist/src/utils/debug.js.map +1 -0
- package/dist/src/utils/performance.d.ts +50 -0
- package/dist/src/utils/performance.d.ts.map +1 -0
- package/dist/src/utils/performance.js +51 -0
- package/dist/src/utils/performance.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +8 -10
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for directive management and lazy loading
|
|
3
|
+
*/
|
|
4
|
+
export declare class DirectiveUtils {
|
|
5
|
+
/**
|
|
6
|
+
* Preload specific directives for better performance
|
|
7
|
+
* @param directiveNames - Array of directive names to preload
|
|
8
|
+
*/
|
|
9
|
+
static preloadDirectives(directiveNames: string[]): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Preload all available directives
|
|
12
|
+
*/
|
|
13
|
+
static preloadAllDirectives(): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Check if a directive is loaded
|
|
16
|
+
* @param directiveName - Name of the directive to check
|
|
17
|
+
*/
|
|
18
|
+
static isDirectiveLoaded(directiveName: string): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Check if a directive is currently loading
|
|
21
|
+
* @param directiveName - Name of the directive to check
|
|
22
|
+
*/
|
|
23
|
+
static isDirectiveLoading(directiveName: string): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Get all loaded directives
|
|
26
|
+
*/
|
|
27
|
+
static getLoadedDirectives(): string[];
|
|
28
|
+
/**
|
|
29
|
+
* Get all registered directives (both loaded and lazy)
|
|
30
|
+
*/
|
|
31
|
+
static getRegisteredDirectives(): string[];
|
|
32
|
+
/**
|
|
33
|
+
* Enable debug logging for directive manager
|
|
34
|
+
*/
|
|
35
|
+
static enableDebug(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Create a loading indicator for elements with lazy directives
|
|
38
|
+
* @param element - The element to add loading indicator to
|
|
39
|
+
* @param directiveName - The directive name being loaded
|
|
40
|
+
*/
|
|
41
|
+
static addLoadingIndicator(element: Element, directiveName: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* Remove loading indicator from element
|
|
44
|
+
* @param element - The element to remove loading indicator from
|
|
45
|
+
*/
|
|
46
|
+
static removeLoadingIndicator(element: Element): void;
|
|
47
|
+
/**
|
|
48
|
+
* Get loading state of an element
|
|
49
|
+
* @param element - The element to check
|
|
50
|
+
*/
|
|
51
|
+
static getElementLoadingState(element: Element): string | null;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* CSS for directive loading indicators
|
|
55
|
+
*/
|
|
56
|
+
export declare const directiveLoadingStyles = "\n .directive-loading {\n position: relative;\n opacity: 0.7;\n pointer-events: none;\n }\n\n .directive-loading::after {\n content: '';\n position: absolute;\n top: 50%;\n left: 50%;\n width: 20px;\n height: 20px;\n margin: -10px 0 0 -10px;\n border: 2px solid #f3f3f3;\n border-top: 2px solid #3498db;\n border-radius: 50%;\n animation: directive-spin 1s linear infinite;\n z-index: 1000;\n }\n\n @keyframes directive-spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n }\n";
|
|
57
|
+
/**
|
|
58
|
+
* Auto-inject directive loading styles
|
|
59
|
+
*/
|
|
60
|
+
export declare function injectDirectiveLoadingStyles(): void;
|
|
61
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/directives/utils.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,qBAAa,cAAc;IACvB;;;OAGG;WACU,iBAAiB,CAAC,cAAc,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAKvE;;OAEG;WACU,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIlD;;;OAGG;IACH,MAAM,CAAC,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO;IAIxD;;;OAGG;IACH,MAAM,CAAC,kBAAkB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO;IAIzD;;OAEG;IACH,MAAM,CAAC,mBAAmB,IAAI,MAAM,EAAE;IAItC;;OAEG;IACH,MAAM,CAAC,uBAAuB,IAAI,MAAM,EAAE;IAI1C;;OAEG;IACH,MAAM,CAAC,WAAW,IAAI,IAAI;IAK1B;;;;OAIG;IACH,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,GAAG,IAAI;IAKzE;;;OAGG;IACH,MAAM,CAAC,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAKrD;;;OAGG;IACH,MAAM,CAAC,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI;CAGjE;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB,soBA0BlC,CAAC;AAEF;;GAEG;AACH,wBAAgB,4BAA4B,IAAI,IAAI,CAOnD"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { DirectiveManager } from './directive-manager';
|
|
2
|
+
/**
|
|
3
|
+
* Utility functions for directive management and lazy loading
|
|
4
|
+
*/
|
|
5
|
+
export class DirectiveUtils {
|
|
6
|
+
/**
|
|
7
|
+
* Preload specific directives for better performance
|
|
8
|
+
* @param directiveNames - Array of directive names to preload
|
|
9
|
+
*/
|
|
10
|
+
static async preloadDirectives(directiveNames) {
|
|
11
|
+
const promises = directiveNames.map(name => DirectiveManager.preloadDirective(name));
|
|
12
|
+
await Promise.all(promises);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Preload all available directives
|
|
16
|
+
*/
|
|
17
|
+
static async preloadAllDirectives() {
|
|
18
|
+
await DirectiveManager.preloadAllDirectives();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Check if a directive is loaded
|
|
22
|
+
* @param directiveName - Name of the directive to check
|
|
23
|
+
*/
|
|
24
|
+
static isDirectiveLoaded(directiveName) {
|
|
25
|
+
return DirectiveManager.isLoaded(directiveName);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Check if a directive is currently loading
|
|
29
|
+
* @param directiveName - Name of the directive to check
|
|
30
|
+
*/
|
|
31
|
+
static isDirectiveLoading(directiveName) {
|
|
32
|
+
return DirectiveManager.isLoading(directiveName);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get all loaded directives
|
|
36
|
+
*/
|
|
37
|
+
static getLoadedDirectives() {
|
|
38
|
+
return DirectiveManager.getLoadedDirectives();
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get all registered directives (both loaded and lazy)
|
|
42
|
+
*/
|
|
43
|
+
static getRegisteredDirectives() {
|
|
44
|
+
return DirectiveManager.getRegisteredDirectives();
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Enable debug logging for directive manager
|
|
48
|
+
*/
|
|
49
|
+
static enableDebug() {
|
|
50
|
+
const { enableDebug } = require('../utils/debug');
|
|
51
|
+
enableDebug({ directiveManager: true });
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Create a loading indicator for elements with lazy directives
|
|
55
|
+
* @param element - The element to add loading indicator to
|
|
56
|
+
* @param directiveName - The directive name being loaded
|
|
57
|
+
*/
|
|
58
|
+
static addLoadingIndicator(element, directiveName) {
|
|
59
|
+
element.setAttribute('data-directive-loading', directiveName);
|
|
60
|
+
element.classList.add('directive-loading');
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Remove loading indicator from element
|
|
64
|
+
* @param element - The element to remove loading indicator from
|
|
65
|
+
*/
|
|
66
|
+
static removeLoadingIndicator(element) {
|
|
67
|
+
element.removeAttribute('data-directive-loading');
|
|
68
|
+
element.classList.remove('directive-loading');
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get loading state of an element
|
|
72
|
+
* @param element - The element to check
|
|
73
|
+
*/
|
|
74
|
+
static getElementLoadingState(element) {
|
|
75
|
+
return element.getAttribute('data-directive-loading');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* CSS for directive loading indicators
|
|
80
|
+
*/
|
|
81
|
+
export const directiveLoadingStyles = `
|
|
82
|
+
.directive-loading {
|
|
83
|
+
position: relative;
|
|
84
|
+
opacity: 0.7;
|
|
85
|
+
pointer-events: none;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.directive-loading::after {
|
|
89
|
+
content: '';
|
|
90
|
+
position: absolute;
|
|
91
|
+
top: 50%;
|
|
92
|
+
left: 50%;
|
|
93
|
+
width: 20px;
|
|
94
|
+
height: 20px;
|
|
95
|
+
margin: -10px 0 0 -10px;
|
|
96
|
+
border: 2px solid #f3f3f3;
|
|
97
|
+
border-top: 2px solid #3498db;
|
|
98
|
+
border-radius: 50%;
|
|
99
|
+
animation: directive-spin 1s linear infinite;
|
|
100
|
+
z-index: 1000;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
@keyframes directive-spin {
|
|
104
|
+
0% { transform: rotate(0deg); }
|
|
105
|
+
100% { transform: rotate(360deg); }
|
|
106
|
+
}
|
|
107
|
+
`;
|
|
108
|
+
/**
|
|
109
|
+
* Auto-inject directive loading styles
|
|
110
|
+
*/
|
|
111
|
+
export function injectDirectiveLoadingStyles() {
|
|
112
|
+
if (!document.getElementById('miura-directive-loading-styles')) {
|
|
113
|
+
const style = document.createElement('style');
|
|
114
|
+
style.id = 'miura-directive-loading-styles';
|
|
115
|
+
style.textContent = directiveLoadingStyles;
|
|
116
|
+
document.head.appendChild(style);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// Auto-inject styles when module is imported
|
|
120
|
+
injectDirectiveLoadingStyles();
|
|
121
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/directives/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;GAEG;AACH,MAAM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C,sBAAsB,CAAC,OAAgB;QAC1C,OAAO,CAAC,eAAe,CAAC,wBAAwB,CAAC,CAAC;QAClD,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;IAClD,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,sBAAsB,CAAC,OAAgB;QAC1C,OAAO,OAAO,CAAC,YAAY,CAAC,wBAAwB,CAAC,CAAC;IAC1D,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BrC,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,4BAA4B;IACxC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,gCAAgC,CAAC,EAAE,CAAC;QAC7D,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC9C,KAAK,CAAC,EAAE,GAAG,gCAAgC,CAAC;QAC5C,KAAK,CAAC,WAAW,GAAG,sBAAsB,CAAC;QAC3C,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;AACL,CAAC;AAED,6CAA6C;AAC7C,4BAA4B,EAAE,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { BaseDirective } from './directive';
|
|
2
|
+
interface ValidationRule {
|
|
3
|
+
required?: boolean;
|
|
4
|
+
minLength?: number;
|
|
5
|
+
maxLength?: number;
|
|
6
|
+
pattern?: RegExp;
|
|
7
|
+
email?: boolean;
|
|
8
|
+
url?: boolean;
|
|
9
|
+
number?: boolean;
|
|
10
|
+
min?: number;
|
|
11
|
+
max?: number;
|
|
12
|
+
custom?: (value: string) => boolean | string;
|
|
13
|
+
}
|
|
14
|
+
interface ValidationOptions {
|
|
15
|
+
rules?: ValidationRule;
|
|
16
|
+
onError?: (errors: string[]) => void;
|
|
17
|
+
onSuccess?: () => void;
|
|
18
|
+
validateOnInput?: boolean;
|
|
19
|
+
validateOnBlur?: boolean;
|
|
20
|
+
showErrors?: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface ValidationResult {
|
|
23
|
+
isValid: boolean;
|
|
24
|
+
errors: string[];
|
|
25
|
+
}
|
|
26
|
+
export declare class ValidateDirective extends BaseDirective {
|
|
27
|
+
private options;
|
|
28
|
+
private currentErrors;
|
|
29
|
+
mount(element: Element): void;
|
|
30
|
+
private handleInput;
|
|
31
|
+
private handleBlur;
|
|
32
|
+
private validateElement;
|
|
33
|
+
private updateElementStyling;
|
|
34
|
+
update(options: ValidationOptions): void;
|
|
35
|
+
unmount(): void;
|
|
36
|
+
validate(): ValidationResult;
|
|
37
|
+
getErrors(): string[];
|
|
38
|
+
clearErrors(): void;
|
|
39
|
+
}
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=validate.directive.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.directive.d.ts","sourceRoot":"","sources":["../../../src/directives/validate.directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,UAAU,cAAc;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,GAAG,MAAM,CAAC;CAChD;AAED,UAAU,iBAAiB;IACvB,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IACrC,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,UAAU,gBAAgB;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,qBAAa,iBAAkB,SAAQ,aAAa;IAChD,OAAO,CAAC,OAAO,CAAyB;IACxC,OAAO,CAAC,aAAa,CAAgB;IAErC,KAAK,CAAC,OAAO,EAAE,OAAO;IAqBtB,OAAO,CAAC,WAAW,CAGjB;IAEF,OAAO,CAAC,UAAU,CAGhB;IAEF,OAAO,CAAC,eAAe;IAuFvB,OAAO,CAAC,oBAAoB;IA4B5B,MAAM,CAAC,OAAO,EAAE,iBAAiB;IAIjC,OAAO;IAQP,QAAQ,IAAI,gBAAgB;IAO5B,SAAS,IAAI,MAAM,EAAE;IAIrB,WAAW;CAMd"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { BaseDirective } from './directive';
|
|
2
|
+
import { debugLog } from '../utils/debug';
|
|
3
|
+
export class ValidateDirective extends BaseDirective {
|
|
4
|
+
options = {};
|
|
5
|
+
currentErrors = [];
|
|
6
|
+
mount(element) {
|
|
7
|
+
debugLog('validate', 'Mounting validate directive');
|
|
8
|
+
this.options = {
|
|
9
|
+
validateOnInput: true,
|
|
10
|
+
validateOnBlur: true,
|
|
11
|
+
showErrors: true,
|
|
12
|
+
rules: {},
|
|
13
|
+
...this.options
|
|
14
|
+
};
|
|
15
|
+
if (element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement || element instanceof HTMLSelectElement) {
|
|
16
|
+
if (this.options.validateOnInput) {
|
|
17
|
+
element.addEventListener('input', this.handleInput.bind(this));
|
|
18
|
+
}
|
|
19
|
+
if (this.options.validateOnBlur) {
|
|
20
|
+
element.addEventListener('blur', this.handleBlur.bind(this));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
handleInput = (event) => {
|
|
25
|
+
const element = event.target;
|
|
26
|
+
this.validateElement(element);
|
|
27
|
+
};
|
|
28
|
+
handleBlur = (event) => {
|
|
29
|
+
const element = event.target;
|
|
30
|
+
this.validateElement(element);
|
|
31
|
+
};
|
|
32
|
+
validateElement(element) {
|
|
33
|
+
const value = element.value;
|
|
34
|
+
const errors = [];
|
|
35
|
+
const rules = this.options.rules || {};
|
|
36
|
+
// Required validation
|
|
37
|
+
if (rules.required && !value.trim()) {
|
|
38
|
+
errors.push('This field is required');
|
|
39
|
+
}
|
|
40
|
+
if (value.trim()) {
|
|
41
|
+
// Min length validation
|
|
42
|
+
if (rules.minLength && value.length < rules.minLength) {
|
|
43
|
+
errors.push(`Minimum length is ${rules.minLength} characters`);
|
|
44
|
+
}
|
|
45
|
+
// Max length validation
|
|
46
|
+
if (rules.maxLength && value.length > rules.maxLength) {
|
|
47
|
+
errors.push(`Maximum length is ${rules.maxLength} characters`);
|
|
48
|
+
}
|
|
49
|
+
// Pattern validation
|
|
50
|
+
if (rules.pattern && !rules.pattern.test(value)) {
|
|
51
|
+
errors.push('Invalid format');
|
|
52
|
+
}
|
|
53
|
+
// Email validation
|
|
54
|
+
if (rules.email) {
|
|
55
|
+
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
56
|
+
if (!emailPattern.test(value)) {
|
|
57
|
+
errors.push('Invalid email format');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// URL validation
|
|
61
|
+
if (rules.url) {
|
|
62
|
+
try {
|
|
63
|
+
new URL(value);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
errors.push('Invalid URL format');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Number validation
|
|
70
|
+
if (rules.number) {
|
|
71
|
+
const num = parseFloat(value);
|
|
72
|
+
if (isNaN(num)) {
|
|
73
|
+
errors.push('Must be a number');
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
if (rules.min !== undefined && num < rules.min) {
|
|
77
|
+
errors.push(`Minimum value is ${rules.min}`);
|
|
78
|
+
}
|
|
79
|
+
if (rules.max !== undefined && num > rules.max) {
|
|
80
|
+
errors.push(`Maximum value is ${rules.max}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// Custom validation
|
|
85
|
+
if (rules.custom) {
|
|
86
|
+
const result = rules.custom(value);
|
|
87
|
+
if (result === false) {
|
|
88
|
+
errors.push('Invalid value');
|
|
89
|
+
}
|
|
90
|
+
else if (typeof result === 'string') {
|
|
91
|
+
errors.push(result);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const isValid = errors.length === 0;
|
|
96
|
+
this.currentErrors = errors;
|
|
97
|
+
// Update element styling
|
|
98
|
+
this.updateElementStyling(element, isValid);
|
|
99
|
+
// Call callbacks
|
|
100
|
+
if (isValid) {
|
|
101
|
+
this.options.onSuccess?.();
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
this.options.onError?.(errors);
|
|
105
|
+
}
|
|
106
|
+
debugLog('validate', 'Validation result:', { isValid, errors });
|
|
107
|
+
return { isValid, errors };
|
|
108
|
+
}
|
|
109
|
+
updateElementStyling(element, isValid) {
|
|
110
|
+
if (this.options.showErrors) {
|
|
111
|
+
element.classList.remove('valid', 'invalid');
|
|
112
|
+
element.classList.add(isValid ? 'valid' : 'invalid');
|
|
113
|
+
// Add or update error message
|
|
114
|
+
let errorContainer = element.parentElement?.querySelector('.validation-error');
|
|
115
|
+
if (!errorContainer && !isValid) {
|
|
116
|
+
errorContainer = document.createElement('div');
|
|
117
|
+
errorContainer.className = 'validation-error';
|
|
118
|
+
if (errorContainer instanceof HTMLElement) {
|
|
119
|
+
errorContainer.style.color = 'red';
|
|
120
|
+
errorContainer.style.fontSize = '12px';
|
|
121
|
+
errorContainer.style.marginTop = '4px';
|
|
122
|
+
}
|
|
123
|
+
element.parentElement?.appendChild(errorContainer);
|
|
124
|
+
}
|
|
125
|
+
if (errorContainer) {
|
|
126
|
+
if (isValid) {
|
|
127
|
+
errorContainer.remove();
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
errorContainer.textContent = this.currentErrors[0];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
update(options) {
|
|
136
|
+
this.options = { ...this.options, ...options };
|
|
137
|
+
}
|
|
138
|
+
unmount() {
|
|
139
|
+
if (this.element instanceof HTMLInputElement) {
|
|
140
|
+
this.element.removeEventListener('input', this.handleInput);
|
|
141
|
+
this.element.removeEventListener('blur', this.handleBlur);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// Public methods
|
|
145
|
+
validate() {
|
|
146
|
+
if (this.element instanceof HTMLInputElement) {
|
|
147
|
+
return this.validateElement(this.element);
|
|
148
|
+
}
|
|
149
|
+
return { isValid: false, errors: ['Element not found'] };
|
|
150
|
+
}
|
|
151
|
+
getErrors() {
|
|
152
|
+
return this.currentErrors;
|
|
153
|
+
}
|
|
154
|
+
clearErrors() {
|
|
155
|
+
this.currentErrors = [];
|
|
156
|
+
if (this.element instanceof HTMLInputElement) {
|
|
157
|
+
this.updateElementStyling(this.element, true);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=validate.directive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.directive.js","sourceRoot":"","sources":["../../../src/directives/validate.directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AA6B1C,MAAM,OAAO,iBAAkB,SAAQ,aAAa;IACxC,OAAO,GAAsB,EAAE,CAAC;IAChC,aAAa,GAAa,EAAE,CAAC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Ac,CAAC,WAAW,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;gBACvD,CAAC;YACL,CAAC;QACL,CAAC;IACL,CAAC;IAED,MAAM,CAAC,OAA0B;QAC7B,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;IACnD,CAAC;IAED,OAAO;QACH,IAAI,IAAI,CAAC,OAAO,YAAY,gBAAgB,EAAE,CAAC;YAC3C,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;YAC5D,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAC9D,CAAC;IACL,CAAC;IAED,iBAAiB;IACjB,QAAQ;QACJ,IAAI,IAAI,CAAC,OAAO,YAAY,gBAAgB,EAAE,CAAC;YAC3C,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,mBAAmB,CAAC,EAAE,CAAC;IAC7D,CAAC;IAED,SAAS;QACL,OAAO,IAAI,CAAC,aAAa,CAAC;IAC9B,CAAC;IAED,WAAW;QACP,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;QACxB,IAAI,IAAI,CAAC,OAAO,YAAY,gBAAgB,EAAE,CAAC;YAC3C,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAClD,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { TemplateResult } from '../processor/template-result';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for virtual scrolling.
|
|
4
|
+
*/
|
|
5
|
+
export interface VirtualScrollConfig<T> {
|
|
6
|
+
/** Full list of items */
|
|
7
|
+
items: readonly T[];
|
|
8
|
+
/** Fixed height of each item in pixels */
|
|
9
|
+
itemHeight: number;
|
|
10
|
+
/** Height of the scrollable container in pixels */
|
|
11
|
+
containerHeight: number;
|
|
12
|
+
/** Render function for each visible item */
|
|
13
|
+
render: (item: T, index: number) => TemplateResult;
|
|
14
|
+
/** Number of extra items to render above/below the visible area (default: 2) */
|
|
15
|
+
overscan?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Result of a virtual scroll computation.
|
|
19
|
+
* Contains the container styles, spacer info, and rendered visible items.
|
|
20
|
+
*/
|
|
21
|
+
export interface VirtualScrollResult<T> {
|
|
22
|
+
/** CSS styles for the outer scrollable container */
|
|
23
|
+
containerStyle: string;
|
|
24
|
+
/** CSS styles for the inner spacer that maintains total scroll height */
|
|
25
|
+
spacerStyle: string;
|
|
26
|
+
/** CSS styles for the content wrapper positioned at the correct offset */
|
|
27
|
+
contentStyle: string;
|
|
28
|
+
/** The visible items to render */
|
|
29
|
+
visibleItems: {
|
|
30
|
+
item: T;
|
|
31
|
+
index: number;
|
|
32
|
+
template: TemplateResult;
|
|
33
|
+
}[];
|
|
34
|
+
/** Total number of items */
|
|
35
|
+
totalCount: number;
|
|
36
|
+
/** Total scrollable height in px */
|
|
37
|
+
totalHeight: number;
|
|
38
|
+
/** First visible index */
|
|
39
|
+
startIndex: number;
|
|
40
|
+
/** Last visible index (exclusive) */
|
|
41
|
+
endIndex: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Compute which items are visible given a scroll offset, and return
|
|
45
|
+
* the positioning metadata needed to render them.
|
|
46
|
+
*
|
|
47
|
+
* This is a pure function — it does not touch the DOM. The component
|
|
48
|
+
* is responsible for:
|
|
49
|
+
* 1. Providing a scroll container with `overflow-y: auto`
|
|
50
|
+
* 2. Listening for `scroll` events and calling this again
|
|
51
|
+
* 3. Rendering the returned templates
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* @component({ tag: 'my-list' })
|
|
56
|
+
* class MyList extends MiuraElement {
|
|
57
|
+
* declare items: any[];
|
|
58
|
+
* declare scrollTop: number;
|
|
59
|
+
*
|
|
60
|
+
* static properties = {
|
|
61
|
+
* items: { type: Array, default: [] },
|
|
62
|
+
* scrollTop: { type: Number, default: 0 },
|
|
63
|
+
* };
|
|
64
|
+
*
|
|
65
|
+
* private onScroll = (e: Event) => {
|
|
66
|
+
* this.scrollTop = (e.target as HTMLElement).scrollTop;
|
|
67
|
+
* };
|
|
68
|
+
*
|
|
69
|
+
* template() {
|
|
70
|
+
* const vs = computeVirtualSlice({
|
|
71
|
+
* items: this.items,
|
|
72
|
+
* itemHeight: 40,
|
|
73
|
+
* containerHeight: 400,
|
|
74
|
+
* render: (item, i) => html`<div class="row">${item.name}</div>`,
|
|
75
|
+
* }, this.scrollTop);
|
|
76
|
+
*
|
|
77
|
+
* return html`
|
|
78
|
+
* <div style=${vs.containerStyle} @scroll=${this.onScroll}>
|
|
79
|
+
* <div style=${vs.spacerStyle}>
|
|
80
|
+
* <div style=${vs.contentStyle}>
|
|
81
|
+
* ${vs.visibleItems.map(v => v.template)}
|
|
82
|
+
* </div>
|
|
83
|
+
* </div>
|
|
84
|
+
* </div>
|
|
85
|
+
* `;
|
|
86
|
+
* }
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare function computeVirtualSlice<T>(config: VirtualScrollConfig<T>, scrollTop?: number): VirtualScrollResult<T>;
|
|
91
|
+
//# sourceMappingURL=virtual-scroll.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"virtual-scroll.d.ts","sourceRoot":"","sources":["../../../src/directives/virtual-scroll.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D;;GAEG;AACH,MAAM,WAAW,mBAAmB,CAAC,CAAC;IAClC,yBAAyB;IACzB,KAAK,EAAE,SAAS,CAAC,EAAE,CAAC;IACpB,0CAA0C;IAC1C,UAAU,EAAE,MAAM,CAAC;IACnB,mDAAmD;IACnD,eAAe,EAAE,MAAM,CAAC;IACxB,4CAA4C;IAC5C,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,cAAc,CAAC;IACnD,gFAAgF;IAChF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB,CAAC,CAAC;IAClC,oDAAoD;IACpD,cAAc,EAAE,MAAM,CAAC;IACvB,yEAAyE;IACzE,WAAW,EAAE,MAAM,CAAC;IACpB,0EAA0E;IAC1E,YAAY,EAAE,MAAM,CAAC;IACrB,kCAAkC;IAClC,YAAY,EAAE;QAAE,IAAI,EAAE,CAAC,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,cAAc,CAAA;KAAE,EAAE,CAAC;IACrE,4BAA4B;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,oCAAoC;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,0BAA0B;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,qCAAqC;IACrC,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EACjC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC,EAC9B,SAAS,GAAE,MAAU,GACtB,mBAAmB,CAAC,CAAC,CAAC,CAiCxB"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compute which items are visible given a scroll offset, and return
|
|
3
|
+
* the positioning metadata needed to render them.
|
|
4
|
+
*
|
|
5
|
+
* This is a pure function — it does not touch the DOM. The component
|
|
6
|
+
* is responsible for:
|
|
7
|
+
* 1. Providing a scroll container with `overflow-y: auto`
|
|
8
|
+
* 2. Listening for `scroll` events and calling this again
|
|
9
|
+
* 3. Rendering the returned templates
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* @component({ tag: 'my-list' })
|
|
14
|
+
* class MyList extends MiuraElement {
|
|
15
|
+
* declare items: any[];
|
|
16
|
+
* declare scrollTop: number;
|
|
17
|
+
*
|
|
18
|
+
* static properties = {
|
|
19
|
+
* items: { type: Array, default: [] },
|
|
20
|
+
* scrollTop: { type: Number, default: 0 },
|
|
21
|
+
* };
|
|
22
|
+
*
|
|
23
|
+
* private onScroll = (e: Event) => {
|
|
24
|
+
* this.scrollTop = (e.target as HTMLElement).scrollTop;
|
|
25
|
+
* };
|
|
26
|
+
*
|
|
27
|
+
* template() {
|
|
28
|
+
* const vs = computeVirtualSlice({
|
|
29
|
+
* items: this.items,
|
|
30
|
+
* itemHeight: 40,
|
|
31
|
+
* containerHeight: 400,
|
|
32
|
+
* render: (item, i) => html`<div class="row">${item.name}</div>`,
|
|
33
|
+
* }, this.scrollTop);
|
|
34
|
+
*
|
|
35
|
+
* return html`
|
|
36
|
+
* <div style=${vs.containerStyle} @scroll=${this.onScroll}>
|
|
37
|
+
* <div style=${vs.spacerStyle}>
|
|
38
|
+
* <div style=${vs.contentStyle}>
|
|
39
|
+
* ${vs.visibleItems.map(v => v.template)}
|
|
40
|
+
* </div>
|
|
41
|
+
* </div>
|
|
42
|
+
* </div>
|
|
43
|
+
* `;
|
|
44
|
+
* }
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export function computeVirtualSlice(config, scrollTop = 0) {
|
|
49
|
+
const { items, itemHeight, containerHeight, render, overscan = 2 } = config;
|
|
50
|
+
const totalCount = items.length;
|
|
51
|
+
const totalHeight = totalCount * itemHeight;
|
|
52
|
+
// Compute visible range
|
|
53
|
+
const rawStart = Math.floor(scrollTop / itemHeight);
|
|
54
|
+
const visibleCount = Math.ceil(containerHeight / itemHeight);
|
|
55
|
+
const startIndex = Math.max(0, rawStart - overscan);
|
|
56
|
+
const endIndex = Math.min(totalCount, rawStart + visibleCount + overscan);
|
|
57
|
+
// Build visible items
|
|
58
|
+
const visibleItems = [];
|
|
59
|
+
for (let i = startIndex; i < endIndex; i++) {
|
|
60
|
+
visibleItems.push({
|
|
61
|
+
item: items[i],
|
|
62
|
+
index: i,
|
|
63
|
+
template: render(items[i], i)
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const offsetY = startIndex * itemHeight;
|
|
67
|
+
return {
|
|
68
|
+
containerStyle: `overflow-y:auto;height:${containerHeight}px;position:relative;`,
|
|
69
|
+
spacerStyle: `height:${totalHeight}px;position:relative;`,
|
|
70
|
+
contentStyle: `position:absolute;top:${offsetY}px;left:0;right:0;`,
|
|
71
|
+
visibleItems,
|
|
72
|
+
totalCount,
|
|
73
|
+
totalHeight,
|
|
74
|
+
startIndex,
|
|
75
|
+
endIndex,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=virtual-scroll.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"virtual-scroll.js","sourceRoot":"","sources":["../../../src/directives/virtual-scroll.ts"],"names":[],"mappings":"AAyCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,MAAM,UAAU,mBAAmB,CAC/B,MAA8B,EAC9B,YAAoB,CAAC;IAErB,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC;IAC5E,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC;IAChC,MAAM,WAAW,GAAG,UAAU,GAAG,UAAU,CAAC;IAE5C,wBAAwB;IACxB,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,UAAU,CAAC,CAAC;IACpD,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,eAAe,GAAG,UAAU,CAAC,CAAC;IAC7D,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC,CAAC;IACpD,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,GAAG,YAAY,GAAG,QAAQ,CAAC,CAAC;IAE1E,sBAAsB;IACtB,MAAM,YAAY,GAA2C,EAAE,CAAC;IAChE,KAAK,IAAI,CAAC,GAAG,UAAU,EAAE,CAAC,GAAG,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC;QACzC,YAAY,CAAC,IAAI,CAAC;YACd,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;YACd,KAAK,EAAE,CAAC;YACR,QAAQ,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;SAChC,CAAC,CAAC;IACP,CAAC;IAED,MAAM,OAAO,GAAG,UAAU,GAAG,UAAU,CAAC;IAExC,OAAO;QACH,cAAc,EAAE,0BAA0B,eAAe,uBAAuB;QAChF,WAAW,EAAE,UAAU,WAAW,uBAAuB;QACzD,YAAY,EAAE,yBAAyB,OAAO,oBAAoB;QAClE,YAAY;QACZ,UAAU;QACV,WAAW;QACX,UAAU;QACV,QAAQ;KACX,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { TemplateResult } from '../processor/template-result';
|
|
2
|
+
/**
|
|
3
|
+
* Conditional rendering directive.
|
|
4
|
+
*
|
|
5
|
+
* Renders `trueCase` when condition is truthy, `falseCase` when falsy.
|
|
6
|
+
* Unlike ternary expressions, template functions are only called for the
|
|
7
|
+
* active branch — the inactive branch is never evaluated.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* ```ts
|
|
11
|
+
* html`
|
|
12
|
+
* ${when(this.isLoggedIn,
|
|
13
|
+
* () => html`<user-profile .user="${this.user}"></user-profile>`,
|
|
14
|
+
* () => html`<login-form></login-form>`
|
|
15
|
+
* )}
|
|
16
|
+
* `
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @param condition - Truthy/falsy value to test
|
|
20
|
+
* @param trueCase - Template function called when condition is truthy
|
|
21
|
+
* @param falseCase - Optional template function called when condition is falsy
|
|
22
|
+
*/
|
|
23
|
+
export declare function when<T extends TemplateResult>(condition: unknown, trueCase: () => T, falseCase?: () => T): T | undefined;
|
|
24
|
+
//# sourceMappingURL=when.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"when.d.ts","sourceRoot":"","sources":["../../../src/directives/when.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,cAAc,EACzC,SAAS,EAAE,OAAO,EAClB,QAAQ,EAAE,MAAM,CAAC,EACjB,SAAS,CAAC,EAAE,MAAM,CAAC,GACpB,CAAC,GAAG,SAAS,CAEf"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conditional rendering directive.
|
|
3
|
+
*
|
|
4
|
+
* Renders `trueCase` when condition is truthy, `falseCase` when falsy.
|
|
5
|
+
* Unlike ternary expressions, template functions are only called for the
|
|
6
|
+
* active branch — the inactive branch is never evaluated.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* ```ts
|
|
10
|
+
* html`
|
|
11
|
+
* ${when(this.isLoggedIn,
|
|
12
|
+
* () => html`<user-profile .user="${this.user}"></user-profile>`,
|
|
13
|
+
* () => html`<login-form></login-form>`
|
|
14
|
+
* )}
|
|
15
|
+
* `
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param condition - Truthy/falsy value to test
|
|
19
|
+
* @param trueCase - Template function called when condition is truthy
|
|
20
|
+
* @param falseCase - Optional template function called when condition is falsy
|
|
21
|
+
*/
|
|
22
|
+
export function when(condition, trueCase, falseCase) {
|
|
23
|
+
return condition ? trueCase() : falseCase?.();
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=when.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"when.js","sourceRoot":"","sources":["../../../src/directives/when.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,IAAI,CAChB,SAAkB,EAClB,QAAiB,EACjB,SAAmB;IAEnB,OAAO,SAAS,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC;AAClD,CAAC"}
|