vevet 3.16.0 → 3.18.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 +5 -1
- package/lib/cjs/Application/events/createOnPageLoad/index.js +36 -0
- package/lib/cjs/Application/events/createOnPageLoad/index.js.map +1 -0
- package/lib/cjs/Application/events/createOnPageLoad/types.js.map +1 -0
- package/lib/cjs/Application/events/createViewport/index.js +144 -0
- package/lib/cjs/Application/events/createViewport/index.js.map +1 -0
- package/lib/cjs/Application/events/createViewport/types.js.map +1 -0
- package/lib/cjs/Application/index.js +13 -13
- package/lib/cjs/Application/index.js.map +1 -1
- package/lib/cjs/base/Callbacks/index.js +37 -22
- package/lib/cjs/base/Callbacks/index.js.map +1 -1
- package/lib/cjs/base/Module/index.js +1 -1
- package/lib/cjs/base/Module/index.js.map +1 -1
- package/lib/cjs/base/MutableProps/index.js +1 -1
- package/lib/cjs/base/MutableProps/index.js.map +1 -1
- package/lib/cjs/utils/listeners/onResize.js +1 -3
- package/lib/cjs/utils/listeners/onResize.js.map +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/Application/events/createOnPageLoad/index.js +32 -0
- package/lib/esm/Application/events/createOnPageLoad/index.js.map +1 -0
- package/lib/esm/Application/events/createOnPageLoad/types.js.map +1 -0
- package/lib/esm/Application/events/createViewport/index.js +140 -0
- package/lib/esm/Application/events/createViewport/index.js.map +1 -0
- package/lib/esm/Application/events/createViewport/types.js.map +1 -0
- package/lib/esm/Application/index.js +9 -9
- package/lib/esm/Application/index.js.map +1 -1
- package/lib/esm/base/Callbacks/index.js +37 -21
- package/lib/esm/base/Callbacks/index.js.map +1 -1
- package/lib/esm/base/Module/index.js +1 -1
- package/lib/esm/base/Module/index.js.map +1 -1
- package/lib/esm/base/MutableProps/index.js +1 -1
- package/lib/esm/base/MutableProps/index.js.map +1 -1
- package/lib/esm/utils/listeners/onResize.js +1 -1
- package/lib/esm/utils/listeners/onResize.js.map +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/types/Application/events/createOnPageLoad/index.d.ts +5 -0
- package/lib/types/Application/events/createOnPageLoad/index.d.ts.map +1 -0
- package/lib/types/Application/events/createOnPageLoad/types.d.ts +5 -0
- package/lib/types/Application/events/createOnPageLoad/types.d.ts.map +1 -0
- package/lib/types/Application/events/createViewport/index.d.ts +20 -0
- package/lib/types/Application/events/createViewport/index.d.ts.map +1 -0
- package/lib/types/Application/events/createViewport/types.d.ts.map +1 -0
- package/lib/types/Application/index.d.ts +21 -7
- package/lib/types/Application/index.d.ts.map +1 -1
- package/lib/types/base/Callbacks/index.d.ts +37 -18
- package/lib/types/base/Callbacks/index.d.ts.map +1 -1
- package/lib/types/base/Module/index.d.ts +2 -2
- package/lib/types/base/Module/index.d.ts.map +1 -1
- package/lib/types/utils/listeners/onResize.d.ts +1 -1
- package/lib/types/utils/listeners/onResize.d.ts.map +1 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +4 -4
- package/src/Application/events/.eslintrc +5 -0
- package/src/Application/events/createOnPageLoad/index.ts +43 -0
- package/src/Application/events/createOnPageLoad/types.ts +5 -0
- package/src/Application/events/createViewport/index.ts +165 -0
- package/src/Application/events/{Viewport → createViewport}/stories/index.tsx +1 -1
- package/src/Application/index.ts +13 -13
- package/src/Application/stories/index.tsx +6 -8
- package/src/base/Callbacks/index.ts +38 -24
- package/src/base/Callbacks/stories/index.tsx +29 -34
- package/src/base/Module/index.ts +3 -3
- package/src/base/MutableProps/index.ts +1 -1
- package/src/utils/listeners/onResize.ts +4 -3
- package/src/version.ts +1 -1
- package/lib/cjs/Application/events/PageLoad/index.js +0 -84
- package/lib/cjs/Application/events/PageLoad/index.js.map +0 -1
- package/lib/cjs/Application/events/PageLoad/types.js.map +0 -1
- package/lib/cjs/Application/events/Viewport/index.js +0 -263
- package/lib/cjs/Application/events/Viewport/index.js.map +0 -1
- package/lib/cjs/Application/events/Viewport/types.js.map +0 -1
- package/lib/esm/Application/events/PageLoad/index.js +0 -55
- package/lib/esm/Application/events/PageLoad/index.js.map +0 -1
- package/lib/esm/Application/events/PageLoad/types.js.map +0 -1
- package/lib/esm/Application/events/Viewport/index.js +0 -188
- package/lib/esm/Application/events/Viewport/index.js.map +0 -1
- package/lib/esm/Application/events/Viewport/types.js.map +0 -1
- package/lib/types/Application/events/PageLoad/index.d.ts +0 -25
- package/lib/types/Application/events/PageLoad/index.d.ts.map +0 -1
- package/lib/types/Application/events/PageLoad/types.d.ts +0 -7
- package/lib/types/Application/events/PageLoad/types.d.ts.map +0 -1
- package/lib/types/Application/events/Viewport/index.d.ts +0 -55
- package/lib/types/Application/events/Viewport/index.d.ts.map +0 -1
- package/lib/types/Application/events/Viewport/types.d.ts.map +0 -1
- package/src/Application/events/PageLoad/index.ts +0 -82
- package/src/Application/events/PageLoad/stories/index.stories.tsx +0 -13
- package/src/Application/events/PageLoad/stories/index.tsx +0 -16
- package/src/Application/events/PageLoad/types.ts +0 -7
- package/src/Application/events/Viewport/index.ts +0 -242
- /package/lib/cjs/Application/events/{PageLoad → createOnPageLoad}/types.js +0 -0
- /package/lib/cjs/Application/events/{Viewport → createViewport}/types.js +0 -0
- /package/lib/esm/Application/events/{PageLoad → createOnPageLoad}/types.js +0 -0
- /package/lib/esm/Application/events/{Viewport → createViewport}/types.js +0 -0
- /package/lib/types/Application/events/{Viewport → createViewport}/types.d.ts +0 -0
- /package/src/Application/events/{Viewport → createViewport}/stories/index.stories.tsx +0 -0
- /package/src/Application/events/{Viewport → createViewport}/types.ts +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NViewport } from '../../Application/events/
|
|
1
|
+
import { NViewport } from '../../Application/events/createViewport';
|
|
2
2
|
export type TOnResizeTarget = keyof NViewport.ICallbacksTypes;
|
|
3
3
|
export interface IOnResizeCallbackProps {
|
|
4
4
|
trigger: 'unknown' | 'Viewport' | 'ResizeObserver';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onResize.d.ts","sourceRoot":"","sources":["../../../../src/utils/listeners/onResize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"onResize.d.ts","sourceRoot":"","sources":["../../../../src/utils/listeners/onResize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGpE,MAAM,MAAM,eAAe,GAAG,MAAM,SAAS,CAAC,eAAe,CAAC;AAE9D,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,SAAS,GAAG,UAAU,GAAG,gBAAgB,CAAC;CACpD;AAED,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,sBAAsB,KAAK,IAAI,CAAC;AAExE,MAAM,WAAW,cAAc;IAC7B,yBAAyB;IACzB,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,yBAAyB;IACzB,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,EAAE,GAAG,KAAK,CAAC;IACtC;;;;;OAKG;IACH,cAAc,CAAC,EAAE,eAAe,CAAC;IACjC;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,SAAS;IACxB,2BAA2B;IAC3B,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,6BAA6B;IAC7B,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,2CAA2C;IAC3C,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,gCAAgC;IAChC,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,QAAQ,CAAC,EACvB,QAAQ,EAAE,YAAY,EACtB,OAAO,EACP,cAAsB,EACtB,aAAqB,EACrB,cAAkB,GACnB,EAAE,cAAc,GAAG,SAAS,CA+D5B"}
|
package/lib/types/version.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vevet",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.18.0",
|
|
4
4
|
"description": "Vevet - a JavaScript library of ready-made solutions and helpers",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"storybook": "storybook dev -p 6006",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"vevet-dom": "^0.0.15"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@anton.bobrov/eslint-config": "2.0.
|
|
70
|
+
"@anton.bobrov/eslint-config": "2.0.2",
|
|
71
71
|
"@babel/preset-env": "^7.22.10",
|
|
72
72
|
"@babel/preset-react": "^7.18.6",
|
|
73
73
|
"@babel/preset-typescript": "^7.22.5",
|
|
@@ -90,12 +90,12 @@
|
|
|
90
90
|
"react": "^18.2.0",
|
|
91
91
|
"react-dom": "^18.2.0",
|
|
92
92
|
"rimraf": "^5.0.1",
|
|
93
|
-
"sass": "
|
|
93
|
+
"sass": "^1.77.8",
|
|
94
94
|
"storybook": "^7.3.2",
|
|
95
95
|
"stylelint": "^14.11.0",
|
|
96
96
|
"stylelint-config-sass-guidelines": "^9.0.1",
|
|
97
97
|
"tsc-alias": "^1.8.7",
|
|
98
98
|
"typedoc": "^0.24.8",
|
|
99
|
-
"typescript": "^5
|
|
99
|
+
"typescript": "^5"
|
|
100
100
|
}
|
|
101
101
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { addEventListener } from 'vevet-dom';
|
|
2
|
+
import { getApp } from '@/utils/internal/getApp';
|
|
3
|
+
import { Callbacks } from '@/base/Callbacks';
|
|
4
|
+
import { ICallbacksTypes } from './types';
|
|
5
|
+
|
|
6
|
+
export function createOnPageLoad() {
|
|
7
|
+
const callbacks = new Callbacks<ICallbacksTypes>();
|
|
8
|
+
|
|
9
|
+
let isLoaded = false;
|
|
10
|
+
|
|
11
|
+
if (document.readyState === 'complete') {
|
|
12
|
+
handleLoaded();
|
|
13
|
+
} else {
|
|
14
|
+
addEventListener(window, 'load', () => handleLoaded());
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Callback on page loaded */
|
|
18
|
+
function handleLoaded() {
|
|
19
|
+
const app = getApp();
|
|
20
|
+
const { prefix } = app;
|
|
21
|
+
|
|
22
|
+
isLoaded = true;
|
|
23
|
+
|
|
24
|
+
app.html.classList.remove(`${prefix}loading`);
|
|
25
|
+
app.body.classList.remove(`${prefix}loading`);
|
|
26
|
+
|
|
27
|
+
app.html.classList.add(`${prefix}loaded`);
|
|
28
|
+
|
|
29
|
+
callbacks.tbt('loaded', undefined);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function onLoad(callback: () => void) {
|
|
33
|
+
if (isLoaded) {
|
|
34
|
+
callback();
|
|
35
|
+
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return callbacks.add('loaded', () => callback());
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return { onLoad, getIsLoaded: () => isLoaded };
|
|
43
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { addEventListener } from 'vevet-dom';
|
|
2
|
+
import { getApp } from '@/utils/internal/getApp';
|
|
3
|
+
import { EOrientationTypes, ESizeTypes, NViewport } from './types';
|
|
4
|
+
import { Callbacks } from '@/base/Callbacks';
|
|
5
|
+
|
|
6
|
+
export function createViewport() {
|
|
7
|
+
// create callbacks
|
|
8
|
+
const callbacks = new Callbacks<NViewport.ICallbacksTypes>();
|
|
9
|
+
|
|
10
|
+
// defaults
|
|
11
|
+
const data = {
|
|
12
|
+
callbacks,
|
|
13
|
+
width: 0,
|
|
14
|
+
height: 0,
|
|
15
|
+
radius: 0,
|
|
16
|
+
vw: 0,
|
|
17
|
+
vh: 0,
|
|
18
|
+
vr: 0,
|
|
19
|
+
isLandscape: false,
|
|
20
|
+
isPortrait: false,
|
|
21
|
+
isDesktop: false,
|
|
22
|
+
isTablet: false,
|
|
23
|
+
isPhone: false,
|
|
24
|
+
dpr: window.devicePixelRatio,
|
|
25
|
+
lowerDesktopDpr: window.devicePixelRatio,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// update values for the first time
|
|
29
|
+
updateValues();
|
|
30
|
+
|
|
31
|
+
// set resize events
|
|
32
|
+
|
|
33
|
+
let resizeTimeout: NodeJS.Timeout | undefined;
|
|
34
|
+
|
|
35
|
+
addEventListener(window, 'resize', () => {
|
|
36
|
+
if (resizeTimeout) {
|
|
37
|
+
clearTimeout(resizeTimeout);
|
|
38
|
+
resizeTimeout = undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
resizeTimeout = setTimeout(() => {
|
|
42
|
+
onResize();
|
|
43
|
+
resizeTimeout = undefined;
|
|
44
|
+
}, getApp().props.resizeDebounce);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// methods
|
|
48
|
+
|
|
49
|
+
function onResize() {
|
|
50
|
+
const { width: prevWidth, height: prevHeight } = data;
|
|
51
|
+
|
|
52
|
+
updateValues();
|
|
53
|
+
|
|
54
|
+
const { width, height } = data;
|
|
55
|
+
|
|
56
|
+
// get changes in viewport
|
|
57
|
+
const changes: NViewport.IChanges = {
|
|
58
|
+
isWidthChanged: width !== prevWidth,
|
|
59
|
+
isHeightChanged: height !== prevHeight,
|
|
60
|
+
isOrientationChanged: width > height !== prevWidth > prevHeight,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
if (width !== prevWidth && height === prevHeight) {
|
|
64
|
+
callbacks.tbt('widthOnly', changes);
|
|
65
|
+
}
|
|
66
|
+
if (height !== prevHeight && width === prevWidth) {
|
|
67
|
+
callbacks.tbt('heightOnly', changes);
|
|
68
|
+
}
|
|
69
|
+
if (width !== prevWidth && height !== prevHeight) {
|
|
70
|
+
callbacks.tbt('both', changes);
|
|
71
|
+
}
|
|
72
|
+
if (width !== prevWidth) {
|
|
73
|
+
callbacks.tbt('width', changes);
|
|
74
|
+
}
|
|
75
|
+
if (height !== prevHeight) {
|
|
76
|
+
callbacks.tbt('height', changes);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
callbacks.tbt('any', changes);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function updateValues() {
|
|
83
|
+
const app = getApp();
|
|
84
|
+
const { html, props } = app;
|
|
85
|
+
|
|
86
|
+
// get width
|
|
87
|
+
const width =
|
|
88
|
+
props.widthDetection === 'boundingRect'
|
|
89
|
+
? parseFloat(html.getBoundingClientRect().width.toFixed(3))
|
|
90
|
+
: html.clientWidth;
|
|
91
|
+
|
|
92
|
+
// set sizes
|
|
93
|
+
data.width = width;
|
|
94
|
+
data.height = html.clientHeight;
|
|
95
|
+
data.radius = Math.sqrt(data.width ** 2 + data.height ** 2) / 2;
|
|
96
|
+
data.vw = data.width / 100;
|
|
97
|
+
data.vh = data.height / 100;
|
|
98
|
+
data.vr = data.radius / 100;
|
|
99
|
+
data.isLandscape = data.width > data.height;
|
|
100
|
+
data.isPortrait = data.width < data.height;
|
|
101
|
+
data.isDesktop = data.width > props.tablet;
|
|
102
|
+
data.isTablet = data.width <= props.tablet && data.width > props.phone;
|
|
103
|
+
data.isPhone = data.width <= props.phone;
|
|
104
|
+
data.dpr = window.devicePixelRatio;
|
|
105
|
+
data.lowerDesktopDpr = data.dpr < 1 ? 1 : data.dpr;
|
|
106
|
+
data.isDesktop = data.width > props.tablet;
|
|
107
|
+
data.isTablet = data.width <= props.tablet && data.width > props.phone;
|
|
108
|
+
data.isPhone = data.width <= props.phone;
|
|
109
|
+
data.dpr = window.devicePixelRatio;
|
|
110
|
+
data.lowerDesktopDpr = app.isDesktop ? 1 : data.dpr;
|
|
111
|
+
|
|
112
|
+
// update states
|
|
113
|
+
updateClassNames();
|
|
114
|
+
updateCSSVars();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function updateClassNames() {
|
|
118
|
+
const viewportSizeTypes: ESizeTypes[] = [
|
|
119
|
+
ESizeTypes.Desktop,
|
|
120
|
+
ESizeTypes.Tablet,
|
|
121
|
+
ESizeTypes.Phone,
|
|
122
|
+
];
|
|
123
|
+
|
|
124
|
+
if (data.isDesktop) {
|
|
125
|
+
updateBreakpointClassNames(ESizeTypes.Desktop, viewportSizeTypes);
|
|
126
|
+
} else if (data.isTablet) {
|
|
127
|
+
updateBreakpointClassNames(ESizeTypes.Tablet, viewportSizeTypes);
|
|
128
|
+
} else {
|
|
129
|
+
updateBreakpointClassNames(ESizeTypes.Phone, viewportSizeTypes);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const orientationTypes: EOrientationTypes[] = [
|
|
133
|
+
EOrientationTypes.Landscape,
|
|
134
|
+
EOrientationTypes.Portrait,
|
|
135
|
+
];
|
|
136
|
+
|
|
137
|
+
if (data.isLandscape) {
|
|
138
|
+
updateBreakpointClassNames(EOrientationTypes.Landscape, orientationTypes);
|
|
139
|
+
} else if (data.isPortrait) {
|
|
140
|
+
updateBreakpointClassNames(EOrientationTypes.Portrait, orientationTypes);
|
|
141
|
+
} else {
|
|
142
|
+
updateBreakpointClassNames('', orientationTypes);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function updateBreakpointClassNames(activeType: string, types: string[]) {
|
|
147
|
+
const { html, prefix } = getApp();
|
|
148
|
+
|
|
149
|
+
types.forEach((type) => {
|
|
150
|
+
html.classList.toggle(`${prefix}viewport-${type}`, type === activeType);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function updateCSSVars() {
|
|
155
|
+
const { html } = getApp();
|
|
156
|
+
|
|
157
|
+
html.style.setProperty('--vw', `${data.vw}px`);
|
|
158
|
+
html.style.setProperty('--vh', `${data.vh}px`);
|
|
159
|
+
html.style.setProperty('--vr', `${data.vr}px`);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return data;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export type { NViewport };
|
|
@@ -30,7 +30,7 @@ export const Component: FC = () => {
|
|
|
30
30
|
useEffect(() => {
|
|
31
31
|
updateFeatures();
|
|
32
32
|
|
|
33
|
-
const callback = viewport.add('any', () => updateFeatures());
|
|
33
|
+
const callback = viewport.callbacks.add('any', () => updateFeatures());
|
|
34
34
|
|
|
35
35
|
return () => callback.remove();
|
|
36
36
|
}, [updateFeatures]);
|
package/src/Application/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Viewport, NViewport } from './events/Viewport';
|
|
2
|
-
import { PageLoad, NPageLoad } from './events/PageLoad';
|
|
3
1
|
import version from '../version';
|
|
4
2
|
import { NApplication } from './types';
|
|
5
3
|
import { getDeviceInfo } from '@/utils/internal/getDeviceInfo';
|
|
6
4
|
import { fetchWebpSupport } from '@/utils/internal/fetchWebpSupport';
|
|
7
5
|
import { PCancelable } from '@/utils/common/PCancelable';
|
|
6
|
+
import { createOnPageLoad } from './events/createOnPageLoad';
|
|
7
|
+
import { createViewport, NViewport } from './events/createViewport';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Vevet Application. This is the base Vevet class
|
|
@@ -97,14 +97,9 @@ export class Application {
|
|
|
97
97
|
return this._isWebpSupported;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
private _pageLoad:
|
|
100
|
+
private _pageLoad: ReturnType<typeof createOnPageLoad>;
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
get pageLoad() {
|
|
104
|
-
return this._pageLoad;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
private _viewport: Viewport;
|
|
102
|
+
private _viewport: ReturnType<typeof createViewport>;
|
|
108
103
|
|
|
109
104
|
/** Viewport Callbacks */
|
|
110
105
|
get viewport() {
|
|
@@ -135,8 +130,8 @@ export class Application {
|
|
|
135
130
|
window.vevetApp = this;
|
|
136
131
|
|
|
137
132
|
// create default helpers
|
|
138
|
-
this._pageLoad =
|
|
139
|
-
this._viewport =
|
|
133
|
+
this._pageLoad = createOnPageLoad();
|
|
134
|
+
this._viewport = createViewport();
|
|
140
135
|
}
|
|
141
136
|
|
|
142
137
|
/** Get and set device info */
|
|
@@ -187,15 +182,20 @@ export class Application {
|
|
|
187
182
|
return document.body;
|
|
188
183
|
}
|
|
189
184
|
|
|
190
|
-
/** Action on page
|
|
185
|
+
/** Action on page load */
|
|
191
186
|
public onPageLoad() {
|
|
192
187
|
return new PCancelable((resolve: (...arg: any) => void) =>
|
|
193
188
|
this._pageLoad.onLoad(resolve),
|
|
194
189
|
);
|
|
195
190
|
}
|
|
191
|
+
|
|
192
|
+
/** Check if page is loaded */
|
|
193
|
+
get isPageLoaded() {
|
|
194
|
+
return this._pageLoad.getIsLoaded();
|
|
195
|
+
}
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
export type { NApplication, NViewport
|
|
198
|
+
export type { NApplication, NViewport };
|
|
199
199
|
|
|
200
200
|
declare global {
|
|
201
201
|
interface Window {
|
|
@@ -17,22 +17,20 @@ export const Component: FC = () => {
|
|
|
17
17
|
'browserName',
|
|
18
18
|
'osName',
|
|
19
19
|
'isWebpSupported',
|
|
20
|
+
'isPageLoaded',
|
|
20
21
|
]);
|
|
21
22
|
|
|
22
23
|
setFeatures(object);
|
|
23
24
|
}, []);
|
|
24
25
|
|
|
25
|
-
useEffect(() =>
|
|
26
|
-
updateFeatures();
|
|
27
|
-
|
|
28
|
-
const promise = vevet.onPageLoad();
|
|
29
|
-
promise.then(() => updateFeatures()).catch(() => {});
|
|
30
|
-
|
|
31
|
-
return () => promise.cancel();
|
|
32
|
-
}, [updateFeatures]);
|
|
26
|
+
useEffect(() => updateFeatures(), [updateFeatures]);
|
|
33
27
|
|
|
34
28
|
return (
|
|
35
29
|
<div>
|
|
30
|
+
<button type="button" onClick={updateFeatures}>
|
|
31
|
+
Update features
|
|
32
|
+
</button>
|
|
33
|
+
|
|
36
34
|
{features &&
|
|
37
35
|
Object.keys(features).map((key) => {
|
|
38
36
|
const value = features[key];
|
|
@@ -4,7 +4,7 @@ import { NCallbacks } from './types';
|
|
|
4
4
|
export type { NCallbacks };
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* This class is responsible for adding, removing, and executing callbacks of different kinds.
|
|
8
8
|
*/
|
|
9
9
|
export class Callbacks<Types extends NCallbacks.ITypes = NCallbacks.ITypes> {
|
|
10
10
|
/** List of callbacks */
|
|
@@ -16,35 +16,49 @@ export class Callbacks<Types extends NCallbacks.ITypes = NCallbacks.ITypes> {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* @param canInit - Defines if you need to call {@linkcode Callbacks._init} at the constructor's end.
|
|
20
|
-
* If no, you will have to call {@linkcode Callbacks._init} manually.
|
|
21
|
-
*
|
|
22
19
|
* @example
|
|
23
|
-
*
|
|
24
|
-
* interface
|
|
25
|
-
*
|
|
26
|
-
*
|
|
20
|
+
*
|
|
21
|
+
* interface ICallbacks {
|
|
22
|
+
* onAdd: undefined;
|
|
23
|
+
* onDelete: undefined;
|
|
27
24
|
* }
|
|
28
|
-
|
|
29
|
-
* const callbacks = new Callbacks<
|
|
30
|
-
|
|
31
|
-
* callbacks.add('
|
|
32
|
-
|
|
33
|
-
* callbacks.add('
|
|
34
|
-
*
|
|
35
|
-
*
|
|
25
|
+
*
|
|
26
|
+
* const callbacks = new Callbacks<ICallbacks>();
|
|
27
|
+
*
|
|
28
|
+
* callbacks.add('onAdd', () => console.log('callback on add #1'));
|
|
29
|
+
*
|
|
30
|
+
* const addCallback2 = callbacks.add('onAdd', () =>
|
|
31
|
+
* console.log('callback on add #2'),
|
|
32
|
+
* );
|
|
33
|
+
*
|
|
34
|
+
* const addCallback3 = callbacks.add(
|
|
35
|
+
* 'onAdd',
|
|
36
|
+
* () => console.log('callback on add #3'),
|
|
37
|
+
* { isProtected: true },
|
|
38
|
+
* );
|
|
39
|
+
*
|
|
40
|
+
* callbacks.add('onDelete', () => console.log('callback on delete'));
|
|
41
|
+
*
|
|
42
|
+
* console.log('--- All callbacks by the target "onAdd" will be executed:');
|
|
43
|
+
* callbacks.tbt('onAdd', undefined);
|
|
44
|
+
*
|
|
45
|
+
* console.log('--- addCallback2 will be removed:');
|
|
46
|
+
* addCallback2.remove();
|
|
47
|
+
* callbacks.tbt('onAdd', undefined);
|
|
48
|
+
* console.log('---');
|
|
49
|
+
*
|
|
50
|
+
* console.log('--- addCallback3 cannot be removed because it is protected:');
|
|
51
|
+
* addCallback3.remove();
|
|
52
|
+
* callbacks.tbt('onAdd', undefined);
|
|
53
|
+
* console.log('---');
|
|
54
|
+
*
|
|
55
|
+
* console.log('--- Execute all callbacks by the target "onDelete":');
|
|
56
|
+
* callbacks.tbt('onDelete', undefined);
|
|
36
57
|
*/
|
|
37
|
-
constructor(
|
|
58
|
+
constructor() {
|
|
38
59
|
this._callbacks = [];
|
|
39
|
-
|
|
40
|
-
if (canInit) {
|
|
41
|
-
this._init();
|
|
42
|
-
}
|
|
43
60
|
}
|
|
44
61
|
|
|
45
|
-
/** Initialize the class */
|
|
46
|
-
protected _init() {}
|
|
47
|
-
|
|
48
62
|
/**
|
|
49
63
|
* Adds a callback
|
|
50
64
|
*
|
|
@@ -1,53 +1,48 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import React, { FC, useEffect } from 'react';
|
|
2
3
|
import { Callbacks } from '..';
|
|
3
4
|
|
|
4
|
-
interface
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
interface ICallbacks {
|
|
6
|
+
onAdd: undefined;
|
|
7
|
+
onDelete: undefined;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
export const Component: FC = () => {
|
|
10
11
|
useEffect(() => {
|
|
11
|
-
const callbacks = new Callbacks<
|
|
12
|
+
const callbacks = new Callbacks<ICallbacks>();
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
name: 'render simple',
|
|
15
|
-
});
|
|
14
|
+
callbacks.add('onAdd', () => console.log('callback on add #1'));
|
|
16
15
|
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const addCallback2 = callbacks.add('onAdd', () =>
|
|
17
|
+
console.log('callback on add #2'),
|
|
18
|
+
);
|
|
20
19
|
|
|
21
|
-
callbacks.add(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
const addCallback3 = callbacks.add(
|
|
21
|
+
'onAdd',
|
|
22
|
+
() => console.log('callback on add #3'),
|
|
23
|
+
{ isProtected: true },
|
|
24
|
+
);
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
isProtected: true,
|
|
28
|
-
name: 'empty protected',
|
|
29
|
-
});
|
|
26
|
+
callbacks.add('onDelete', () => console.log('callback on delete'));
|
|
30
27
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
isOnce: true,
|
|
34
|
-
name: 'empty protected and once',
|
|
35
|
-
});
|
|
28
|
+
console.log('--- All callbacks by the target "onAdd" will be executed:');
|
|
29
|
+
callbacks.tbt('onAdd', undefined);
|
|
36
30
|
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
console.log('--- addCallback2 will be removed:');
|
|
32
|
+
addCallback2.remove();
|
|
33
|
+
callbacks.tbt('onAdd', undefined);
|
|
34
|
+
console.log('---');
|
|
39
35
|
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
console.log('--- addCallback3 cannot be removed because it is protected:');
|
|
37
|
+
addCallback3.remove();
|
|
38
|
+
callbacks.tbt('onAdd', undefined);
|
|
39
|
+
console.log('---');
|
|
42
40
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
emptyProtected.remove();
|
|
46
|
-
// eslint-disable-next-line no-console
|
|
47
|
-
console.log(callbacks.callbacks.map(({ name }) => name));
|
|
41
|
+
console.log('--- Execute all callbacks by the target "onDelete":');
|
|
42
|
+
callbacks.tbt('onDelete', undefined);
|
|
48
43
|
|
|
49
44
|
return () => callbacks.destroy();
|
|
50
45
|
}, []);
|
|
51
46
|
|
|
52
|
-
return
|
|
47
|
+
return <p>Open the console to see the output</p>;
|
|
53
48
|
};
|
package/src/base/Module/index.ts
CHANGED
|
@@ -7,13 +7,13 @@ import {
|
|
|
7
7
|
import { NModule } from './types';
|
|
8
8
|
import { MutableProps, NMutableProps } from '../MutableProps';
|
|
9
9
|
import { Callbacks, NCallbacks } from '../Callbacks';
|
|
10
|
-
import { Viewport } from '@/src/Application/events/Viewport';
|
|
11
10
|
import { TRequiredModuleProp } from '@/types/utility';
|
|
12
11
|
import { getApp } from '@/utils/internal/getApp';
|
|
12
|
+
import { createViewport } from '@/src/Application/events/createViewport';
|
|
13
13
|
|
|
14
14
|
export type { NModule };
|
|
15
15
|
|
|
16
|
-
type TViewportAdd =
|
|
16
|
+
type TViewportAdd = ReturnType<typeof createViewport>['callbacks']['add'];
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Module base
|
|
@@ -215,7 +215,7 @@ export class Module<
|
|
|
215
215
|
action: Parameters<TViewportAdd>[1],
|
|
216
216
|
data: Parameters<TViewportAdd>[2] = {},
|
|
217
217
|
) {
|
|
218
|
-
const callback = getApp().viewport.add(target, action, {
|
|
218
|
+
const callback = getApp().viewport.callbacks.add(target, action, {
|
|
219
219
|
...data,
|
|
220
220
|
name: this.constructor.name,
|
|
221
221
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NViewport } from '@/src/Application/events/
|
|
1
|
+
import { NViewport } from '@/src/Application/events/createViewport';
|
|
2
2
|
import { NCallbacks } from '@/base/Callbacks';
|
|
3
3
|
|
|
4
4
|
export type TOnResizeTarget = keyof NViewport.ICallbacksTypes;
|
|
@@ -119,8 +119,9 @@ export function onResize({
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
if (hasBothEvents || !resizeObserver) {
|
|
122
|
-
viewportCallback = window.vevetApp.viewport.add(
|
|
123
|
-
|
|
122
|
+
viewportCallback = window.vevetApp.viewport.callbacks.add(
|
|
123
|
+
viewportTarget,
|
|
124
|
+
() => debounceResize({ trigger: 'Viewport' }),
|
|
124
125
|
);
|
|
125
126
|
}
|
|
126
127
|
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const version = '3.
|
|
1
|
+
const version = '3.18.0';
|
|
2
2
|
export default version;
|