@itcase/storybook-config 1.2.61 → 1.2.63

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.
@@ -19,26 +19,34 @@ function FormSubmitWrapper(props) {
19
19
  }
20
20
  var cancelled = false;
21
21
  var timeoutId;
22
- var lastCount = 0;
22
+ var lastFieldCount = -1;
23
23
  var stableTicks = 0;
24
24
  var _pollSubmit = function pollSubmit() {
25
- var _form$getRegisteredFi, _form$getRegisteredFi2;
25
+ var _document$getElementB, _form$getRegisteredFi, _form$getRegisteredFi2;
26
26
  if (cancelled) {
27
27
  return;
28
28
  }
29
+ var submitButton = (_document$getElementB = document.getElementById('storybook-root')) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.querySelector('button[type="submit"]');
29
30
  var form = formRef.current;
30
- var count = (_form$getRegisteredFi = form === null || form === void 0 || (_form$getRegisteredFi2 = form.getRegisteredFields) === null || _form$getRegisteredFi2 === void 0 || (_form$getRegisteredFi2 = _form$getRegisteredFi2.call(form)) === null || _form$getRegisteredFi2 === void 0 ? void 0 : _form$getRegisteredFi2.length) !== null && _form$getRegisteredFi !== void 0 ? _form$getRegisteredFi : 0;
31
- if (!count) {
32
- lastCount = 0;
31
+ var fieldCount = (_form$getRegisteredFi = form === null || form === void 0 || (_form$getRegisteredFi2 = form.getRegisteredFields) === null || _form$getRegisteredFi2 === void 0 || (_form$getRegisteredFi2 = _form$getRegisteredFi2.call(form)) === null || _form$getRegisteredFi2 === void 0 ? void 0 : _form$getRegisteredFi2.length) !== null && _form$getRegisteredFi !== void 0 ? _form$getRegisteredFi : 0;
32
+ if (!submitButton || !form || fieldCount === 0) {
33
+ lastFieldCount = -1;
33
34
  stableTicks = 0;
34
- } else if (count !== lastCount) {
35
- lastCount = count;
36
- stableTicks = 1;
37
- } else if (++stableTicks >= STABLE_TICKS) {
38
- form.submit();
35
+ timeoutId = setTimeout(_pollSubmit, 0);
39
36
  return;
40
37
  }
41
- timeoutId = setTimeout(_pollSubmit, 0);
38
+ if (fieldCount !== lastFieldCount) {
39
+ lastFieldCount = fieldCount;
40
+ stableTicks = 0;
41
+ timeoutId = setTimeout(_pollSubmit, 0);
42
+ return;
43
+ }
44
+ stableTicks += 1;
45
+ if (stableTicks < STABLE_TICKS) {
46
+ timeoutId = setTimeout(_pollSubmit, 0);
47
+ return;
48
+ }
49
+ submitButton.click();
42
50
  };
43
51
  timeoutId = setTimeout(_pollSubmit, 0);
44
52
  return function () {
@@ -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;
@@ -17,26 +17,34 @@ function FormSubmitWrapper(props) {
17
17
  }
18
18
  var cancelled = false;
19
19
  var timeoutId;
20
- var lastCount = 0;
20
+ var lastFieldCount = -1;
21
21
  var stableTicks = 0;
22
22
  var _pollSubmit = function pollSubmit() {
23
- var _form$getRegisteredFi, _form$getRegisteredFi2;
23
+ var _document$getElementB, _form$getRegisteredFi, _form$getRegisteredFi2;
24
24
  if (cancelled) {
25
25
  return;
26
26
  }
27
+ var submitButton = (_document$getElementB = document.getElementById('storybook-root')) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.querySelector('button[type="submit"]');
27
28
  var form = formRef.current;
28
- var count = (_form$getRegisteredFi = form === null || form === void 0 || (_form$getRegisteredFi2 = form.getRegisteredFields) === null || _form$getRegisteredFi2 === void 0 || (_form$getRegisteredFi2 = _form$getRegisteredFi2.call(form)) === null || _form$getRegisteredFi2 === void 0 ? void 0 : _form$getRegisteredFi2.length) !== null && _form$getRegisteredFi !== void 0 ? _form$getRegisteredFi : 0;
29
- if (!count) {
30
- lastCount = 0;
29
+ var fieldCount = (_form$getRegisteredFi = form === null || form === void 0 || (_form$getRegisteredFi2 = form.getRegisteredFields) === null || _form$getRegisteredFi2 === void 0 || (_form$getRegisteredFi2 = _form$getRegisteredFi2.call(form)) === null || _form$getRegisteredFi2 === void 0 ? void 0 : _form$getRegisteredFi2.length) !== null && _form$getRegisteredFi !== void 0 ? _form$getRegisteredFi : 0;
30
+ if (!submitButton || !form || fieldCount === 0) {
31
+ lastFieldCount = -1;
31
32
  stableTicks = 0;
32
- } else if (count !== lastCount) {
33
- lastCount = count;
34
- stableTicks = 1;
35
- } else if (++stableTicks >= STABLE_TICKS) {
36
- form.submit();
33
+ timeoutId = setTimeout(_pollSubmit, 0);
37
34
  return;
38
35
  }
39
- timeoutId = setTimeout(_pollSubmit, 0);
36
+ if (fieldCount !== lastFieldCount) {
37
+ lastFieldCount = fieldCount;
38
+ stableTicks = 0;
39
+ timeoutId = setTimeout(_pollSubmit, 0);
40
+ return;
41
+ }
42
+ stableTicks += 1;
43
+ if (stableTicks < STABLE_TICKS) {
44
+ timeoutId = setTimeout(_pollSubmit, 0);
45
+ return;
46
+ }
47
+ submitButton.click();
40
48
  };
41
49
  timeoutId = setTimeout(_pollSubmit, 0);
42
50
  return function () {
@@ -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.61",
3
+ "version": "1.2.63",
4
4
  "author": "ITCase",
5
5
  "description": "Storybook configuration package",
6
6
  "engines": {