@itcase/storybook-config 1.2.60 → 1.2.62
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.
|
@@ -5,54 +5,78 @@ var React = require('react');
|
|
|
5
5
|
|
|
6
6
|
function FormSubmitWrapper(props) {
|
|
7
7
|
var formRef = React.useRef();
|
|
8
|
-
var
|
|
9
|
-
|
|
8
|
+
var initialArgs = props.initialArgs,
|
|
9
|
+
args = props.args,
|
|
10
|
+
allArgs = props.allArgs,
|
|
11
|
+
context = props.context,
|
|
12
|
+
_props$submit = props.submit,
|
|
13
|
+
submit = _props$submit === void 0 ? true : _props$submit,
|
|
14
|
+
children = props.children;
|
|
10
15
|
React.useEffect(function () {
|
|
11
16
|
if (!submit) {
|
|
12
17
|
return undefined;
|
|
13
18
|
}
|
|
14
19
|
var cancelled = false;
|
|
15
20
|
var timeoutId;
|
|
16
|
-
var
|
|
17
|
-
var
|
|
21
|
+
var _pollSubmit = function pollSubmit() {
|
|
22
|
+
var _document$getElementB, _formRef$current$getR, _formRef$current, _formRef$current$getR2;
|
|
18
23
|
if (cancelled) {
|
|
19
24
|
return;
|
|
20
25
|
}
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
var submitButton = (_document$getElementB = document.getElementById('storybook-root')) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.querySelector('button[type="submit"]');
|
|
27
|
+
var fieldCount = (_formRef$current$getR = (_formRef$current = formRef.current) === null || _formRef$current === void 0 || (_formRef$current$getR2 = _formRef$current.getRegisteredFields) === null || _formRef$current$getR2 === void 0 || (_formRef$current$getR2 = _formRef$current$getR2.call(_formRef$current)) === null || _formRef$current$getR2 === void 0 ? void 0 : _formRef$current$getR2.length) !== null && _formRef$current$getR !== void 0 ? _formRef$current$getR : 0;
|
|
28
|
+
var isReady = submitButton && (!formRef.current || fieldCount > 0);
|
|
29
|
+
if (!isReady) {
|
|
30
|
+
timeoutId = setTimeout(_pollSubmit, 0);
|
|
25
31
|
return;
|
|
26
32
|
}
|
|
27
|
-
|
|
33
|
+
timeoutId = setTimeout(function () {
|
|
34
|
+
var _formRef$current$subm, _formRef$current2, _formRef$current2$sub;
|
|
35
|
+
if (cancelled) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
(_formRef$current$subm = (_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 || (_formRef$current2$sub = _formRef$current2.submit) === null || _formRef$current2$sub === void 0 ? void 0 : _formRef$current2$sub.call(_formRef$current2)) !== null && _formRef$current$subm !== void 0 ? _formRef$current$subm : submitButton.click();
|
|
39
|
+
}, 100);
|
|
28
40
|
};
|
|
29
|
-
timeoutId = setTimeout(
|
|
41
|
+
timeoutId = setTimeout(_pollSubmit, 0);
|
|
30
42
|
return function () {
|
|
31
43
|
cancelled = true;
|
|
32
44
|
clearTimeout(timeoutId);
|
|
33
45
|
};
|
|
34
46
|
}, [submit]);
|
|
35
|
-
return /*#__PURE__*/React.cloneElement(
|
|
36
|
-
initialArgs: _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({},
|
|
47
|
+
return /*#__PURE__*/React.cloneElement(children, {
|
|
48
|
+
initialArgs: initialArgs ? _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({}, initialArgs), {}, {
|
|
37
49
|
ref: formRef
|
|
38
|
-
})
|
|
39
|
-
args: _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({}, props.args), {}, {
|
|
50
|
+
}) : {
|
|
40
51
|
ref: formRef
|
|
41
|
-
}
|
|
42
|
-
|
|
52
|
+
},
|
|
53
|
+
args: args ? _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({}, args), {}, {
|
|
43
54
|
ref: formRef
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
|
|
55
|
+
}) : {
|
|
56
|
+
ref: formRef
|
|
57
|
+
},
|
|
58
|
+
allArgs: allArgs ? _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({}, allArgs), {}, {
|
|
59
|
+
ref: formRef
|
|
60
|
+
}) : {
|
|
61
|
+
ref: formRef
|
|
62
|
+
},
|
|
63
|
+
context: context ? _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({}, context), {}, {
|
|
64
|
+
initialArgs: context.initialArgs ? _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({}, context.initialArgs), {}, {
|
|
65
|
+
ref: formRef
|
|
66
|
+
}) : {
|
|
47
67
|
ref: formRef
|
|
48
|
-
}
|
|
49
|
-
args: _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({},
|
|
68
|
+
},
|
|
69
|
+
args: context.args ? _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({}, context.args), {}, {
|
|
50
70
|
ref: formRef
|
|
51
|
-
})
|
|
52
|
-
allArgs: _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({}, props.context.allArgs), {}, {
|
|
71
|
+
}) : {
|
|
53
72
|
ref: formRef
|
|
54
|
-
}
|
|
55
|
-
|
|
73
|
+
},
|
|
74
|
+
allArgs: context.allArgs ? _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({}, context.allArgs), {}, {
|
|
75
|
+
ref: formRef
|
|
76
|
+
}) : {
|
|
77
|
+
ref: formRef
|
|
78
|
+
}
|
|
79
|
+
}) : context
|
|
56
80
|
});
|
|
57
81
|
}
|
|
58
82
|
|
|
@@ -12,9 +12,10 @@ function hasFormParameters(parameters) {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
function withFormSubmitDecorator() {
|
|
15
|
-
var decorator = function decorator(Story,
|
|
16
|
-
var parameters =
|
|
17
|
-
context =
|
|
15
|
+
var decorator = function decorator(Story, storyContext) {
|
|
16
|
+
var parameters = storyContext.parameters,
|
|
17
|
+
_storyContext$context = storyContext.context,
|
|
18
|
+
context = _storyContext$context === void 0 ? storyContext : _storyContext$context;
|
|
18
19
|
return hasFormParameters(parameters) ? /*#__PURE__*/React.createElement(index.FormSubmitWrapper, context, /*#__PURE__*/React.createElement(Story, context)) : /*#__PURE__*/React.createElement(Story, context);
|
|
19
20
|
};
|
|
20
21
|
return decorator;
|
|
@@ -3,54 +3,78 @@ import React__default, { useRef, useEffect } from 'react';
|
|
|
3
3
|
|
|
4
4
|
function FormSubmitWrapper(props) {
|
|
5
5
|
var formRef = useRef();
|
|
6
|
-
var
|
|
7
|
-
|
|
6
|
+
var initialArgs = props.initialArgs,
|
|
7
|
+
args = props.args,
|
|
8
|
+
allArgs = props.allArgs,
|
|
9
|
+
context = props.context,
|
|
10
|
+
_props$submit = props.submit,
|
|
11
|
+
submit = _props$submit === void 0 ? true : _props$submit,
|
|
12
|
+
children = props.children;
|
|
8
13
|
useEffect(function () {
|
|
9
14
|
if (!submit) {
|
|
10
15
|
return undefined;
|
|
11
16
|
}
|
|
12
17
|
var cancelled = false;
|
|
13
18
|
var timeoutId;
|
|
14
|
-
var
|
|
15
|
-
var
|
|
19
|
+
var _pollSubmit = function pollSubmit() {
|
|
20
|
+
var _document$getElementB, _formRef$current$getR, _formRef$current, _formRef$current$getR2;
|
|
16
21
|
if (cancelled) {
|
|
17
22
|
return;
|
|
18
23
|
}
|
|
19
|
-
var
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
var submitButton = (_document$getElementB = document.getElementById('storybook-root')) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.querySelector('button[type="submit"]');
|
|
25
|
+
var fieldCount = (_formRef$current$getR = (_formRef$current = formRef.current) === null || _formRef$current === void 0 || (_formRef$current$getR2 = _formRef$current.getRegisteredFields) === null || _formRef$current$getR2 === void 0 || (_formRef$current$getR2 = _formRef$current$getR2.call(_formRef$current)) === null || _formRef$current$getR2 === void 0 ? void 0 : _formRef$current$getR2.length) !== null && _formRef$current$getR !== void 0 ? _formRef$current$getR : 0;
|
|
26
|
+
var isReady = submitButton && (!formRef.current || fieldCount > 0);
|
|
27
|
+
if (!isReady) {
|
|
28
|
+
timeoutId = setTimeout(_pollSubmit, 0);
|
|
23
29
|
return;
|
|
24
30
|
}
|
|
25
|
-
|
|
31
|
+
timeoutId = setTimeout(function () {
|
|
32
|
+
var _formRef$current$subm, _formRef$current2, _formRef$current2$sub;
|
|
33
|
+
if (cancelled) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
(_formRef$current$subm = (_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 || (_formRef$current2$sub = _formRef$current2.submit) === null || _formRef$current2$sub === void 0 ? void 0 : _formRef$current2$sub.call(_formRef$current2)) !== null && _formRef$current$subm !== void 0 ? _formRef$current$subm : submitButton.click();
|
|
37
|
+
}, 100);
|
|
26
38
|
};
|
|
27
|
-
timeoutId = setTimeout(
|
|
39
|
+
timeoutId = setTimeout(_pollSubmit, 0);
|
|
28
40
|
return function () {
|
|
29
41
|
cancelled = true;
|
|
30
42
|
clearTimeout(timeoutId);
|
|
31
43
|
};
|
|
32
44
|
}, [submit]);
|
|
33
|
-
return /*#__PURE__*/React__default.cloneElement(
|
|
34
|
-
initialArgs: _objectSpread2(_objectSpread2({},
|
|
45
|
+
return /*#__PURE__*/React__default.cloneElement(children, {
|
|
46
|
+
initialArgs: initialArgs ? _objectSpread2(_objectSpread2({}, initialArgs), {}, {
|
|
35
47
|
ref: formRef
|
|
36
|
-
})
|
|
37
|
-
args: _objectSpread2(_objectSpread2({}, props.args), {}, {
|
|
48
|
+
}) : {
|
|
38
49
|
ref: formRef
|
|
39
|
-
}
|
|
40
|
-
|
|
50
|
+
},
|
|
51
|
+
args: args ? _objectSpread2(_objectSpread2({}, args), {}, {
|
|
41
52
|
ref: formRef
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
|
|
53
|
+
}) : {
|
|
54
|
+
ref: formRef
|
|
55
|
+
},
|
|
56
|
+
allArgs: allArgs ? _objectSpread2(_objectSpread2({}, allArgs), {}, {
|
|
57
|
+
ref: formRef
|
|
58
|
+
}) : {
|
|
59
|
+
ref: formRef
|
|
60
|
+
},
|
|
61
|
+
context: context ? _objectSpread2(_objectSpread2({}, context), {}, {
|
|
62
|
+
initialArgs: context.initialArgs ? _objectSpread2(_objectSpread2({}, context.initialArgs), {}, {
|
|
63
|
+
ref: formRef
|
|
64
|
+
}) : {
|
|
45
65
|
ref: formRef
|
|
46
|
-
}
|
|
47
|
-
args: _objectSpread2(_objectSpread2({},
|
|
66
|
+
},
|
|
67
|
+
args: context.args ? _objectSpread2(_objectSpread2({}, context.args), {}, {
|
|
48
68
|
ref: formRef
|
|
49
|
-
})
|
|
50
|
-
allArgs: _objectSpread2(_objectSpread2({}, props.context.allArgs), {}, {
|
|
69
|
+
}) : {
|
|
51
70
|
ref: formRef
|
|
52
|
-
}
|
|
53
|
-
|
|
71
|
+
},
|
|
72
|
+
allArgs: context.allArgs ? _objectSpread2(_objectSpread2({}, context.allArgs), {}, {
|
|
73
|
+
ref: formRef
|
|
74
|
+
}) : {
|
|
75
|
+
ref: formRef
|
|
76
|
+
}
|
|
77
|
+
}) : context
|
|
54
78
|
});
|
|
55
79
|
}
|
|
56
80
|
|
|
@@ -10,9 +10,10 @@ function hasFormParameters(parameters) {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
function withFormSubmitDecorator() {
|
|
13
|
-
var decorator = function decorator(Story,
|
|
14
|
-
var parameters =
|
|
15
|
-
context =
|
|
13
|
+
var decorator = function decorator(Story, storyContext) {
|
|
14
|
+
var parameters = storyContext.parameters,
|
|
15
|
+
_storyContext$context = storyContext.context,
|
|
16
|
+
context = _storyContext$context === void 0 ? storyContext : _storyContext$context;
|
|
16
17
|
return hasFormParameters(parameters) ? /*#__PURE__*/React__default.createElement(FormSubmitWrapper, context, /*#__PURE__*/React__default.createElement(Story, context)) : /*#__PURE__*/React__default.createElement(Story, context);
|
|
17
18
|
};
|
|
18
19
|
return decorator;
|