@playkit-js/transcript 3.7.4-canary.0-cef3398 → 3.7.4

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": "@playkit-js/transcript",
3
- "version": "3.7.4-canary.0-cef3398",
3
+ "version": "3.7.4",
4
4
  "main": "dist/playkit-transcript.js",
5
5
  "license": "AGPL-3.0",
6
6
  "private": false,
@@ -37,6 +37,8 @@ interface ExtendedCaptionProps extends CaptionProps {
37
37
  activeSearchIndex: number;
38
38
  longerThanHour: boolean;
39
39
  isAutoScrollEnabled: boolean;
40
+ onUpKeyPressed?: (e: KeyboardEvent) => void;
41
+ onDownKeyPressed?: (e: KeyboardEvent) => void;
40
42
  }
41
43
 
42
44
  const translates = {
@@ -174,7 +176,11 @@ export class Caption extends Component<ExtendedCaptionProps> {
174
176
  };
175
177
 
176
178
  return (
177
- <A11yWrapper onClick={this._handleClick}>
179
+ <A11yWrapper
180
+ onClick={this._handleClick}
181
+ onUpKeyPressed={(e: KeyboardEvent) => this.props.onUpKeyPressed?.(e)}
182
+ onDownKeyPressed={(e: KeyboardEvent) => this.props.onDownKeyPressed?.(e)}
183
+ >
178
184
  <div
179
185
  className={styles.caption}
180
186
  ref={node => {
@@ -33,6 +33,40 @@ export class CaptionList extends Component<Props> {
33
33
  private _currentCaptionRef: any = null;
34
34
  private _firstCaptionRef: any = null;
35
35
  private _lastCaptionRef: any = null;
36
+ private _captionRefs: Map<number, HTMLElement | null> = new Map();
37
+
38
+ private _setCaptionRef = (index: number, ref: HTMLElement | null) => {
39
+ this._captionRefs.set(index, ref);
40
+ };
41
+
42
+ private _getCaptionRef = (index: number) => {
43
+ return this._captionRefs.get(index);
44
+ };
45
+
46
+ private _focusPrevCaption = (currentIndex: number) => {
47
+ const { data } = this.props;
48
+ if (!data.length) return;
49
+
50
+ let prevIndex = currentIndex - 1;
51
+ if (prevIndex < 0) {
52
+ prevIndex = data.length - 1;
53
+ }
54
+
55
+ this._getCaptionRef(prevIndex)?.focus();
56
+ };
57
+
58
+ private _focusNextCaption = (currentIndex: number) => {
59
+ const { data } = this.props;
60
+ if (!data.length) return;
61
+
62
+ let nextIndex = currentIndex + 1;
63
+ if (nextIndex >= data.length) {
64
+ nextIndex = 0;
65
+ }
66
+
67
+ this._getCaptionRef(nextIndex)?.focus();
68
+ };
69
+
36
70
  shouldComponentUpdate(nextProps: Readonly<Props>) {
37
71
  const {highlightedMap, data, searchMap, activeSearchIndex, isAutoScrollEnabled, captionProps} = this.props;
38
72
  if (
@@ -122,6 +156,7 @@ export class CaptionList extends Component<Props> {
122
156
  <Caption
123
157
  setTextToRead={setTextToRead}
124
158
  ref={node => {
159
+ this._setCaptionRef(index, node?.base ?? null);
125
160
  if (index === 0) {
126
161
  this._firstCaptionRef = node;
127
162
  } else if (index === data.length - 1) {
@@ -131,6 +166,8 @@ export class CaptionList extends Component<Props> {
131
166
  this._currentCaptionRef = node;
132
167
  }
133
168
  }}
169
+ onUpKeyPressed={() => this._focusPrevCaption(index)}
170
+ onDownKeyPressed={() => this._focusNextCaption(index)}
134
171
  {...captionProps}
135
172
  />
136
173
  );