@24i/bigscreen-sdk 1.0.11-alpha.2229 → 1.0.12-alpha.2237

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@24i/bigscreen-sdk",
3
- "version": "1.0.11-alpha.2229",
3
+ "version": "1.0.12-alpha.2237",
4
4
  "description": "SmartApps BIGscreen SDK monorepo",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -260,6 +260,7 @@
260
260
  "./utils/debounce": "./packages/utils/src/debounce.ts",
261
261
  "./utils/displayToggler": "./packages/utils/src/displayToggler.ts",
262
262
  "./utils/elementUtils": "./packages/utils/src/elementUtils.ts",
263
+ "./utils/forceReflow": "./packages/utils/src/forceReflow.ts",
263
264
  "./utils/generateUuid": "./packages/utils/src/generateUuid.ts",
264
265
  "./utils/memoryInfo": "./packages/utils/src/memoryInfo.ts",
265
266
  "./utils/nTimes": "./packages/utils/src/nTimes.ts",
@@ -100,7 +100,7 @@ export class MenuAndContentContainer<T extends string = string>
100
100
  * Handles opening with mouse.
101
101
  * @param event mouse event
102
102
  */
103
- onMouseMove = (event: MouseEvent) => {
103
+ onMouseDown = (event: MouseEvent) => {
104
104
  const menu = this.menu.current!;
105
105
  if (this.isMenuAvailable() && !menu.isOpen()) {
106
106
  menu.open();
@@ -108,6 +108,30 @@ export class MenuAndContentContainer<T extends string = string>
108
108
  }
109
109
  };
110
110
 
111
+ /**
112
+ * Handles hover with mouse.
113
+ * @param event mouse event
114
+ */
115
+ onMouseEnter = (event: MouseEvent) => {
116
+ const menu = this.menu.current!;
117
+ if (this.isMenuAvailable() && !menu.isOpen() && menu.mrcuEnter) {
118
+ menu.mrcuEnter();
119
+ stopEvent(event);
120
+ }
121
+ };
122
+
123
+ /**
124
+ * Handles hover end with mouse.
125
+ * @param event mouse event
126
+ */
127
+ onMouseLeave = (event: MouseEvent) => {
128
+ const menu = this.menu.current!;
129
+ if (this.isMenuAvailable() && !menu.isOpen() && menu.mrcuLeave) {
130
+ menu.mrcuLeave();
131
+ stopEvent(event);
132
+ }
133
+ };
134
+
111
135
  /**
112
136
  * Handles adding/removing mouse listeners based on whether the mouse is used or not.
113
137
  * @param event mouse active event
@@ -137,7 +161,9 @@ export class MenuAndContentContainer<T extends string = string>
137
161
  if (!this.listensToMouse) {
138
162
  this.listensToMouse = true;
139
163
  if (!this.menu.current!.isOpen()) this.mouseTriggerElementDisplayToggler.show();
140
- this.mouseTriggerElement.current!.addEventListener('mousemove', this.onMouseMove);
164
+ this.mouseTriggerElement.current!.addEventListener('mousedown', this.onMouseDown);
165
+ this.mouseTriggerElement.current!.addEventListener('mouseenter', this.onMouseEnter);
166
+ this.mouseTriggerElement.current!.addEventListener('mouseleave', this.onMouseLeave);
141
167
  }
142
168
  }
143
169
 
@@ -148,7 +174,9 @@ export class MenuAndContentContainer<T extends string = string>
148
174
  if (this.listensToMouse) {
149
175
  this.listensToMouse = false;
150
176
  if (!this.menu.current!.isOpen()) this.mouseTriggerElementDisplayToggler.hide();
151
- this.mouseTriggerElement.current!.removeEventListener('mousemove', this.onMouseMove);
177
+ this.mouseTriggerElement.current!.removeEventListener('mousedown', this.onMouseDown);
178
+ this.mouseTriggerElement.current!.removeEventListener('mouseenter', this.onMouseEnter);
179
+ this.mouseTriggerElement.current!.removeEventListener('mouseleave', this.onMouseLeave);
152
180
  }
153
181
  }
154
182
 
@@ -112,6 +112,14 @@ export interface Menu<
112
112
  * Function to close the menu.
113
113
  */
114
114
  close(): void,
115
+ /**
116
+ * Function for "hover" effect on the menu.
117
+ */
118
+ mrcuEnter?(): void,
119
+ /**
120
+ * Function for ending "hover" effect on the menu.
121
+ */
122
+ mrcuLeave?(): void,
115
123
  /**
116
124
  * Renders new menu items.
117
125
  * @param items new items to render
@@ -2,8 +2,10 @@ import { NavigationConfig } from './types';
2
2
 
3
3
  export const history: string[] = [];
4
4
 
5
+ const pathWithHash = (path:string) => `#${path}`;
6
+
5
7
  const navigate = (path: string) => {
6
- window.location.href = `#${path}`;
8
+ window.location.href = pathWithHash(path);
7
9
  };
8
10
 
9
11
  export const go = (path: string, { skipHistory, replaceHistory }: NavigationConfig = {}) => {
@@ -22,3 +24,8 @@ export const back = () => {
22
24
  export const clearHistory = () => {
23
25
  history.length = 0;
24
26
  };
27
+
28
+ export const replaceState = (path: string) => {
29
+ history[history.length - 1] = path;
30
+ window.history.replaceState(null, '', pathWithHash(path));
31
+ };
@@ -1,6 +1,6 @@
1
1
  export { Router } from './Router';
2
2
  export { Route } from './Route';
3
3
  export type { IRoute } from './types';
4
- export { history, go, back, clearHistory } from './history';
4
+ export { history, go, back, clearHistory, replaceState } from './history';
5
5
  export { focusActiveRoute } from './focusActiveRoute';
6
6
  export { fromSafeUrl, toSafeUrl } from './utils';
@@ -21,6 +21,7 @@ import { generateUuid } from '@24i/bigscreen-sdk/utils/generateUuid';
21
21
  - **[addClass](#addClass)** - safely adds class to reference.
22
22
  - **[debounce](#debounce)** - debounced function is only executed again after a period of not being called, supports leading, trailing (default) and both executions.
23
23
  - **[displayToggler](#displayToggler)** - exports `getDisplayToggler` that allows you to easily show/hide an element with guard preventing unnecessary DOM calls.
24
+ - **[forceReflow](#forceReflow)** - To force a DOM reflow on given DOM element.
24
25
  - **[generateUuid](#generateUuid)** - function to get UUIDv4 according to RFC 4122.
25
26
  - **[isMouseUsed](#isMouseUsed)** - **DEPRECATED** moved to `device` package.
26
27
  - **[memoryInfo](#memoryInfo)** - two functions that returns currently active segment size and total allocated size of JS heap, in bytes.
@@ -92,6 +93,18 @@ And returns `IDisplayToggler` interface with 4 functions:
92
93
  - `isVisible: () => boolean;` - returns true if the element is visible, false otherwise
93
94
  - `isHidden: () => boolean;` - returns true if the element is hidden, false otherwise
94
95
 
96
+ ### forceReflow
97
+ To force a DOM reflow on given DOM element. It can be needed for transitions
98
+ or other purposes.
99
+
100
+ It takes 1 param:
101
+ - `elementOrReference: HTMLElement | Reference<HTMLElement>` - DOM element or
102
+ reference to element on which reflow is called.
103
+
104
+ ```ts
105
+ forceReflow(elementRef);
106
+ ```
107
+
95
108
  ### generateUuid
96
109
  Returns an UUIDv4 according to RFC 4122, like ex. "123e4567-e89b-12d3-a456-426614174000".
97
110
 
@@ -0,0 +1,14 @@
1
+ import { Reference, unwrapReference } from '@24i/bigscreen-sdk/jsx';
2
+
3
+ /**
4
+ * To force a DOM reflow on given DOM element. It can be needed for transitions
5
+ * or other purposes.
6
+ * @param elementOrReference DOM element or reference to element on which reflow is called.
7
+ */
8
+ export const forceReflow = (
9
+ elementOrReference: HTMLElement | Reference<HTMLElement>,
10
+ ) => {
11
+ const element = unwrapReference(elementOrReference);
12
+ if (!element) return;
13
+ void element.offsetHeight; // eslint-disable-line no-void
14
+ };
@@ -6,6 +6,7 @@ export { addClass } from './addClass';
6
6
  export { removeClass } from './removeClass';
7
7
  export { debounce } from './debounce';
8
8
  export { wait } from './wait';
9
+ export { forceReflow } from './forceReflow';
9
10
  export { scaledImage } from './scaledImage';
10
11
  export { nTimes } from './nTimes';
11
12
  export { getDisplayToggler, DISPLAY_NONE } from './displayToggler';