@playkit-js/transcript 3.0.1 → 3.1.0-canary.0-0df319e

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.
@@ -1,164 +0,0 @@
1
- import {h, Component, ComponentChild, VNode} from 'preact';
2
- import {Popover, PopoverHorizontalPositions, PopoverVerticalPositions} from '../../utils';
3
- import {PopoverMenu, PopoverMenuItem} from '../popover-menu';
4
- import * as styles from './download-print-menu.scss';
5
- import {DownloadIcon, PrintIcon} from './download-print-icons';
6
-
7
- const {ENTER, Esc} = KalturaPlayer.ui.utils.KeyMap;
8
-
9
- export function downloadContent(content: string, name: string): void {
10
- const blob = new Blob([content], {type: 'text/plain;charset=utf-8;'});
11
- const anchor = document.createElement('a');
12
- const {navigator} = window as any;
13
-
14
- if (navigator.msSaveBlob) {
15
- // IE
16
- navigator.msSaveOrOpenBlob(blob, name);
17
- return;
18
- }
19
- if (navigator.userAgent.search('Firefox') !== -1) {
20
- // Firefox
21
- anchor.style.display = 'none';
22
- anchor.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(content));
23
- } else {
24
- // Chrome
25
- anchor.setAttribute('href', URL.createObjectURL(blob));
26
- }
27
- anchor.setAttribute('target', '_blank');
28
- anchor.setAttribute('download', name);
29
- anchor.click();
30
- anchor.remove();
31
- }
32
-
33
- export function printContent(content: string): void {
34
- const printWindow = window.open('', '', 'width=400,height=600');
35
- if (printWindow) {
36
- printWindow.document.write(content);
37
- printWindow.document.close();
38
- printWindow.focus();
39
- printWindow.print();
40
- printWindow.close();
41
- }
42
- }
43
-
44
- interface DownloadPrintMenuProps {
45
- dropdownAriaLabel: string;
46
- printButtonAriaLabel: string;
47
- downloadButtonAriaLabel: string;
48
- onDownload: () => void;
49
- onPrint: () => void;
50
- downloadDisabled: boolean;
51
- printDisabled: boolean;
52
- }
53
-
54
- interface ButtonProperties {
55
- ['aria-label']: string;
56
- buttonStyles: string;
57
- onClick?: () => void;
58
- tabIndex?: number;
59
- iconStyles: string;
60
- icon: VNode;
61
- }
62
-
63
- interface DownloadPrintMenuState {
64
- popoverOpen: boolean;
65
- }
66
-
67
- export class DownloadPrintMenu extends Component<DownloadPrintMenuProps, DownloadPrintMenuState> {
68
- state: DownloadPrintMenuState = {
69
- popoverOpen: false
70
- };
71
-
72
- private _onDownloadClicked = () => {
73
- this.props.onDownload();
74
- };
75
-
76
- private _onPrintClicked = () => {
77
- this.props.onPrint();
78
- };
79
- private _onKeyDown = (e: KeyboardEvent, callBack: Function) => {
80
- if (e.keyCode !== ENTER && e.keyCode !== Esc) {
81
- // don't stopPropagation on ESC and Enter pressed as it prevent the popup closing
82
- e.stopPropagation();
83
- }
84
- switch (e.keyCode) {
85
- case 13: // Enter pressed
86
- callBack();
87
- break;
88
- }
89
- };
90
- private _popoverMenuItemRenderer = (el: PopoverMenuItem) => (
91
- <div
92
- tabIndex={1}
93
- role="button"
94
- onClick={() => el.onMenuChosen()}
95
- onKeyDown={(e: KeyboardEvent) => this._onKeyDown(e, el.onMenuChosen)}
96
- className={styles.popoverMenuItem}>
97
- {el.label}
98
- </div>
99
- );
100
-
101
- private _getPopoverMenuOptions = () => {
102
- return [
103
- {
104
- label: this.props.downloadButtonAriaLabel,
105
- onMenuChosen: this._onDownloadClicked
106
- },
107
- {
108
- label: this.props.printButtonAriaLabel,
109
- onMenuChosen: this._onPrintClicked
110
- }
111
- ];
112
- };
113
-
114
- private _renderIcon = ({buttonStyles, tabIndex = 0, iconStyles, icon, ...props}: ButtonProperties): ComponentChild => {
115
- return (
116
- <button className={buttonStyles} tabIndex={tabIndex} {...props}>
117
- <div className={iconStyles}>{icon}</div>
118
- </button>
119
- );
120
- };
121
-
122
- private _popoverContent = () => {
123
- return <PopoverMenu itemRenderer={this._popoverMenuItemRenderer} options={this._getPopoverMenuOptions()} />;
124
- };
125
-
126
- render(props: DownloadPrintMenuProps) {
127
- const {downloadDisabled, printDisabled} = props;
128
- if (!downloadDisabled && !printDisabled) {
129
- return (
130
- <Popover
131
- className="download-print-popover"
132
- verticalPosition={PopoverVerticalPositions.Bottom}
133
- horizontalPosition={PopoverHorizontalPositions.Left}
134
- content={this._popoverContent()}>
135
- {this._renderIcon({
136
- ['aria-label']: props.dropdownAriaLabel,
137
- buttonStyles: styles.downloadPrintButton,
138
- iconStyles: styles.icon,
139
- icon: <DownloadIcon />
140
- })}
141
- </Popover>
142
- );
143
- }
144
- if (!downloadDisabled && printDisabled) {
145
- return this._renderIcon({
146
- ['aria-label']: props.downloadButtonAriaLabel,
147
- buttonStyles: styles.downloadPrintButton,
148
- iconStyles: styles.icon,
149
- onClick: this._onDownloadClicked,
150
- icon: <DownloadIcon />
151
- });
152
- }
153
- if (downloadDisabled && !printDisabled) {
154
- return this._renderIcon({
155
- ['aria-label']: props.printButtonAriaLabel,
156
- buttonStyles: styles.downloadPrintButton,
157
- iconStyles: styles.icon,
158
- onClick: this._onPrintClicked,
159
- icon: <PrintIcon />
160
- });
161
- }
162
- return null;
163
- }
164
- }
@@ -1 +0,0 @@
1
- export * from './download-print-menu';
@@ -1 +0,0 @@
1
- export * from './popover-menu';
@@ -1,6 +0,0 @@
1
- @import '../../variables.scss';
2
-
3
- .popover-menu {
4
- padding-top: 6px;
5
- padding-bottom: 6px;
6
- }
@@ -1,52 +0,0 @@
1
- import {h, Component, ComponentChild} from 'preact';
2
- import * as styles from './popover-menu.scss';
3
-
4
- export interface PopoverMenuItem {
5
- label: string;
6
- onMenuChosen: Function;
7
- customRenderer?: (el: PopoverMenuItem) => ComponentChild;
8
- }
9
-
10
- interface PopoverMenuProps {
11
- options: Array<PopoverMenuItem>;
12
- itemRenderer?: (el: PopoverMenuItem) => ComponentChild;
13
- }
14
-
15
- /**
16
- * Popover menu renders list of options.
17
- * options example:
18
- * [
19
- * {label: 'option_1', onMenuChosen: () => console.log('selected first')},
20
- * {label: 'option_2', onMenuChosen: () => console.log('selected second')}
21
- * ]
22
- * In case when 'itemRenderer' properdy hasn't provided - PopoverMenu renders
23
- * div with class "popover-menu-item" that contain label for the current option.
24
- * Default render of options can be changed by providing 'itemRenderer' - it should be
25
- * function that takes current option and returns valid 'preact' node.
26
- * If some option need to be rendered with a different method - specific render
27
- * method can be provided with 'customRenderer' property for the current option.
28
- * option example with specific render method:
29
- * { label: 'specific render', onMenuChosen: () => {}, customRenderer: el => (<span>{el.label}</span>)}
30
- */
31
-
32
- export class PopoverMenu extends Component<PopoverMenuProps> {
33
- render(props: any) {
34
- return (
35
- <div className={styles.popoverMenu}>
36
- {props.options.map((el: PopoverMenuItem) => {
37
- if (el.customRenderer) {
38
- return el.customRenderer(el);
39
- }
40
- if (props.itemRenderer) {
41
- return props.itemRenderer(el);
42
- }
43
- return (
44
- <div className="popover-menu-item" onClick={() => el.onMenuChosen(el)}>
45
- {el.label}
46
- </div>
47
- );
48
- })}
49
- </div>
50
- );
51
- }
52
- }
@@ -1,30 +0,0 @@
1
- .popover-container {
2
- position: relative;
3
- .popover-component {
4
- background-color: #222222;
5
- border-radius: 4px;
6
- position: absolute;
7
- right: 0px;
8
- font-size: 15px;
9
- display: block;
10
- &.visible {
11
- visibility: visible;
12
- opacity: 1;
13
- z-index: 10;
14
- }
15
- &.top {
16
- bottom: 100%;
17
- margin-bottom: 6px;
18
- }
19
- &.bottom {
20
- top: 100%;
21
- margin-top: 6px;
22
- }
23
- &.right {
24
- left: 0px;
25
- }
26
- &.left {
27
- right: 0px;
28
- }
29
- }
30
- }
@@ -1,178 +0,0 @@
1
- import {h, Component, ComponentChild} from 'preact';
2
- import * as styles from './popover.scss';
3
-
4
- const {ENTER, Esc} = KalturaPlayer.ui.utils.KeyMap;
5
-
6
- export enum PopoverVerticalPositions {
7
- Top = 'top',
8
- Bottom = 'bottom'
9
- }
10
- export enum PopoverHorizontalPositions {
11
- Left = 'left',
12
- Right = 'right'
13
- }
14
- export enum PopoverTriggerMode {
15
- Click = 'click',
16
- Hover = 'hover'
17
- }
18
-
19
- const CLOSE_ON_HOVER_DELAY = 500;
20
-
21
- const defaultProps = {
22
- verticalPosition: PopoverVerticalPositions.Top,
23
- horizontalPosition: PopoverHorizontalPositions.Left,
24
- triggerMode: PopoverTriggerMode.Click,
25
- className: 'popover',
26
- closeOnEsc: true,
27
- closeOnClick: true
28
- };
29
-
30
- interface PopoverProps {
31
- onClose?: () => void;
32
- onOpen?: () => void;
33
- closeOnClick: boolean;
34
- closeOnEsc: boolean;
35
- verticalPosition: PopoverVerticalPositions;
36
- horizontalPosition: PopoverHorizontalPositions;
37
- className: string;
38
- triggerMode: PopoverTriggerMode;
39
- content: ComponentChild;
40
- children: ComponentChild;
41
- }
42
-
43
- interface PopoverState {
44
- open: boolean;
45
- }
46
-
47
- export class Popover extends Component<PopoverProps, PopoverState> {
48
- private _closeTimeout: any = null;
49
- private _controlElement: HTMLDivElement | null = null;
50
- static defaultProps = {
51
- ...defaultProps
52
- };
53
- state = {
54
- open: false
55
- };
56
-
57
- componentWillUnmount() {
58
- this._removeListeners();
59
- }
60
-
61
- private _clearTimeout = () => {
62
- clearTimeout(this._closeTimeout);
63
- this._closeTimeout = null;
64
- };
65
-
66
- private _handleMouseEvent = (event: MouseEvent) => {
67
- if (!this._controlElement?.contains(event.target as Node | null) && this.props.closeOnClick) {
68
- this._closePopover();
69
- }
70
- };
71
-
72
- private _handleKeyboardEvent = (event: KeyboardEvent) => {
73
- if (this._controlElement?.contains(event.target as Node | null) && event.keyCode === ENTER) {
74
- // handle Enter key pressed on Target icon to prevent triggering of _closePopover twice
75
- return;
76
- }
77
- if ((this.props.closeOnEsc && event.keyCode === Esc) || event.keyCode === ENTER) {
78
- // handle if ESC or Enter button presesd
79
- this._closePopover();
80
- }
81
- };
82
-
83
- private _openPopover = () => {
84
- const {onOpen} = this.props;
85
- this._clearTimeout();
86
- this.setState({open: true}, () => {
87
- this._addListeners();
88
- if (onOpen) {
89
- onOpen();
90
- }
91
- });
92
- };
93
-
94
- private _closePopover = () => {
95
- const {onClose} = this.props;
96
- this._clearTimeout();
97
- this.setState({open: false}, () => {
98
- this._removeListeners();
99
- if (onClose) {
100
- onClose();
101
- }
102
- });
103
- };
104
-
105
- private _togglePopover = (e: MouseEvent | KeyboardEvent) => {
106
- if (this.state.open) {
107
- this._closePopover();
108
- } else {
109
- this._openPopover();
110
- }
111
- };
112
- private _handleMouseEnter = () => {
113
- if (!this.state.open) {
114
- this._openPopover();
115
- }
116
- };
117
- private _handleMouseLeave = () => {
118
- this._closeTimeout = setTimeout(this._closePopover, CLOSE_ON_HOVER_DELAY);
119
- };
120
- private _handleHoverOnPopover = () => {
121
- if (this.state.open && this._closeTimeout) {
122
- this._clearTimeout();
123
- } else {
124
- this._closePopover();
125
- }
126
- };
127
- private _addListeners = () => {
128
- document.addEventListener('click', this._handleMouseEvent);
129
- document.addEventListener('keydown', this._handleKeyboardEvent);
130
- };
131
- private _removeListeners = () => {
132
- document.removeEventListener('click', this._handleMouseEvent);
133
- document.removeEventListener('keydown', this._handleKeyboardEvent);
134
- };
135
- private _getHoverEvents = () => {
136
- if (this.props.triggerMode === PopoverTriggerMode.Hover) {
137
- return {
138
- targetEvents: {
139
- onMouseEnter: this._handleMouseEnter,
140
- onMouseLeave: this._handleMouseLeave
141
- },
142
- popoverEvents: {
143
- onMouseEnter: this._handleHoverOnPopover,
144
- onMouseLeave: this._handleHoverOnPopover
145
- }
146
- };
147
- }
148
- return {targetEvents: {onClick: this._togglePopover}, popoverEvents: {}};
149
- };
150
- render(props: PopoverProps) {
151
- if (!props.content || !props.children) {
152
- return null;
153
- }
154
- const {targetEvents, popoverEvents} = this._getHoverEvents();
155
- return (
156
- <div className={styles.popoverContainer}>
157
- <div
158
- className="popover-anchor-container"
159
- ref={node => {
160
- this._controlElement = node;
161
- }}
162
- {...targetEvents}
163
- >
164
- {props.children}
165
- </div>
166
- {this.state.open && (
167
- <div
168
- aria-expanded="true"
169
- className={[props.className, styles.popoverComponent, styles[props.verticalPosition], styles[props.horizontalPosition]].join(' ')}
170
- {...popoverEvents}
171
- >
172
- {props.content}
173
- </div>
174
- )}
175
- </div>
176
- );
177
- }
178
- }