@zcomponent/core 0.0.4 → 0.0.5
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/css/zcomponent.css +12 -0
- package/lib/components/LongLoad.d.ts +45 -0
- package/lib/components/LongLoad.js +28 -0
- package/lib/contexts/canvascontext.d.ts +7 -1
- package/lib/contexts/canvascontext.js +28 -3
- package/lib/contexts/environmentcontext.d.ts +1 -0
- package/lib/contexts/environmentcontext.js +3 -0
- package/package.json +1 -1
package/css/zcomponent.css
CHANGED
|
@@ -32,4 +32,16 @@
|
|
|
32
32
|
background-color: white;
|
|
33
33
|
height: 12px;
|
|
34
34
|
border-radius: 6px;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
#zcomponent-overlay {
|
|
38
|
+
position: fixed;
|
|
39
|
+
top: 0;
|
|
40
|
+
left: 0;
|
|
41
|
+
pointer-events: none;
|
|
42
|
+
overflow: hidden;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
#zcomponent-overlay > * {
|
|
46
|
+
pointer-events: auto;
|
|
35
47
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Component, ConstructorProps, ContextManager } from "..";
|
|
2
|
+
export interface LongLoadConstructorProps extends ConstructorProps {
|
|
3
|
+
/**
|
|
4
|
+
* The number of loading processes to simulate
|
|
5
|
+
* @zprop
|
|
6
|
+
* @zgroup LongLoad
|
|
7
|
+
* @zgrouppriority 10
|
|
8
|
+
* @zdefault 10
|
|
9
|
+
*/
|
|
10
|
+
numberOfLoads: number;
|
|
11
|
+
/**
|
|
12
|
+
* The shortest time (in milliseconds) that a given load should take
|
|
13
|
+
* @zprop
|
|
14
|
+
* @zgroup LongLoad
|
|
15
|
+
* @zgrouppriority 10
|
|
16
|
+
* @zdefault 500
|
|
17
|
+
*/
|
|
18
|
+
minimumLoadTime: number;
|
|
19
|
+
/**
|
|
20
|
+
* The shortest time (in milliseconds) that a given load should take
|
|
21
|
+
* @zprop
|
|
22
|
+
* @zgroup LongLoad
|
|
23
|
+
* @zgrouppriority 10
|
|
24
|
+
* @zdefault 5000
|
|
25
|
+
*/
|
|
26
|
+
maximumLoadTime: number;
|
|
27
|
+
/**
|
|
28
|
+
* If the long loading process should occur in production builds (in addition to development builds)
|
|
29
|
+
* @zprop
|
|
30
|
+
* @zgroup LongLoad
|
|
31
|
+
* @zgrouppriority 10
|
|
32
|
+
* @zdefault false
|
|
33
|
+
*/
|
|
34
|
+
runInProduction: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Simulates long random loading times to facilitate development and debugging of loading processes.
|
|
38
|
+
*
|
|
39
|
+
* @zcomponent
|
|
40
|
+
* @zicon settings
|
|
41
|
+
* @zgroup Advanced
|
|
42
|
+
*/
|
|
43
|
+
export declare class LongLoad extends Component<LongLoadConstructorProps> {
|
|
44
|
+
constructor(props: LongLoadConstructorProps, contextManager: ContextManager);
|
|
45
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Component, isDevelopmentBuild, registerLoadable } from "..";
|
|
2
|
+
/**
|
|
3
|
+
* Simulates long random loading times to facilitate development and debugging of loading processes.
|
|
4
|
+
*
|
|
5
|
+
* @zcomponent
|
|
6
|
+
* @zicon settings
|
|
7
|
+
* @zgroup Advanced
|
|
8
|
+
*/
|
|
9
|
+
export class LongLoad extends Component {
|
|
10
|
+
constructor(props, contextManager) {
|
|
11
|
+
super(props, contextManager);
|
|
12
|
+
if (!props.runInProduction && !isDevelopmentBuild(contextManager))
|
|
13
|
+
return;
|
|
14
|
+
const minimumLoadTime = props.minimumLoadTime ?? 500;
|
|
15
|
+
const maximumLoadTime = props.maximumLoadTime ?? 5000;
|
|
16
|
+
for (let i = 0; i < (props.numberOfLoads ?? 10); i++) {
|
|
17
|
+
registerLoadable(contextManager, new Promise(resolve => {
|
|
18
|
+
if (this.disposed)
|
|
19
|
+
return;
|
|
20
|
+
setTimeout(() => {
|
|
21
|
+
if (this.disposed)
|
|
22
|
+
return;
|
|
23
|
+
resolve();
|
|
24
|
+
}, minimumLoadTime + Math.random() * (maximumLoadTime - minimumLoadTime));
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -7,9 +7,15 @@ export interface CanvasContext {
|
|
|
7
7
|
onAfterRender: Event<[number]>;
|
|
8
8
|
size: Observable<[number, number]>;
|
|
9
9
|
dispose: () => void;
|
|
10
|
+
overlayDefault: HTMLDivElement;
|
|
11
|
+
overlay: Observable<HTMLDivElement>;
|
|
10
12
|
}
|
|
11
|
-
export
|
|
13
|
+
export interface CanvasContextOptions {
|
|
14
|
+
overlay: HTMLDivElement;
|
|
15
|
+
}
|
|
16
|
+
export declare const CanvasContext: import("../context").ContextTypeWithDefault<CanvasContext, [canvas?: HTMLCanvasElement | undefined, options?: CanvasContextOptions | undefined]>;
|
|
12
17
|
export declare function useCanvas(mgr: ContextManager): HTMLCanvasElement;
|
|
18
|
+
export declare function useOverlay(mgr: ContextManager): Observable<HTMLDivElement, never>;
|
|
13
19
|
export declare function useCanvasSize(mgr: ContextManager): Observable<[number, number], never>;
|
|
14
20
|
export declare function useOnBeforeRender(mgr: ContextManager): Event<[number]>;
|
|
15
21
|
export declare function useOnAfterRender(mgr: ContextManager): Event<[number]>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineContextType } from '../context';
|
|
2
2
|
import { Event } from '../event';
|
|
3
3
|
import { Observable } from '../observable';
|
|
4
|
-
export const CanvasContext = defineContextType((ctx, canvas) => {
|
|
4
|
+
export const CanvasContext = defineContextType((ctx, canvas, options) => {
|
|
5
5
|
if (!canvas) {
|
|
6
6
|
canvas = document.createElement("canvas");
|
|
7
7
|
canvas.style.position = "fixed";
|
|
@@ -12,6 +12,11 @@ export const CanvasContext = defineContextType((ctx, canvas) => {
|
|
|
12
12
|
canvas.style.touchAction = "none";
|
|
13
13
|
document.body.append(canvas);
|
|
14
14
|
}
|
|
15
|
+
const overlayDefault = options?.overlay ?? document.createElement('div');
|
|
16
|
+
overlayDefault.id = 'zcomponent-overlay';
|
|
17
|
+
if (!options?.overlay) {
|
|
18
|
+
document.body.append(overlayDefault);
|
|
19
|
+
}
|
|
15
20
|
const size = new Observable([canvas.clientWidth, canvas.clientHeight]);
|
|
16
21
|
const resizeObserver = new ResizeObserver(entries => {
|
|
17
22
|
for (const entry of entries) {
|
|
@@ -21,12 +26,29 @@ export const CanvasContext = defineContextType((ctx, canvas) => {
|
|
|
21
26
|
}
|
|
22
27
|
});
|
|
23
28
|
resizeObserver.observe(canvas);
|
|
29
|
+
const onBeforeRender = new Event();
|
|
30
|
+
let lastRect;
|
|
31
|
+
onBeforeRender.bindfn(() => {
|
|
32
|
+
const rect = canvas.getBoundingClientRect();
|
|
33
|
+
if (lastRect && lastRect.top === rect.top && lastRect.left === rect.left && lastRect.width === rect.width && lastRect.height === rect.height)
|
|
34
|
+
return;
|
|
35
|
+
overlayDefault.style.top = rect.top.toString() + 'px';
|
|
36
|
+
overlayDefault.style.left = rect.left.toString() + 'px';
|
|
37
|
+
overlayDefault.style.width = rect.width.toString() + 'px';
|
|
38
|
+
overlayDefault.style.height = rect.height.toString() + 'px';
|
|
39
|
+
lastRect = rect;
|
|
40
|
+
});
|
|
41
|
+
const onAfterRender = new Event();
|
|
24
42
|
return {
|
|
25
43
|
canvas,
|
|
26
|
-
onBeforeRender
|
|
27
|
-
onAfterRender
|
|
44
|
+
onBeforeRender,
|
|
45
|
+
onAfterRender,
|
|
28
46
|
size,
|
|
47
|
+
overlayDefault,
|
|
48
|
+
overlay: new Observable(overlayDefault, undefined, false),
|
|
29
49
|
dispose: () => {
|
|
50
|
+
onBeforeRender.clear();
|
|
51
|
+
onAfterRender.clear();
|
|
30
52
|
resizeObserver.disconnect();
|
|
31
53
|
}
|
|
32
54
|
};
|
|
@@ -34,6 +56,9 @@ export const CanvasContext = defineContextType((ctx, canvas) => {
|
|
|
34
56
|
export function useCanvas(mgr) {
|
|
35
57
|
return mgr.get(CanvasContext).canvas;
|
|
36
58
|
}
|
|
59
|
+
export function useOverlay(mgr) {
|
|
60
|
+
return mgr.get(CanvasContext).overlay;
|
|
61
|
+
}
|
|
37
62
|
export function useCanvasSize(mgr) {
|
|
38
63
|
return mgr.get(CanvasContext).size;
|
|
39
64
|
}
|
|
@@ -7,3 +7,4 @@ export interface EnvirontmentContext {
|
|
|
7
7
|
export declare const EnvironmentContext: import("../context").ContextTypeWithDefault<EnvirontmentContext, []>;
|
|
8
8
|
export declare function isDesignTime(ctx: ContextManager): boolean;
|
|
9
9
|
export declare function isEditTime(ctx: ContextManager): boolean;
|
|
10
|
+
export declare function isDevelopmentBuild(ctx: ContextManager): boolean;
|
|
@@ -12,3 +12,6 @@ export function isDesignTime(ctx) {
|
|
|
12
12
|
export function isEditTime(ctx) {
|
|
13
13
|
return ctx.get(EnvironmentContext).editTime.value;
|
|
14
14
|
}
|
|
15
|
+
export function isDevelopmentBuild(ctx) {
|
|
16
|
+
return (typeof process !== 'undefined' && process?.env?.NODE_ENV === 'development');
|
|
17
|
+
}
|