creevey 0.9.0-non-webpack.0 → 0.9.0-non-webpack.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.
- package/lib/cjs/client/addon/Manager.js +121 -275
- package/lib/cjs/client/addon/components/Addon.js +17 -38
- package/lib/cjs/client/addon/components/Icons.js +10 -6
- package/lib/cjs/client/addon/components/Panel.js +17 -13
- package/lib/cjs/client/addon/components/TestSelect.js +11 -9
- package/lib/cjs/client/addon/components/Tools.js +21 -40
- package/lib/cjs/client/addon/decorator.js +1 -1
- package/lib/cjs/client/addon/index.js +2 -2
- package/lib/cjs/client/addon/preset.js +11 -30
- package/lib/cjs/client/addon/register.js +45 -73
- package/lib/cjs/client/addon/utils.js +1 -1
- package/lib/cjs/client/addon/withCreevey.js +153 -360
- package/lib/cjs/client/shared/components/ImagesView/BlendView.js +23 -21
- package/lib/cjs/client/shared/components/ImagesView/ImagesView.js +21 -17
- package/lib/cjs/client/shared/components/ImagesView/SideBySideView.js +42 -64
- package/lib/cjs/client/shared/components/ImagesView/SlideView.js +35 -48
- package/lib/cjs/client/shared/components/ImagesView/SwapView.js +24 -43
- package/lib/cjs/client/shared/components/ImagesView/index.js +5 -5
- package/lib/cjs/client/shared/components/PageFooter/PageFooter.js +12 -8
- package/lib/cjs/client/shared/components/PageFooter/Paging.js +14 -18
- package/lib/cjs/client/shared/components/PageHeader/ImagePreview.js +22 -18
- package/lib/cjs/client/shared/components/PageHeader/PageHeader.js +42 -67
- package/lib/cjs/client/shared/components/ResultsPage.js +38 -68
- package/lib/cjs/client/shared/creeveyClientApi.js +55 -86
- package/lib/cjs/client/shared/helpers.js +123 -194
- package/lib/cjs/client/shared/viewMode.js +4 -4
- package/lib/cjs/shared/index.js +26 -14
- package/lib/cjs/shared/serializeRegExp.js +5 -4
- package/lib/esm/client/addon/Manager.js +121 -275
- package/lib/esm/client/addon/components/Addon.js +15 -34
- package/lib/esm/client/addon/components/Icons.js +10 -6
- package/lib/esm/client/addon/components/Panel.js +17 -13
- package/lib/esm/client/addon/components/TestSelect.js +11 -9
- package/lib/esm/client/addon/components/Tools.js +19 -36
- package/lib/esm/client/addon/decorator.js +1 -1
- package/lib/esm/client/addon/preset.js +9 -24
- package/lib/esm/client/addon/register.js +42 -70
- package/lib/esm/client/addon/utils.js +1 -1
- package/lib/esm/client/addon/withCreevey.js +148 -357
- package/lib/esm/client/shared/components/ImagesView/BlendView.js +21 -17
- package/lib/esm/client/shared/components/ImagesView/ImagesView.js +21 -17
- package/lib/esm/client/shared/components/ImagesView/SideBySideView.js +40 -60
- package/lib/esm/client/shared/components/ImagesView/SlideView.js +33 -44
- package/lib/esm/client/shared/components/ImagesView/SwapView.js +22 -39
- package/lib/esm/client/shared/components/PageFooter/PageFooter.js +12 -8
- package/lib/esm/client/shared/components/PageFooter/Paging.js +14 -18
- package/lib/esm/client/shared/components/PageHeader/ImagePreview.js +22 -18
- package/lib/esm/client/shared/components/PageHeader/PageHeader.js +37 -60
- package/lib/esm/client/shared/components/ResultsPage.js +36 -64
- package/lib/esm/client/shared/creeveyClientApi.js +57 -88
- package/lib/esm/client/shared/helpers.js +123 -194
- package/lib/esm/client/shared/viewMode.js +4 -4
- package/lib/esm/shared/index.js +26 -14
- package/lib/esm/shared/serializeRegExp.js +5 -4
- package/package.json +1 -1
- package/preset.js +1 -1
@@ -1,9 +1,11 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { styled, withTheme } from '@storybook/theming';
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
const IMG_SIZE = 64;
|
4
|
+
const DIAG_LENGTH = (2 * (IMG_SIZE - 8) ** 2) ** (1 / 2);
|
5
|
+
const Button = styled.button(_ref => {
|
6
|
+
let {
|
7
|
+
borderColor
|
8
|
+
} = _ref;
|
7
9
|
return {
|
8
10
|
appearance: 'none',
|
9
11
|
background: 'none',
|
@@ -20,10 +22,12 @@ var Button = styled.button(function (_ref) {
|
|
20
22
|
}
|
21
23
|
};
|
22
24
|
});
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
const Image = withTheme(styled.img(_ref2 => {
|
26
|
+
let {
|
27
|
+
hasBorder,
|
28
|
+
backgroundColor,
|
29
|
+
theme
|
30
|
+
} = _ref2;
|
27
31
|
return {
|
28
32
|
maxHeight: "".concat(IMG_SIZE, "px"),
|
29
33
|
width: "".concat(IMG_SIZE, "px"),
|
@@ -40,17 +44,17 @@ var Image = withTheme(styled.img(function (_ref2) {
|
|
40
44
|
}
|
41
45
|
};
|
42
46
|
}));
|
43
|
-
export
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
export const ImagePreview = withTheme(_ref3 => {
|
48
|
+
let {
|
49
|
+
isActive,
|
50
|
+
onClick,
|
51
|
+
imageName,
|
52
|
+
url,
|
53
|
+
theme,
|
54
|
+
error
|
55
|
+
} = _ref3;
|
50
56
|
|
51
|
-
|
52
|
-
return onClick(imageName);
|
53
|
-
};
|
57
|
+
const handleClick = () => onClick(imageName);
|
54
58
|
|
55
59
|
return /*#__PURE__*/React.createElement(Button, {
|
56
60
|
onClick: handleClick,
|
@@ -1,26 +1,16 @@
|
|
1
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
2
|
-
|
3
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
4
|
-
|
5
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
6
|
-
|
7
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
8
|
-
|
9
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
10
|
-
|
11
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
12
|
-
|
13
1
|
import React, { useState } from 'react';
|
14
2
|
import { getImageUrl } from '../../helpers';
|
15
3
|
import { Icons, Tabs } from '@storybook/components';
|
16
4
|
import { styled, withTheme } from '@storybook/theming';
|
17
5
|
import { ImagePreview } from './ImagePreview';
|
18
6
|
import { viewModes } from '../../viewMode';
|
19
|
-
|
7
|
+
const Container = styled.div({
|
20
8
|
margin: '24px 44px 0'
|
21
9
|
});
|
22
|
-
|
23
|
-
|
10
|
+
const ErrorContainer = withTheme(styled.div(_ref => {
|
11
|
+
let {
|
12
|
+
theme
|
13
|
+
} = _ref;
|
24
14
|
return {
|
25
15
|
marginTop: '8px',
|
26
16
|
padding: '8px',
|
@@ -41,62 +31,51 @@ var ErrorContainer = withTheme(styled.div(function (_ref) {
|
|
41
31
|
}
|
42
32
|
};
|
43
33
|
}));
|
44
|
-
|
34
|
+
const H1 = styled.h1({
|
45
35
|
margin: 0,
|
46
36
|
marginBottom: '8px'
|
47
37
|
});
|
48
|
-
|
49
|
-
|
38
|
+
const HeaderDivider = withTheme(styled.span(_ref2 => {
|
39
|
+
let {
|
40
|
+
theme
|
41
|
+
} = _ref2;
|
50
42
|
return {
|
51
43
|
padding: '0 8px',
|
52
44
|
color: theme.color.mediumdark
|
53
45
|
};
|
54
46
|
}));
|
55
|
-
|
47
|
+
const ImagesEntriesContainer = styled.div({
|
56
48
|
display: 'flex',
|
57
49
|
margin: '16px 0 8px'
|
58
50
|
});
|
59
51
|
export function PageHeader(_ref3) {
|
60
52
|
var _, _imageEntires$, _images$imageName;
|
61
53
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
54
|
+
let {
|
55
|
+
title,
|
56
|
+
images = {},
|
57
|
+
errorMessage,
|
58
|
+
showViewModes,
|
59
|
+
showTitle,
|
60
|
+
viewMode,
|
61
|
+
imagesWithError = [],
|
62
|
+
onImageChange,
|
63
|
+
onViewModeChange
|
64
|
+
} = _ref3;
|
65
|
+
const imageEntires = Object.entries(images);
|
66
|
+
const [imageName, setImageName] = useState((_ = ((_imageEntires$ = imageEntires[0]) !== null && _imageEntires$ !== void 0 ? _imageEntires$ : [])[0]) !== null && _ !== void 0 ? _ : '');
|
74
67
|
|
75
|
-
|
76
|
-
_useState2 = _slicedToArray(_useState, 2),
|
77
|
-
imageName = _useState2[0],
|
78
|
-
setImageName = _useState2[1];
|
68
|
+
const handleImageChange = name => (setImageName(name), onImageChange(name));
|
79
69
|
|
80
|
-
|
81
|
-
return setImageName(name), onImageChange(name);
|
82
|
-
};
|
83
|
-
|
84
|
-
var handleViewModeChange = function handleViewModeChange(mode) {
|
85
|
-
return onViewModeChange(mode);
|
86
|
-
};
|
70
|
+
const handleViewModeChange = mode => onViewModeChange(mode);
|
87
71
|
|
88
|
-
|
89
|
-
return showTitle || error || imageEntires.length > 1 || showViewModes ? /*#__PURE__*/React.createElement(Container, null, showTitle && /*#__PURE__*/React.createElement(H1, null, title.flatMap(
|
90
|
-
|
91
|
-
|
92
|
-
}, "/")];
|
93
|
-
}).slice(0, -1)), error && /*#__PURE__*/React.createElement(ErrorContainer, null, /*#__PURE__*/React.createElement(Icons, {
|
72
|
+
const error = errorMessage || imagesWithError.includes(imageName) ? ((_images$imageName = images[imageName]) === null || _images$imageName === void 0 ? void 0 : _images$imageName.error) || errorMessage : null;
|
73
|
+
return showTitle || error || imageEntires.length > 1 || showViewModes ? /*#__PURE__*/React.createElement(Container, null, showTitle && /*#__PURE__*/React.createElement(H1, null, title.flatMap(token => [token, /*#__PURE__*/React.createElement(HeaderDivider, {
|
74
|
+
key: token
|
75
|
+
}, "/")]).slice(0, -1)), error && /*#__PURE__*/React.createElement(ErrorContainer, null, /*#__PURE__*/React.createElement(Icons, {
|
94
76
|
icon: "closeAlt"
|
95
|
-
}), /*#__PURE__*/React.createElement("pre", null, error)), imageEntires.length > 1 ? /*#__PURE__*/React.createElement(ImagesEntriesContainer, null, imageEntires.map(
|
96
|
-
|
97
|
-
name = _ref5[0],
|
98
|
-
image = _ref5[1];
|
99
|
-
|
77
|
+
}), /*#__PURE__*/React.createElement("pre", null, error)), imageEntires.length > 1 ? /*#__PURE__*/React.createElement(ImagesEntriesContainer, null, imageEntires.map(_ref4 => {
|
78
|
+
let [name, image] = _ref4;
|
100
79
|
return /*#__PURE__*/React.createElement(ImagePreview, {
|
101
80
|
key: name,
|
102
81
|
imageName: name,
|
@@ -110,11 +89,9 @@ export function PageHeader(_ref3) {
|
|
110
89
|
actions: {
|
111
90
|
onSelect: handleViewModeChange
|
112
91
|
}
|
113
|
-
}, viewModes.map(
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
});
|
119
|
-
}))) : null;
|
92
|
+
}, viewModes.map(x => /*#__PURE__*/React.createElement("div", {
|
93
|
+
key: x,
|
94
|
+
id: x,
|
95
|
+
title: x
|
96
|
+
})))) : null;
|
120
97
|
}
|
@@ -1,15 +1,3 @@
|
|
1
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
2
|
-
|
3
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
4
|
-
|
5
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
6
|
-
|
7
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
8
|
-
|
9
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
10
|
-
|
11
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
12
|
-
|
13
1
|
import React, { useState, useEffect } from 'react';
|
14
2
|
import { ImagesView } from './ImagesView/ImagesView';
|
15
3
|
import { PageHeader } from './PageHeader/PageHeader';
|
@@ -18,39 +6,42 @@ import { getImageUrl } from '../helpers';
|
|
18
6
|
import { styled, withTheme } from '@storybook/theming';
|
19
7
|
import { Placeholder, ScrollArea } from '@storybook/components';
|
20
8
|
import { getViewMode, VIEW_MODE_KEY } from '../viewMode';
|
21
|
-
|
9
|
+
const Wrapper = styled.div({
|
22
10
|
width: '100%',
|
23
11
|
height: '100%',
|
24
12
|
boxSizing: 'border-box',
|
25
13
|
display: 'flex',
|
26
14
|
flexDirection: 'column'
|
27
15
|
});
|
28
|
-
|
29
|
-
|
16
|
+
const ImagesViewContainer = styled.div(_ref => {
|
17
|
+
let {
|
18
|
+
theme
|
19
|
+
} = _ref;
|
30
20
|
return {
|
31
21
|
background: theme.base == 'light' ? theme.color.mediumlight : theme.color.darker,
|
32
22
|
flexGrow: 1,
|
33
23
|
padding: '20px 0'
|
34
24
|
};
|
35
25
|
});
|
36
|
-
|
26
|
+
const HeaderContainer = styled.div({
|
37
27
|
position: 'sticky',
|
38
28
|
top: 0,
|
39
29
|
zIndex: 1
|
40
30
|
});
|
41
|
-
|
31
|
+
const BodyContainer = styled.div({
|
42
32
|
flexGrow: 1
|
43
33
|
});
|
44
|
-
|
34
|
+
const FooterContainer = styled.div({
|
45
35
|
position: 'sticky',
|
46
36
|
bottom: 0,
|
47
37
|
zIndex: 1
|
48
38
|
});
|
49
|
-
|
50
|
-
|
51
|
-
|
39
|
+
const Container = styled.div(_ref2 => {
|
40
|
+
let {
|
41
|
+
height = '100vh'
|
42
|
+
} = _ref2;
|
52
43
|
return {
|
53
|
-
height
|
44
|
+
height,
|
54
45
|
width: '100%',
|
55
46
|
overflowY: 'hidden',
|
56
47
|
display: 'flex',
|
@@ -60,53 +51,34 @@ var Container = styled.div(function (_ref2) {
|
|
60
51
|
export function ResultsPageInternal(_ref3) {
|
61
52
|
var _results, _Object$keys$, _result$images, _result$images2;
|
62
53
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
84
|
-
imageName = _useState4[0],
|
85
|
-
setImageName = _useState4[1];
|
86
|
-
|
87
|
-
var _useState5 = useState(getViewMode()),
|
88
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
89
|
-
viewMode = _useState6[0],
|
90
|
-
setViewMode = _useState6[1];
|
91
|
-
|
92
|
-
useEffect(function () {
|
93
|
-
return setRetry(results.length);
|
94
|
-
}, [results.length]);
|
95
|
-
var url = getImageUrl(path, imageName);
|
96
|
-
var image = (_result$images2 = result.images) === null || _result$images2 === void 0 ? void 0 : _result$images2[imageName];
|
97
|
-
var canApprove = Boolean(image && approved[imageName] != retry - 1 && result.status != 'success');
|
98
|
-
var hasDiffAndExpect = canApprove && Boolean((image === null || image === void 0 ? void 0 : image.diff) && image.expect);
|
99
|
-
var imagesWithError = result.images ? Object.keys(result.images).filter(function (imageName) {
|
54
|
+
let {
|
55
|
+
id,
|
56
|
+
path,
|
57
|
+
results = [],
|
58
|
+
approved = {},
|
59
|
+
theme,
|
60
|
+
onImageApprove,
|
61
|
+
showTitle = false,
|
62
|
+
height
|
63
|
+
} = _ref3;
|
64
|
+
const [retry, setRetry] = useState(results.length);
|
65
|
+
const result = (_results = results[retry - 1]) !== null && _results !== void 0 ? _results : {};
|
66
|
+
const [imageName, setImageName] = useState((_Object$keys$ = Object.keys((_result$images = result.images) !== null && _result$images !== void 0 ? _result$images : {})[0]) !== null && _Object$keys$ !== void 0 ? _Object$keys$ : '');
|
67
|
+
const [viewMode, setViewMode] = useState(getViewMode());
|
68
|
+
useEffect(() => setRetry(results.length), [results.length]);
|
69
|
+
const url = getImageUrl(path, imageName);
|
70
|
+
const image = (_result$images2 = result.images) === null || _result$images2 === void 0 ? void 0 : _result$images2[imageName];
|
71
|
+
const canApprove = Boolean(image && approved[imageName] != retry - 1 && result.status != 'success');
|
72
|
+
const hasDiffAndExpect = canApprove && Boolean((image === null || image === void 0 ? void 0 : image.diff) && image.expect);
|
73
|
+
const imagesWithError = result.images ? Object.keys(result.images).filter(imageName => {
|
100
74
|
var _imageName;
|
101
75
|
|
102
76
|
return result.status != 'success' && approved[imageName] != retry - 1 && ((_imageName = (result.images || {})[imageName]) === null || _imageName === void 0 ? void 0 : _imageName.error) != null;
|
103
77
|
}) : [];
|
104
78
|
|
105
|
-
|
106
|
-
return onImageApprove(id, retry - 1, imageName);
|
107
|
-
};
|
79
|
+
const handleApprove = () => onImageApprove(id, retry - 1, imageName);
|
108
80
|
|
109
|
-
|
81
|
+
const handleChangeViewMode = mode => {
|
110
82
|
localStorage.setItem(VIEW_MODE_KEY, mode);
|
111
83
|
setViewMode(mode);
|
112
84
|
};
|
@@ -140,4 +112,4 @@ export function ResultsPageInternal(_ref3) {
|
|
140
112
|
onApprove: handleApprove
|
141
113
|
})) : null);
|
142
114
|
}
|
143
|
-
export
|
115
|
+
export const ResultsPage = withTheme(ResultsPageInternal);
|
@@ -1,98 +1,67 @@
|
|
1
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
2
|
-
|
3
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
4
|
-
|
5
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
6
|
-
|
7
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
8
|
-
|
9
1
|
import { noop } from '../../types';
|
10
2
|
import { getConnectionUrl } from './helpers';
|
11
|
-
export function initCreeveyClientApi() {
|
12
|
-
|
13
|
-
|
3
|
+
export async function initCreeveyClientApi() {
|
4
|
+
let clientApiResolver = noop;
|
5
|
+
const updateListeners = new Set();
|
6
|
+
let statusRequest = null;
|
7
|
+
let statusResolver = noop;
|
8
|
+
const ws = new WebSocket("ws://".concat(getConnectionUrl()));
|
14
9
|
|
15
|
-
function
|
16
|
-
|
17
|
-
|
18
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
19
|
-
while (1) {
|
20
|
-
switch (_context.prev = _context.next) {
|
21
|
-
case 0:
|
22
|
-
send = function _send(request) {
|
23
|
-
ws.send(JSON.stringify(request));
|
24
|
-
};
|
10
|
+
function send(request) {
|
11
|
+
ws.send(JSON.stringify(request));
|
12
|
+
}
|
25
13
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
send({
|
35
|
-
type: 'start',
|
36
|
-
payload: ids
|
37
|
-
});
|
38
|
-
},
|
39
|
-
stop: function stop() {
|
40
|
-
send({
|
41
|
-
type: 'stop'
|
42
|
-
});
|
43
|
-
},
|
44
|
-
approve: function approve(id, retry, image) {
|
45
|
-
send({
|
46
|
-
type: 'approve',
|
47
|
-
payload: {
|
48
|
-
id: id,
|
49
|
-
retry: retry,
|
50
|
-
image: image
|
51
|
-
}
|
52
|
-
});
|
53
|
-
},
|
54
|
-
onUpdate: function onUpdate(fn) {
|
55
|
-
updateListeners.add(fn);
|
56
|
-
return function () {
|
57
|
-
return updateListeners.delete(fn);
|
58
|
-
};
|
59
|
-
},
|
14
|
+
ws.addEventListener('open', () => {
|
15
|
+
clientApiResolver({
|
16
|
+
start(ids) {
|
17
|
+
send({
|
18
|
+
type: 'start',
|
19
|
+
payload: ids
|
20
|
+
});
|
21
|
+
},
|
60
22
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
return statusRequest = new Promise(function (resolve) {
|
67
|
-
return statusResolver = resolve;
|
68
|
-
});
|
69
|
-
}
|
23
|
+
stop() {
|
24
|
+
send({
|
25
|
+
type: 'stop'
|
26
|
+
});
|
27
|
+
},
|
70
28
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
29
|
+
approve(id, retry, image) {
|
30
|
+
send({
|
31
|
+
type: 'approve',
|
32
|
+
payload: {
|
33
|
+
id,
|
34
|
+
retry,
|
35
|
+
image
|
36
|
+
}
|
37
|
+
});
|
38
|
+
},
|
78
39
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
}
|
84
|
-
}); // TODO Reconnect
|
40
|
+
onUpdate(fn) {
|
41
|
+
updateListeners.add(fn);
|
42
|
+
return () => updateListeners.delete(fn);
|
43
|
+
},
|
85
44
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
return _context.stop();
|
93
|
-
}
|
45
|
+
get status() {
|
46
|
+
if (statusRequest) return statusRequest;
|
47
|
+
send({
|
48
|
+
type: 'status'
|
49
|
+
});
|
50
|
+
return statusRequest = new Promise(resolve => statusResolver = resolve);
|
94
51
|
}
|
95
|
-
|
96
|
-
|
97
|
-
|
52
|
+
|
53
|
+
});
|
54
|
+
});
|
55
|
+
ws.addEventListener('message', message => {
|
56
|
+
const data = JSON.parse(message.data);
|
57
|
+
if (data.type == 'update') updateListeners.forEach(fn => fn(data.payload));
|
58
|
+
|
59
|
+
if (data.type == 'status') {
|
60
|
+
statusResolver(data.payload);
|
61
|
+
statusResolver = noop;
|
62
|
+
statusRequest = null;
|
63
|
+
}
|
64
|
+
}); // TODO Reconnect
|
65
|
+
|
66
|
+
return new Promise(resolve => clientApiResolver = resolve);
|
98
67
|
}
|