@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 _props$submit = props.submit,
9
- submit = _props$submit === void 0 ? true : _props$submit;
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 _scheduleSubmit = function scheduleSubmit() {
17
- var _form$getRegisteredFi;
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 form = formRef.current;
22
- var hasFields = Boolean(form === null || form === void 0 || (_form$getRegisteredFi = form.getRegisteredFields) === null || _form$getRegisteredFi === void 0 ? void 0 : _form$getRegisteredFi.call(form).length);
23
- if (!form || !hasFields) {
24
- timeoutId = setTimeout(_scheduleSubmit, 0);
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
- form.submit();
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(_scheduleSubmit, 0);
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(props.children, {
36
- initialArgs: _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({}, props.initialArgs), {}, {
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
- allArgs: _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({}, props.allArgs), {}, {
52
+ },
53
+ args: args ? _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({}, args), {}, {
43
54
  ref: formRef
44
- }),
45
- context: _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({}, props.context), {}, {
46
- initialArgs: _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({}, props.context.initialArgs), {}, {
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({}, props.context.args), {}, {
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, _ref) {
16
- var parameters = _ref.parameters,
17
- context = _ref.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 _props$submit = props.submit,
7
- submit = _props$submit === void 0 ? true : _props$submit;
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 _scheduleSubmit = function scheduleSubmit() {
15
- var _form$getRegisteredFi;
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 form = formRef.current;
20
- var hasFields = Boolean(form === null || form === void 0 || (_form$getRegisteredFi = form.getRegisteredFields) === null || _form$getRegisteredFi === void 0 ? void 0 : _form$getRegisteredFi.call(form).length);
21
- if (!form || !hasFields) {
22
- timeoutId = setTimeout(_scheduleSubmit, 0);
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
- form.submit();
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(_scheduleSubmit, 0);
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(props.children, {
34
- initialArgs: _objectSpread2(_objectSpread2({}, props.initialArgs), {}, {
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
- allArgs: _objectSpread2(_objectSpread2({}, props.allArgs), {}, {
50
+ },
51
+ args: args ? _objectSpread2(_objectSpread2({}, args), {}, {
41
52
  ref: formRef
42
- }),
43
- context: _objectSpread2(_objectSpread2({}, props.context), {}, {
44
- initialArgs: _objectSpread2(_objectSpread2({}, props.context.initialArgs), {}, {
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({}, props.context.args), {}, {
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, _ref) {
14
- var parameters = _ref.parameters,
15
- context = _ref.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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itcase/storybook-config",
3
- "version": "1.2.60",
3
+ "version": "1.2.62",
4
4
  "author": "ITCase",
5
5
  "description": "Storybook configuration package",
6
6
  "engines": {