@imposium-hub/components 1.31.1 → 1.32.1

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,14 +1,14 @@
1
1
  import * as React from 'react';
2
2
  import { useDrag } from 'react-dnd';
3
- import { ASSET_DND_TYPES } from '../../constants/dnd';
4
-
5
- const DRAGGER_NAME : string = 'Asset';
3
+ import mergeRefs from 'react-merge-refs';
6
4
 
7
5
  interface IDataTableDnDWrapper {
8
6
  children : any;
9
7
  dndType : string;
10
8
  dndName : string;
11
9
  row : any;
10
+ rowRef : any;
11
+ rowProps : any;
12
12
  }
13
13
 
14
14
  const DataTableDndWrapper : React.FC<IDataTableDnDWrapper> = (props : IDataTableDnDWrapper) => {
@@ -25,9 +25,9 @@ const DataTableDndWrapper : React.FC<IDataTableDnDWrapper> = (props : IDataTable
25
25
  });
26
26
 
27
27
  return (
28
- <div ref = {drag}>
28
+ <tr {...props.rowProps} ref={mergeRefs([drag, props.rowRef])}>
29
29
  {props.children}
30
- </div>
30
+ </tr>
31
31
  );
32
32
  };
33
33
 
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import Moveable from 'react-moveable';
3
+ import hotkeys from 'hotkeys-js';
3
4
  import TextLayer from './TextLayer';
4
5
 
5
6
  interface ICompositionRendererLayerProps {
@@ -11,7 +12,11 @@ interface ICompositionRendererLayerProps {
11
12
  onUpdate(l : any) : void;
12
13
  }
13
14
 
14
- class CompositionRendererLayer extends React.PureComponent<ICompositionRendererLayerProps, undefined> {
15
+ interface ICompositionRendererLayerState {
16
+ lockRatio : boolean;
17
+ }
18
+
19
+ class CompositionRendererLayer extends React.PureComponent<ICompositionRendererLayerProps, ICompositionRendererLayerState> {
15
20
 
16
21
  private evtHandlers;
17
22
  private moveable;
@@ -26,10 +31,43 @@ class CompositionRendererLayer extends React.PureComponent<ICompositionRendererL
26
31
  onDrag: (e) => this.handleDrag(e),
27
32
  onResize: (e) => this.handleResize(e),
28
33
  onRotate: (e) => this.handleRotate(e),
29
- onClick: (e) => this.layerClicked(e)
34
+ onClick: (e) => this.layerClicked(e),
35
+ onShift: (e) => this.onShift(e),
36
+ onLeft: (e) => this.move(e, -1, 0),
37
+ onRight: (e) => this.move(e, 1, 0),
38
+ onUp: (e) => this.move(e, 0, -1),
39
+ onDown: (e) => this.move(e, 0, 1),
30
40
  };
31
41
 
32
42
  this.moveable = React.createRef();
43
+
44
+ this.state = {
45
+ lockRatio: false
46
+ };
47
+ }
48
+
49
+ private move(e, x, y) {
50
+
51
+ if (this.props.selected) {
52
+ const shiftX = (e.shiftKey) ? x * 10 : x;
53
+ const shiftY = (e.shiftKey) ? y * 10 : y;
54
+
55
+ const newLayer = {...this.props.layer};
56
+ newLayer.x = newLayer.x + shiftX;
57
+ newLayer.y = newLayer.y + shiftY;
58
+
59
+ this.props.onUpdate(newLayer);
60
+ }
61
+ }
62
+
63
+ private onShift(e) {
64
+
65
+ if (e.key === 'Shift' && e.keyCode === 16 && this.props.selected) {
66
+ const lockRatio = (e.type === 'keydown') ? true : false;
67
+ this.setState({
68
+ lockRatio
69
+ });
70
+ }
33
71
  }
34
72
 
35
73
  public componentDidUpdate() {
@@ -40,6 +78,24 @@ class CompositionRendererLayer extends React.PureComponent<ICompositionRendererL
40
78
  }
41
79
  }
42
80
 
