Browse Source

Improved swiping and keyboard and screen reader support in the IoT Hub screenshot and attribute widget carousels (#16834)

* Improved swiping and keyboard and screen reader support in the IoT Hub screenshot and attribute widget carousels

ngx-hm-carousel is unmaintained, needed a patch to run on Angular 20 and pulled in
hammerjs (globally imported only for it) and @nghedgehog/core. It is replaced with an
in-house carousel that keeps the library's selectors, inputs, content templates and
currentIndex and is exposed under the same 'ngx-hm-carousel' module id, so custom
widgets keep working.

Swipe and mouse drag use Pointer Events; the carousel is focusable and switches slides
with the arrow keys, slides are labelled and off-screen slides are inert. The prev/next
buttons of the attribute widget preview got accessible names.

* Fixed IoT Hub screenshot carousel autoplay staying paused and showing a focus ring after closing the full-screen viewer

- A mouse click no longer focuses the carousel (it stays focusable from the keyboard), so the
  full-screen viewer does not return focus to it with a focus ring.
- Autoplay pauses on focus only when it is keyboard focus (:focus-visible); moving the
  mouse out of the carousel resumes it.
- Prev/next areas and dots react only to the carousel's own elements, not to elements
  with the same classes inside slides.
- Slide role, aria-roledescription and aria-label set by the slide author are kept.
- Pinch-zoom stays available on touch screens over the carousel.
- The slides container is looked up by [ngx-hm-carousel-container].
- Removed inputs and templates the new carousel ignores ([data], default [infinite] and
  [show-num], #carousel, empty prev/next/dot templates) and the styles that hid them.

* Removed leftover IoT Hub carousel styles of the replaced library and tidied carousel comments

* Updated the license header of the modified IoT Hub item dialog template
pull/16847/head
Vladyslav Prykhodko 1 week ago
committed by GitHub
parent
commit
bbc4b32a71
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      ui-ngx/package.json
  2. 31
      ui-ngx/patches/ngx-hm-carousel+19.0.0.patch
  3. 2
      ui-ngx/src/app/app.component.ts
  4. 2
      ui-ngx/src/app/modules/common/modules-map.ts
  5. 5
      ui-ngx/src/app/modules/home/components/attribute/attribute-table.component.html
  6. 8
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-detail-dialog.component.html
  7. 17
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-detail-dialog.component.scss
  8. 30
      ui-ngx/src/app/shared/components/carousel/carousel.component.html
  9. 51
      ui-ngx/src/app/shared/components/carousel/carousel.component.scss
  10. 471
      ui-ngx/src/app/shared/components/carousel/carousel.component.ts
  11. 6
      ui-ngx/src/app/shared/shared.module.ts
  12. 27
      ui-ngx/yarn.lock

1
ui-ngx/package.json

@ -89,7 +89,6 @@
"ngx-daterangepicker-material": "^6.0.4",
"ngx-drag-drop": "^20.0.1",
"ngx-flowchart": "https://github.com/thingsboard/ngx-flowchart.git#release/4.1.0",
"ngx-hm-carousel": "^19.0.0",
"ngx-markdown": "^20.1.0",
"ngx-sharebuttons": "^17.0.0",
"ngx-translate-messageformat-compiler": "^7.3.0",

31
ui-ngx/patches/ngx-hm-carousel+19.0.0.patch

@ -1,31 +0,0 @@
diff --git a/node_modules/ngx-hm-carousel/fesm2022/ngx-hm-carousel.mjs b/node_modules/ngx-hm-carousel/fesm2022/ngx-hm-carousel.mjs
index 117f782..70e49a7 100644
--- a/node_modules/ngx-hm-carousel/fesm2022/ngx-hm-carousel.mjs
+++ b/node_modules/ngx-hm-carousel/fesm2022/ngx-hm-carousel.mjs
@@ -1,5 +1,5 @@
import * as i0 from '@angular/core';
-import { Directive, inject, ViewContainerRef, TemplateRef, input, PLATFORM_ID, DestroyRef, Renderer2, NgZone, ChangeDetectorRef, viewChild, ElementRef, contentChildren, contentChild, computed, signal, effect, forwardRef, Component, ChangeDetectionStrategy } from '@angular/core';
+import { Directive, inject, ViewContainerRef, TemplateRef, input, PLATFORM_ID, DestroyRef, Renderer2, NgZone, ChangeDetectorRef, viewChild, ElementRef, contentChildren, contentChild, computed, signal, effect, forwardRef, Component, ChangeDetectionStrategy, afterNextRender } from '@angular/core';
import { DOCUMENT, isPlatformBrowser, NgTemplateOutlet, AsyncPipe } from '@angular/common';
import { toObservable, takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
@@ -340,7 +340,7 @@ class NgxHmCarouselComponent {
});
});
});
- const effectRef = effect(() => {
+ afterNextRender(() => {
this.rootElm = this.container().nativeElement;
this.containerElm = this.rootElm.children[0];
this.init();
@@ -365,10 +365,6 @@ class NgxHmCarouselComponent {
])
.pipe(takeUntilDestroyed(this._destroyRef))
.subscribe();
- // only exec once
- effectRef.destroy();
- }, {
- allowSignalWrites: true,
});
}
ngOnDestroy() {

2
ui-ngx/src/app/app.component.ts

@ -1,8 +1,6 @@
// SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
import 'hammerjs';
import { Component } from '@angular/core';
import { environment as env } from '@env/environment';

2
ui-ngx/src/app/modules/common/modules-map.ts

@ -71,7 +71,7 @@ import * as momentPlugin from '@fullcalendar/moment';
import * as interactionPlugin from '@fullcalendar/interaction';
import * as FullCalendar from '@fullcalendar/angular';
import * as CanvasGauges from 'canvas-gauges';
import * as NgxHmCarousel from 'ngx-hm-carousel';
import * as NgxHmCarousel from '@shared/components/carousel/carousel.component';
import * as TbCore from '@core/public-api';
import * as TbShared from '@shared/public-api';

5
ui-ngx/src/app/modules/home/components/attribute/attribute-table.component.html

@ -239,11 +239,8 @@
showFirstLastButtons></mat-paginator>
@if (mode === 'widget' && widgetsList.length > 0) {
<ngx-hm-carousel
#carousel
[(ngModel)]="widgetsCarouselIndex"
(ngModelChange)="onWidgetsCarouselIndexChanged()"
[data]="widgetsList"
[infinite]="false"
class="carousel c-accent flex-1">
<section ngx-hm-carousel-container class="content">
@for (widgets of widgetsList; track widgets) {
@ -267,6 +264,7 @@
<ng-template #carouselPrev>
@if (widgetsCarouselIndex > 0) {
<button mat-icon-button
[attr.aria-label]="'attribute.prev-widget' | translate"
matTooltip="{{ 'attribute.prev-widget' | translate }}"
matTooltipPosition="above">
<mat-icon>keyboard_arrow_left</mat-icon>
@ -276,6 +274,7 @@
<ng-template #carouselNext>
@if (widgetsCarouselIndex < widgetsList.length - 1) {
<button mat-icon-button
[attr.aria-label]="'attribute.next-widget' | translate"
matTooltip="{{ 'attribute.next-widget' | translate }}"
matTooltipPosition="above">
<mat-icon>keyboard_arrow_right</mat-icon>

8
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-detail-dialog.component.html

@ -1,7 +1,8 @@
<!--
SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
SPDX-License-Identifier: Apache-2.0
SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc.
SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
-->
<div class="tb-iot-hub-detail-dialog">
@ -98,13 +99,11 @@
<div class="dlg-hero-carousel">
<ngx-hm-carousel
[(ngModel)]="carouselIndex"
[data]="carouselImages"
[infinite]="true"
[autoplay-speed]="3000"
[between-delay]="0"
[autoplay]="!lightboxOpen"
[mouse-enable]="true"
[show-num]="1"
class="dlg-carousel">
<section ngx-hm-carousel-container class="dlg-carousel-container">
@for (imageUrl of carouselImages; track imageUrl) {
@ -113,9 +112,6 @@
</article>
}
</section>
<ng-template #carouselPrev><span class="dlg-carousel-hidden-nav"></span></ng-template>
<ng-template #carouselNext><span class="dlg-carousel-hidden-nav"></span></ng-template>
<ng-template #carouselDot><span></span></ng-template>
</ngx-hm-carousel>
<div class="dlg-carousel-controls">
<button mat-icon-button class="dlg-carousel-nav" (click)="goToPrevSlide()">

17
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-detail-dialog.component.scss

@ -467,19 +467,6 @@
}
.dlg-carousel {
height: 100%;
::ng-deep .carousel {
display: flex !important;
flex-direction: column !important;
flex: 1;
> section { flex: 1; min-height: 0; }
ul.indicators { display: none !important; }
.direction { display: none !important; }
}
.dlg-carousel-container {
display: flex;
height: 100%;
@ -499,10 +486,6 @@
}
}
.dlg-carousel-hidden-nav {
display: none;
}
.dlg-carousel-controls {
display: flex;
align-items: center;

30
ui-ngx/src/app/shared/components/carousel/carousel.component.html

@ -0,0 +1,30 @@
<!--
SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
SPDX-License-Identifier: BUSL-1.1
-->
<div #root class="carousel"
[class.grab]="dragEnabled()"
[class.grabbing]="grabbing()">
<ng-content select="[ngx-hm-carousel-container]"/>
@if (contentPrev(); as prevTemplate) {
<div class="direction left">
<ng-container *ngTemplateOutlet="prevTemplate"/>
</div>
}
@if (contentNext(); as nextTemplate) {
<div class="direction right">
<ng-container *ngTemplateOutlet="nextTemplate"/>
</div>
}
@if (contentDot(); as dotTemplate) {
<ul class="indicators">
@for (item of itemElms(); track item; let i = $index) {
<li [attr.data-index]="i">
<ng-container *ngTemplateOutlet="dotTemplate; context: {$implicit: {index: i, currentIndex: index()}}"/>
</li>
}
</ul>
}
</div>

51
ui-ngx/src/app/shared/components/carousel/carousel.component.scss

@ -0,0 +1,51 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
:host {
display: block;
height: 100%;
}
.carousel {
position: relative;
overflow: hidden;
width: 100%;
height: 100%;
touch-action: pan-y pinch-zoom;
}
.grab {
cursor: grab;
}
.grabbing {
cursor: grabbing;
user-select: none;
}
.direction {
position: absolute;
top: 0;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
&.left {
left: 0;
}
&.right {
right: 0;
}
}
ul.indicators {
position: absolute;
bottom: 1rem;
left: 0;
width: 100%;
margin: 0;
padding: 0;
list-style: none;
text-align: center;
li {
position: relative;
display: inline-block;
padding: .5rem;
cursor: pointer;
}
}

471
ui-ngx/src/app/shared/components/carousel/carousel.component.ts

@ -0,0 +1,471 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
import {
afterNextRender,
afterRenderEffect,
ChangeDetectionStrategy,
Component,
computed,
contentChild,
contentChildren,
DestroyRef,
Directive,
effect,
ElementRef,
forwardRef,
inject,
input,
NgZone,
signal,
TemplateRef,
untracked,
viewChild,
ViewContainerRef
} from '@angular/core';
import { NgTemplateOutlet } from '@angular/common';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
/*
* Replacement of the `ngx-hm-carousel` library (https://github.com/ZouYouShun/ngx-hm-carousel).
* Custom widgets still use it under that module id (modules-map.ts),
* so names, selectors, inputs, templates and `currentIndex` repeat the library's API and the classes stay standalone.
*/
/* eslint-disable @angular-eslint/no-input-rename */
export type NgxHmCarouselAlign = 'left' | 'center' | 'right';
export type NgxHmCarouselDirection = 'left' | 'right';
export interface NgxHmCarouselDotContext {
$implicit: {
index: number;
currentIndex: number;
};
}
/** Movement after which a press becomes a drag, so a click on a slide stays a click. */
const DRAG_START_THRESHOLD = 5;
const EDGE_RESISTANCE = 0.2;
/** The release speed is measured over the last part of the gesture only. */
const VELOCITY_WINDOW_MS = 100;
const MIN_SWIPE_DISTANCE = 10;
const DEFAULT_AUTOPLAY_SPEED = 5000;
const FOCUSABLE = 'a[href], button, input, select, textarea, [tabindex], [contenteditable]';
interface DragSample {
x: number;
t: number;
}
@Directive({
selector: '[ngx-hm-carousel-item]'
})
export class NgxHmCarouselItemDirective {
}
/** @deprecated Renders its content right away. */
@Directive({
selector: '[ngxHmCarouselDynamic]'
})
export class NgxHmCarouselDynamicDirective {
index = input<number>(undefined, { alias: 'ngxHmCarouselDynamic' });
length = input(0, { alias: 'ngxHmCarouselDynamicLength' });
show = input(1, { alias: 'ngxHmCarouselDynamicShow' });
currentI = input(0, { alias: 'ngxHmCarouselDynamicIndex' });
constructor() {
inject(ViewContainerRef).createEmbeddedView(inject(TemplateRef));
}
}
@Component({
selector: 'ngx-hm-carousel',
imports: [NgTemplateOutlet],
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => NgxHmCarouselComponent),
multi: true
}
],
host: {
'role': 'region',
'aria-roledescription': 'carousel',
'[attr.tabindex]': 'count() > 1 ? 0 : null',
'(keydown.arrowleft)': 'onArrowKey($event, -1)',
'(keydown.arrowright)': 'onArrowKey($event, 1)',
'(click)': 'onClick($event)',
'(mouseenter)': 'onHover(true)',
'(mouseleave)': 'onHover(false)',
'(focusin)': 'onFocusIn($event)',
'(focusout)': 'onFocusOut()'
},
templateUrl: './carousel.component.html',
styleUrl: './carousel.component.scss'
})
export class NgxHmCarouselComponent implements ControlValueAccessor {
private zone = inject(NgZone);
private host: HTMLElement = inject(ElementRef).nativeElement;
/** @deprecated No effect. */
data = input<unknown[]>([]);
/** @deprecated No effect. */
aniTime = input(400);
/** Added to the slides container when it moves to another slide; the consumer styles the transition. */
aniClass = input('transition');
/** Replaces `aniClass` when autoplay moves the slides. */
aniClassAuto = input<string>(undefined);
/** Share of the slide width a drag must cover to change the slide; `false` leaves it to the swipe speed. */
panBoundary = input<number | false>(0.15, { alias: 'pan-boundary' });
align = input<NgxHmCarouselAlign>('center');
notDrag = input(false, { alias: 'not-follow-pan' });
/** Autoplay pauses while the mouse is over the carousel. */
mouseEnable = input(false, { alias: 'mouse-enable' });
/** Added to `autoplay-speed` between autoplay steps, in ms. */
delay = input(8000, { alias: 'between-delay' });
direction = input<NgxHmCarouselDirection>('right', { alias: 'autoplay-direction' });
scrollNum = input(1, { alias: 'scroll-num' });
isDragMany = input(false, { alias: 'drag-many' });
/** In px/ms. */
swipeVelocity = input(0.3, { alias: 'swipe-velocity' });
/** @deprecated No effect; `show-num="auto"` shows one slide. */
breakpoint = input<unknown[]>([]);
disableDrag = input(false, { alias: 'disable-drag' });
infinite = input(false);
speed = input<number>(undefined, { alias: 'autoplay-speed' });
/** @deprecated No effect. */
recognizers = input<unknown[]>([]);
stopPanListener = input(false);
showNum = input<number | 'auto'>(1, { alias: 'show-num' });
autoplay = input(false);
protected root = viewChild.required<ElementRef<HTMLElement>>('root');
protected itemElms = contentChildren(NgxHmCarouselItemDirective, { read: ElementRef, descendants: true });
protected contentPrev = contentChild('carouselPrev', { read: TemplateRef });
protected contentNext = contentChild('carouselNext', { read: TemplateRef });
protected contentDot = contentChild<TemplateRef<NgxHmCarouselDotContext>>('carouselDot');
protected index = signal(0);
protected grabbing = signal(false);
protected count = computed(() => this.itemElms().length);
protected dragEnabled = computed(() => !this.disableDrag() && !this.stopPanListener() && this.count() > 1);
private shown = computed(() => {
const showNum = this.showNum();
return typeof showNum === 'number' && showNum >= 1 ? showNum : 1;
});
/** Slides between the left edge of the viewport and the selected slide. */
private alignShift = computed(() => {
const free = this.shown() - 1;
return this.align() === 'left' ? 0 : this.align() === 'right' ? free : free / 2;
});
private loop = computed(() => this.autoplay() || this.infinite());
private maxIndex = computed(() =>
Math.max(0, this.align() === 'left' ? this.count() - this.shown() : this.count() - 1));
private rendered = false;
private animation: string = null;
private labelledItems = new WeakSet<HTMLElement>();
private hovered = false;
private focused = false;
private autoplayTimer: ReturnType<typeof setTimeout>;
private pointerId: number = null;
private dragging = false;
private startX = 0;
private startY = 0;
private samples: DragSample[] = [];
private suppressClick = false;
private onChange: (index: number) => void = () => {};
private onTouched: () => void = () => {};
constructor() {
effect(() => {
const count = this.count();
if (count && this.index() > count - 1) {
untracked(() => this.select(count - 1));
}
});
effect(() => {
this.autoplay();
this.speed();
this.delay();
this.count();
untracked(() => this.restartAutoplay());
});
afterRenderEffect({
write: () => this.layout()
});
afterNextRender(() => this.listenPointer());
inject(DestroyRef).onDestroy(() => this.stopAutoplay());
}
get currentIndex(): number {
return this.index();
}
set currentIndex(index: number) {
this.goTo(index);
}
writeValue(value: number): void {
if (value || value === 0) {
this.animation = this.rendered ? this.aniClass() : null;
this.index.set(value);
this.restartAutoplay();
}
}
registerOnChange(fn: (index: number) => void): void {
this.onChange = fn;
}
registerOnTouched(fn: () => void): void {
this.onTouched = fn;
}
goTo(index: number, fromAutoplay = false): void {
const count = this.count();
if (!count) {
return;
}
const target = this.loop()
? ((index % count) + count) % count
: Math.min(Math.max(index, 0), this.maxIndex());
this.animation = fromAutoplay ? (this.aniClassAuto() ?? this.aniClass()) : this.aniClass();
if (target !== this.index()) {
this.select(target);
} else {
this.move();
}
this.restartAutoplay();
}
protected step(direction: number): void {
this.goTo(this.index() + direction * this.scrollNum());
this.onTouched();
}
/** Handles the prev/next areas and the dots; keyboard users switch slides with the arrow keys. */
protected onClick(event: Event): void {
const root = this.root().nativeElement;
const target = (event.target as Element).closest('.direction, .indicators > li');
if (target?.parentElement === root) {
this.step(target.classList.contains('left') ? -1 : 1);
} else if (target?.matches('li') && target.parentElement.parentElement === root) {
this.goTo(Number(target.getAttribute('data-index')));
}
}
protected onArrowKey(event: Event, direction: number): void {
if (event.target === event.currentTarget) {
event.preventDefault();
this.step(direction);
}
}
protected onHover(hovered: boolean): void {
this.hovered = hovered;
if (!hovered) {
// A dialog may return focus here; leaving with the mouse resumes autoplay
this.focused = false;
}
this.restartAutoplay();
}
/** Autoplay pauses while the keyboard focus is inside; a mouse click on a slide does not pause it. */
protected onFocusIn(event: FocusEvent): void {
this.focused = (event.target as Element).matches(':focus-visible');
this.restartAutoplay();
}
protected onFocusOut(): void {
this.focused = false;
this.restartAutoplay();
}
private select(index: number): void {
this.index.set(index);
this.onChange(index);
}
private get container(): HTMLElement {
return this.root().nativeElement.querySelector(':scope > [ngx-hm-carousel-container]');
}
private layout(): void {
const container = this.container;
const items = this.itemElms().map(item => item.nativeElement as HTMLElement);
if (!container || !items.length) {
return;
}
const count = items.length;
const firstVisible = this.index() - this.alignShift();
container.style.position = 'relative';
container.style.width = `${count * 100 / this.shown()}%`;
items.forEach((item, i) => {
item.style.width = `${100 / count}%`;
item.style.flexShrink = '0';
// Keeps what the slide author set; an element with a role of its own (article, li…) may not take another one
if (!item.hasAttribute('role') && (item.tagName === 'DIV' || item.tagName === 'SPAN')) {
item.setAttribute('role', 'group');
}
if (!item.hasAttribute('aria-roledescription')) {
item.setAttribute('aria-roledescription', 'slide');
}
if (!item.hasAttribute('aria-label') || this.labelledItems.has(item)) {
item.setAttribute('aria-label', `${i + 1} / ${count}`);
this.labelledItems.add(item);
}
// Off-screen slides must not take the focus
item.inert = i <= firstVisible - 1 || i >= firstVisible + this.shown();
});
this.move();
this.rendered = true;
}
/** Moves the slides to the selected one, shifted by `dragOffset` px while dragging. */
private move(dragOffset = 0): void {
const container = this.container;
const count = this.count();
if (!container || !count) {
return;
}
container.classList.remove(...[this.aniClass(), this.aniClassAuto()].filter(Boolean));
if (this.animation && !dragOffset) {
container.classList.add(this.animation);
}
const position = -(this.index() - this.alignShift()) * 100 / count;
container.style.transform = dragOffset
? `translateX(calc(${position}% + ${dragOffset}px))`
: `translateX(${position}%)`;
}
private restartAutoplay(): void {
this.stopAutoplay();
if (!this.autoplay() || this.count() < 2 || this.dragging || this.focused || (this.hovered && this.mouseEnable())) {
return;
}
const interval = (this.speed() ?? DEFAULT_AUTOPLAY_SPEED) + this.delay();
const direction = this.direction() === 'left' ? -1 : 1;
this.zone.runOutsideAngular(() => {
this.autoplayTimer = setTimeout(() =>
this.zone.run(() => this.goTo(this.index() + direction * this.scrollNum(), true)), interval);
});
}
private stopAutoplay(): void {
clearTimeout(this.autoplayTimer);
}
private listenPointer(): void {
const root = this.root().nativeElement;
this.zone.runOutsideAngular(() => {
root.addEventListener('pointerdown', event => this.onPointerDown(event));
root.addEventListener('pointermove', event => this.onPointerMove(event));
root.addEventListener('pointerup', event => this.onPointerUp(event, true));
root.addEventListener('pointercancel', event => this.onPointerUp(event, false));
// Native image drag would take the gesture over
root.addEventListener('dragstart', event => event.preventDefault());
// Focusable for the keyboard only: focus from a click would return with a focus ring when a dialog opened from a slide closes
root.addEventListener('mousedown', event => {
if ((event.target as Element).closest(FOCUSABLE) === this.host) {
event.preventDefault();
}
});
// The click that ends a drag must not reach the slide
root.addEventListener('click', event => {
if (this.suppressClick) {
this.suppressClick = false;
event.preventDefault();
event.stopPropagation();
}
}, true);
});
}
private onPointerDown(event: PointerEvent): void {
if (!this.dragEnabled() || this.pointerId !== null || !this.container?.contains(event.target as Node) ||
(event.pointerType === 'mouse' && event.button !== 0)) {
return;
}
this.pointerId = event.pointerId;
this.startX = event.clientX;
this.startY = event.clientY;
this.samples = [{ x: event.clientX, t: event.timeStamp }];
}
private onPointerMove(event: PointerEvent): void {
if (event.pointerId !== this.pointerId) {
return;
}
let offset = event.clientX - this.startX;
if (!this.dragging) {
const offsetY = event.clientY - this.startY;
if (Math.abs(offset) < DRAG_START_THRESHOLD && Math.abs(offsetY) < DRAG_START_THRESHOLD) {
return;
}
if (Math.abs(offsetY) > Math.abs(offset)) {
this.pointerId = null;
return;
}
this.dragging = true;
this.root().nativeElement.setPointerCapture(event.pointerId);
this.stopAutoplay();
this.grabbing.set(true);
}
this.samples.push({ x: event.clientX, t: event.timeStamp });
while (this.samples.length > 2 && this.samples[1].t < event.timeStamp - VELOCITY_WINDOW_MS) {
this.samples.shift();
}
const index = this.index();
if (!this.loop() && ((offset > 0 && index <= 0) || (offset < 0 && index >= this.maxIndex()))) {
offset *= EDGE_RESISTANCE;
}
if (!this.notDrag()) {
this.move(offset);
}
}
private onPointerUp(event: PointerEvent, released: boolean): void {
if (event.pointerId !== this.pointerId) {
return;
}
this.pointerId = null;
if (!this.dragging) {
return;
}
this.dragging = false;
this.grabbing.set(false);
const offset = event.clientX - this.startX;
let steps = 0;
if (released) {
steps = this.swipeSteps(offset, { x: event.clientX, t: event.timeStamp });
this.suppressClick = true;
setTimeout(() => this.suppressClick = false);
}
this.zone.run(() => {
this.goTo(this.index() + steps);
this.onTouched();
});
}
/** Slides to move on release: by the covered distance, otherwise by the release speed. */
private swipeSteps(offset: number, release: DragSample): number {
const slideWidth = this.root().nativeElement.getBoundingClientRect().width / this.shown();
const panBoundary = this.panBoundary();
if (panBoundary !== false && Math.abs(offset) > slideWidth * panBoundary) {
const steps = this.isDragMany() ? Math.ceil(Math.abs(offset) / slideWidth) : this.scrollNum();
return offset > 0 ? -steps : steps;
}
const first = this.samples[0];
const duration = release.t - first.t;
const velocity = duration > 0 ? (release.x - first.x) / duration : 0;
if (Math.abs(velocity) > this.swipeVelocity() && Math.abs(offset) > MIN_SWIPE_DISTANCE) {
return velocity > 0 ? -this.scrollNum() : this.scrollNum();
}
return 0;
}
}

6
ui-ngx/src/app/shared/shared.module.ts

@ -50,7 +50,11 @@ import { RouterModule } from '@angular/router';
import { ShareButtonDirective } from 'ngx-sharebuttons';
import { HotkeyModule } from 'angular2-hotkeys';
import { ColorPickerModule } from '@iplab/ngx-color-picker';
import { NgxHmCarouselComponent, NgxHmCarouselDynamicDirective, NgxHmCarouselItemDirective } from 'ngx-hm-carousel';
import {
NgxHmCarouselComponent,
NgxHmCarouselDynamicDirective,
NgxHmCarouselItemDirective
} from '@shared/components/carousel/carousel.component';
import { EditorModule, HUGERTE_SCRIPT_SRC } from '@hugerte/hugerte-angular';
import { HUGERTE_ASSETS_PATH } from '@shared/models/hugerte/hugerte.models';
import { UserMenuComponent } from '@shared/components/user-menu.component';

27
ui-ngx/yarn.lock

@ -1514,13 +1514,6 @@
"@napi-rs/nice-win32-ia32-msvc" "1.1.1"
"@napi-rs/nice-win32-x64-msvc" "1.1.1"
"@nghedgehog/core@^0.0.4":
version "0.0.4"
resolved "https://registry.yarnpkg.com/@nghedgehog/core/-/core-0.0.4.tgz#4e3231847d0dac557a2e2dbdf1e3a52b106dd57c"
integrity sha512-5yl2ji0nBG/J8cI57ewxgE5Fl2pCXKL+QOCKUghvbfIgRZJ0sSA4TMQtt57x3/U6ymFoVHFw4vEPe3Vk2DABIg==
dependencies:
tslib "^2.3.0"
"@ngrx/effects@^20.1.0":
version "20.1.0"
resolved "https://registry.yarnpkg.com/@ngrx/effects/-/effects-20.1.0.tgz#e8947a0840dc76d289eafcaa929113ab303335ea"
@ -2432,11 +2425,6 @@
resolved "https://registry.yarnpkg.com/@types/geojson/-/geojson-7946.0.16.tgz#8ebe53d69efada7044454e3305c19017d97ced2a"
integrity sha512-6C8nqWur3j98U6+lXDfTUWIfgvZU+EumvpHKcYjujKH7woYyLj2sUmff0tRhrqM7BohUw7Pz3ZB1jj2gW9Fvmg==
"@types/hammerjs@^2.0.45":
version "2.0.45"
resolved "https://registry.yarnpkg.com/@types/hammerjs/-/hammerjs-2.0.45.tgz#ffa764bb68a66c08db6efb9c816eb7be850577b1"
integrity sha512-qkcUlZmX6c4J8q45taBKTL3p+LbITgyx7qhlPYOdOHZB7B31K0mXbP5YA7i7SgDeEGuI9MnumiKPEMrxg8j3KQ==
"@types/jquery@*":
version "3.5.33"
resolved "https://registry.yarnpkg.com/@types/jquery/-/jquery-3.5.33.tgz#f42f40bac3edd84abdc9f6297d28e570fe463b35"
@ -5110,11 +5098,6 @@ hachure-fill@^0.5.2:
resolved "https://registry.yarnpkg.com/hachure-fill/-/hachure-fill-0.5.2.tgz#d19bc4cc8750a5962b47fb1300557a85fcf934cc"
integrity sha512-3GKBOn+m2LX9iq+JC1064cSFprJY4jL1jCXTcpnfER5HYE2l/4EfWSGzkPa/ZDBmYI0ZOEj5VHV/eKnPGkHuOg==
hammerjs@^2.0.8:
version "2.0.8"
resolved "https://registry.yarnpkg.com/hammerjs/-/hammerjs-2.0.8.tgz#04ef77862cff2bb79d30f7692095930222bf60f1"
integrity sha512-tSQXBXS/MWQOn/RKckawJ61vvsDpCom87JgxiYdGwHdOa0ht0vzUWDlfioofFCRU0L+6NGDt6XzbgoJvZkMeRQ==
has-bigints@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/has-bigints/-/has-bigints-1.0.2.tgz#0871bd3e3d51626f6ca0966668ba35d5602d6eaa"
@ -6453,16 +6436,6 @@ ngx-drag-drop@^20.0.1:
dependencies:
tslib "^2.3.0"
ngx-hm-carousel@^19.0.0:
version "19.0.0"
resolved "https://registry.yarnpkg.com/ngx-hm-carousel/-/ngx-hm-carousel-19.0.0.tgz#5a4f2999ebb05b1222702246cf06c79ecb08b66a"
integrity sha512-LjigrlIHPmdkLJME81iGGLa5gs2+UEQ051h6XEG22wTZUz5blKG6I+8KU4cY1oCPps10VkzbrTq+jGgvhndPTA==
dependencies:
"@nghedgehog/core" "^0.0.4"
"@types/hammerjs" "^2.0.45"
hammerjs "^2.0.8"
tslib "^2.3.0"
ngx-markdown@^20.1.0:
version "20.1.0"
resolved "https://registry.yarnpkg.com/ngx-markdown/-/ngx-markdown-20.1.0.tgz#e48b043e7ea00c63db2c3f48c5f45dbc7198d500"

Loading…
Cancel
Save