81
+ public componentDidMount() {
82
+
83
+ hotkeys('*', {keyup: true}, this.evtHandlers.onShift);
84
+ hotkeys('left, shift+left', this.evtHandlers.onLeft);
85
+ hotkeys('right, shift+right', this.evtHandlers.onRight);
86
+ hotkeys('up, shift+up', this.evtHandlers.onUp);
87
+ hotkeys('down, shift+down', this.evtHandlers.onDown);
88
+ }
89
+
90
+ public componentWillUnmount() {
91
+
92
+ hotkeys.unbind('*', this.evtHandlers.onShift);
93
+ hotkeys.unbind('left, shift+left', this.evtHandlers.onLeft);
94
+ hotkeys.unbind('right, shift+right', this.evtHandlers.onRight);
95
+ hotkeys.unbind('up, shift+up', this.evtHandlers.onUp);
96
+ hotkeys.unbind('down, shift+down', this.evtHandlers.onDown);
97
+ }
98
+
43
99
  private handleDrag(e) {
44
100
 
45
101
  const newLayer = {...this.props.layer};
@@ -51,9 +107,13 @@ class CompositionRendererLayer extends React.PureComponent<ICompositionRendererL
51
107
 
52
108
  private handleResize(e) {
53
109
 
110
+ const {drag: {beforeDelta}, width, height} = e;
111
+
54
112
  const newLayer = {...this.props.layer};
55
- newLayer.width = Math.round(e.width);
56
- newLayer.height = Math.round(e.height);
113
+ newLayer.width = Math.round(width);
114
+ newLayer.height = Math.round(height);
115
+ newLayer.x = Math.round(newLayer.x + beforeDelta[0]);
116
+ newLayer.y = Math.round(newLayer.y + beforeDelta[1]);
57
117
 
58
118
  this.props.onUpdate(newLayer);
59
119
  }
@@ -95,6 +155,7 @@ class CompositionRendererLayer extends React.PureComponent<ICompositionRendererL
95
155
  public render() {
96
156
 
97
157
  const { selected, layer } = this.props;
158
+ const { lockRatio } = this.state;
98
159
 
99
160
  const layerClass = `comp-layer-${layer.id}`;
100
161
  const layerStyle : any = {
@@ -114,6 +175,7 @@ class CompositionRendererLayer extends React.PureComponent<ICompositionRendererL
114
175
  onResizeEnd = {this.evtHandlers.onResizeEnd}
115
176
  onRotate = {this.evtHandlers.onRotate}
116
177
  onRotateEnd = {this.evtHandlers.onRotateEnd}
178
+ keepRatio = {lockRatio}
117
179
  resizable = {true}
118
180
  rotatable = {true}
119
181
  origin = {false}
@@ -348,42 +348,48 @@ const DataTable : React.FC<IDataTableProps> = (props : IDataTableProps) => {
348
348
 
349
349
  prepareRow(row);
350
350
 
351
- const rowContent = <>
352
- <tr
353
- {...row.getRowProps()}
354
- ref = {activeRef}
355
- className = {`ip-table-row ${selectedClass}`}
356
- onClick = {(e) => {
357
- const onClick = () => {
358
- if (typeof props.onRowClick === 'function') {
359
- props.onRowClick(row);
360
- }
361
- };
362
-
363
- if (!doubleClickEnabled) {
364
- onClick();
365
- }
366
-
367
- if (e.detail === 1 && doubleClickEnabled) {
368
- doubleClickTimeout = window.setTimeout(onClick, 200);
369
- }
370
- }}
371
- onDoubleClick = {(e) => {
372
- clearTimeout(doubleClickTimeout);
373
- if (doubleClickEnabled) {
374
- props.onRowDoubleClick(row);
375
- }
376
- }}
351
+ const rowProps = row.getRowProps();
352
+ rowProps.className = `ip-table-row ${selectedClass}`;
353
+ rowProps.onClick = (e) => {
354
+ const onClick = () => {
355
+ if (typeof props.onRowClick === 'function') {
356
+ props.onRowClick(row);
357
+ }
358
+ };
359
+
360
+ if (!doubleClickEnabled) {
361
+ onClick();
362
+ }
363
+
364
+ if (e.detail === 1 && doubleClickEnabled) {
365
+ doubleClickTimeout = window.setTimeout(onClick, 200);
366
+ }
367
+ };
368
+ rowProps.onDoubleClick = (e) => {
369
+ clearTimeout(doubleClickTimeout);
370
+ if (doubleClickEnabled) {
371
+ props.onRowDoubleClick(row);
372
+ }
373
+ };
374
+
375
+ const rowContent = row.cells.map((cell) => (
376
+ <td
377
+ {...cell.getCellProps()}
378
+ className = {`ip-table-col ${(cell.column.overflowVisible) ? 'overflow-visible' : ''}`.trim()}
377
379
  >
378
- {row.cells.map((cell) => (
379
- <td
380
- {...cell.getCellProps()}
381
- className = {`ip-table-col ${(cell.column.overflowVisible) ? 'overflow-visible' : ''}`.trim()}
382
- >
383
- {cell.render('Cell')}
384
- </td>
385
- ))}
386
- </tr>
380
+ {cell.render('Cell')}
381
+ </td>
382
+ ));
383
+
384
+ return <React.Fragment key = {`row-${i}`}>
385
+
386
+ {(props.dnd) && <DataTableDnDWrapper rowProps = {rowProps} rowRef = {activeRef} key = {`row-${i}`} row = {row} dndType = {props.dndType} dndName = {props.dndName}>
387
+ {rowContent}
388
+ </DataTableDnDWrapper>}
389
+
390
+ {(!props.dnd) && <tr key = {`row-${i}`} ref = {activeRef} {...rowProps}>
391
+ {rowContent}
392
+ </tr>}
387
393
 
388
394
  {(row.isExpanded) &&
389
395
  (
@@ -400,18 +406,7 @@ const DataTable : React.FC<IDataTableProps> = (props : IDataTableProps) => {
400
406
  </tr>
401
407
  )
402
408
  }
403
- </>;
404
-
405
- if (props.dnd) {
406
- return <DataTableDnDWrapper key = {`row-${i}`} row = {row} dndType = {props.dndType} dndName = {props.dndName}>
407
- {rowContent}
408
- </DataTableDnDWrapper>;
409
- } else {
410
-
411
- return <React.Fragment key = {`row-${i}`}>
412
- {rowContent}
413
- </React.Fragment>;
414
- }
409
+ </React.Fragment>;
415
410
  })}
416
411
  </tbody>
417
412
  </table>
@@ -0,0 +1,97 @@
1
+ import * as React from 'react';
2
+ import AnsiUp from 'ansi_up';
3
+ import { fitToContainer } from '../../Util';
4
+ import { previewer as copy} from '../../constants/copy';
5
+ import { IImposiumAPI } from '../../services/API';
6
+
7
+ interface ILogViewerProps {
8
+ jobId : string;
9
+ onError?(e : string) : void;
10
+ api : IImposiumAPI;
11
+ }
12
+
13
+ interface ILogViewerState {
14
+ loading : boolean;
15
+ log : string;
16
+ }
17
+
18
+ class LogViewer extends React.PureComponent<ILogViewerProps, ILogViewerState> {
19
+
20
+ private videoNode : any;
21
+ private ansi_up : any;
22
+
23
+ constructor(props) {
24
+
25
+ super(props);
26
+
27
+ this.state = {
28
+ loading : true,
29
+ log: ''
30
+ };
31
+
32
+ this.ansi_up = new AnsiUp();
33
+ this.ansi_up.use_classes = true;
34
+ }
35
+
36
+ private getJobLogs() {
37
+
38
+ const { api, onError, jobId } = this.props;
39
+
40
+ api.getJobLogUrl(this.props.jobId).then((resLogUrl) => {
41
+
42
+ const jobUrl = resLogUrl.signed_url;
43
+
44
+ api.getJobLog(jobUrl).then((log) => {
45
+
46
+ this.setState({
47
+ loading: false,
48
+ log
49
+ });
50
+
51
+ }).catch((e) => {
52
+ if (onError) {
53
+ onError(copy.logDownloadError.replace('[jobId]', jobId));
54
+ }
55
+ this.setState({
56
+ loading: false,
57
+ log: ''
58
+ });
59
+ });
60
+
61
+ }).catch((e) => {
62
+ if (onError) {
63
+ onError(copy.logURLError.replace('[jobId]', this.props.jobId));
64
+ }
65
+ this.setState({
66
+ loading: false,
67
+ log: ''
68
+ });
69
+ });
70
+ }
71
+
72
+ public componentDidMount() {
73
+
74
+ if (this.props.jobId) {
75
+ this.getJobLogs();
76
+ }
77
+ }
78
+
79
+ public componentDidUpdate(prevProps) {
80
+
81
+ if (prevProps.jobId !== this.props.jobId && this.props.jobId) {
82
+ this.getJobLogs();
83
+ }
84
+ }
85
+ public render() {
86
+
87
+ const logHTML = this.ansi_up.ansi_to_html(this.state.log);
88
+
89
+ return (
90
+ <div className = 'log-viewer'>
91
+ <div className = 'log-html' dangerouslySetInnerHTML={{__html: logHTML}}></div>
92
+ </div>
93
+ );
94
+ }
95
+ }
96
+
97
+ export default LogViewer;