@itcase/storybook-config 1.2.65 → 1.2.66

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.
@@ -0,0 +1,207 @@
1
+ 'use strict';
2
+
3
+ var _rollupPluginBabelHelpers = require('./_rollupPluginBabelHelpers-D8XyM9rZ.js');
4
+ var React = require('react');
5
+
6
+ var SUBMIT_TIMEOUT_MS = 15000;
7
+ var SUBMIT_POLL_MS = 50;
8
+ function getMountRoot() {
9
+ var _ref, _document$getElementB;
10
+ return (_ref = (_document$getElementB = document.getElementById('storybook-root')) !== null && _document$getElementB !== void 0 ? _document$getElementB : document.getElementById('root')) !== null && _ref !== void 0 ? _ref : document.body;
11
+ }
12
+ function sleep() {
13
+ var ms = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : SUBMIT_POLL_MS;
14
+ return new Promise(function (resolve) {
15
+ setTimeout(resolve, ms);
16
+ });
17
+ }
18
+ function prepareFormForAutoSubmit(form) {
19
+ var _config$field, _fieldState$value, _config$suffix;
20
+ var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
21
+ var fieldNames = typeof (form === null || form === void 0 ? void 0 : form.getRegisteredFields) === 'function' ? form.getRegisteredFields() : [];
22
+ var fieldName = (_config$field = config.field) !== null && _config$field !== void 0 ? _config$field : fieldNames[0];
23
+ if (!fieldName) {
24
+ return false;
25
+ }
26
+ var fieldState = form.getFieldState(fieldName);
27
+ var value = (_fieldState$value = fieldState === null || fieldState === void 0 ? void 0 : fieldState.value) !== null && _fieldState$value !== void 0 ? _fieldState$value : '';
28
+ var suffix = (_config$suffix = config.suffix) !== null && _config$suffix !== void 0 ? _config$suffix : "\u200B";
29
+ var nextValue = "".concat(value).concat(suffix);
30
+ if (nextValue === value) {
31
+ return false;
32
+ }
33
+ form.change(fieldName, nextValue);
34
+ return true;
35
+ }
36
+ function findSubmitButton(root) {
37
+ if (!root) {
38
+ return null;
39
+ }
40
+ var byType = root.querySelector('button[type="submit"]');
41
+ if (byType) {
42
+ return byType;
43
+ }
44
+ var form = root.querySelector('form[data-testid], form');
45
+ if (!form) {
46
+ return null;
47
+ }
48
+ var primaryInGroup = form.querySelector('.form__button .form__button-item, .form__button-item');
49
+ if (primaryInGroup) {
50
+ return primaryInGroup;
51
+ }
52
+ var byTestId = form.querySelector('button[data-testid*="Submit"], button[data-testid*="SignIn"], button[data-testid*="Create"]');
53
+ return byTestId;
54
+ }
55
+ function getFormSubmitTarget(formRef) {
56
+ var root = getMountRoot();
57
+ var submitButton = findSubmitButton(root);
58
+ var form = formRef.current;
59
+ var hasFields = typeof (form === null || form === void 0 ? void 0 : form.getRegisteredFields) === 'function' && form.getRegisteredFields().length > 0;
60
+ return {
61
+ canMarkForm: Boolean(form && hasFields),
62
+ canSubmit: Boolean(submitButton),
63
+ form: form,
64
+ submitButton: submitButton
65
+ };
66
+ }
67
+ function autoSubmitForm(_x, _x2, _x3) {
68
+ return _autoSubmitForm.apply(this, arguments);
69
+ }
70
+ function _autoSubmitForm() {
71
+ _autoSubmitForm = _rollupPluginBabelHelpers._asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers._regenerator().m(function _callee(formRef, formSubmitConfig, signal) {
72
+ var deadline, didPrepareUnchangedSubmit, _getFormSubmitTarget, canMarkForm, canSubmit, form, submitButton;
73
+ return _rollupPluginBabelHelpers._regenerator().w(function (_context) {
74
+ while (1) switch (_context.n) {
75
+ case 0:
76
+ deadline = Date.now() + SUBMIT_TIMEOUT_MS;
77
+ didPrepareUnchangedSubmit = false;
78
+ case 1:
79
+ if (!(Date.now() < deadline)) {
80
+ _context.n = 9;
81
+ break;
82
+ }
83
+ if (!signal.aborted) {
84
+ _context.n = 2;
85
+ break;
86
+ }
87
+ return _context.a(2);
88
+ case 2:
89
+ _getFormSubmitTarget = getFormSubmitTarget(formRef), canMarkForm = _getFormSubmitTarget.canMarkForm, canSubmit = _getFormSubmitTarget.canSubmit, form = _getFormSubmitTarget.form, submitButton = _getFormSubmitTarget.submitButton;
90
+ if (canSubmit) {
91
+ _context.n = 4;
92
+ break;
93
+ }
94
+ _context.n = 3;
95
+ return sleep();
96
+ case 3:
97
+ return _context.a(3, 1);
98
+ case 4:
99
+ if (!(formSubmitConfig !== null && formSubmitConfig !== void 0 && formSubmitConfig.allowUnchangedSubmit && !didPrepareUnchangedSubmit)) {
100
+ _context.n = 8;
101
+ break;
102
+ }
103
+ if (!canMarkForm) {
104
+ _context.n = 6;
105
+ break;
106
+ }
107
+ prepareFormForAutoSubmit(form, formSubmitConfig);
108
+ didPrepareUnchangedSubmit = true;
109
+ _context.n = 5;
110
+ return sleep();
111
+ case 5:
112
+ return _context.a(3, 1);
113
+ case 6:
114
+ _context.n = 7;
115
+ return sleep();
116
+ case 7:
117
+ return _context.a(3, 1);
118
+ case 8:
119
+ submitButton.click();
120
+ return _context.a(2);
121
+ case 9:
122
+ return _context.a(2);
123
+ }
124
+ }, _callee);
125
+ }));
126
+ return _autoSubmitForm.apply(this, arguments);
127
+ }
128
+
129
+ function wrapRender(component, render, formRef) {
130
+ if (!component || typeof render !== 'function') {
131
+ return render;
132
+ }
133
+ return function renderWithRef(storyArgs) {
134
+ var args = _rollupPluginBabelHelpers._objectSpread2({}, storyArgs !== null && storyArgs !== void 0 ? storyArgs : {});
135
+ delete args.ref;
136
+ return /*#__PURE__*/React.createElement(component, _rollupPluginBabelHelpers._objectSpread2({
137
+ ref: formRef
138
+ }, args));
139
+ };
140
+ }
141
+ function withFormRef(children, formRef, bindings) {
142
+ var _ref, _children$props, _ref2, _children$props2, _ref3, _children$props3;
143
+ var component = bindings.component,
144
+ args = bindings.args,
145
+ storyRender = bindings.render,
146
+ allArgs = bindings.allArgs,
147
+ context = bindings.context;
148
+ var storyComponent = (_ref = component !== null && component !== void 0 ? component : context === null || context === void 0 ? void 0 : context.component) !== null && _ref !== void 0 ? _ref : children === null || children === void 0 || (_children$props = children.props) === null || _children$props === void 0 ? void 0 : _children$props.component;
149
+ var storyRenderFn = (_ref2 = storyRender !== null && storyRender !== void 0 ? storyRender : context === null || context === void 0 ? void 0 : context.render) !== null && _ref2 !== void 0 ? _ref2 : children === null || children === void 0 || (_children$props2 = children.props) === null || _children$props2 === void 0 ? void 0 : _children$props2.render;
150
+ var boundRender = wrapRender(storyComponent, storyRenderFn, formRef);
151
+ var addRef = function addRef(value) {
152
+ return value ? _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({}, value), {}, {
153
+ ref: formRef
154
+ }) : value;
155
+ };
156
+ return /*#__PURE__*/React.cloneElement(children, {
157
+ component: storyComponent,
158
+ args: addRef((_ref3 = args !== null && args !== void 0 ? args : context === null || context === void 0 ? void 0 : context.args) !== null && _ref3 !== void 0 ? _ref3 : children === null || children === void 0 || (_children$props3 = children.props) === null || _children$props3 === void 0 ? void 0 : _children$props3.args),
159
+ render: boundRender,
160
+ allArgs: addRef(allArgs),
161
+ context: context ? _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({}, context), {}, {
162
+ component: storyComponent,
163
+ args: addRef(context.args),
164
+ render: boundRender,
165
+ allArgs: addRef(context.allArgs)
166
+ }) : context
167
+ });
168
+ }
169
+
170
+ /**
171
+ * Авто-submit для интерактивного Storybook (Require / Validation / ServerError).
172
+ * В Vitest не используется — submit делается в play.
173
+ */
174
+ function FormSubmitWrapper(props) {
175
+ var formRef = React.useRef(null);
176
+ var component = props.component,
177
+ args = props.args,
178
+ parameters = props.parameters,
179
+ render = props.render,
180
+ allArgs = props.allArgs,
181
+ context = props.context,
182
+ _props$submit = props.submit,
183
+ submit = _props$submit === void 0 ? true : _props$submit,
184
+ children = props.children;
185
+ var formSubmitConfig = parameters === null || parameters === void 0 ? void 0 : parameters.formSubmit;
186
+ React.useEffect(function () {
187
+ if (!submit) {
188
+ return undefined;
189
+ }
190
+ var abortController = new AbortController();
191
+ autoSubmitForm(formRef, formSubmitConfig, abortController.signal);
192
+ return function () {
193
+ abortController.abort();
194
+ };
195
+ }, [formSubmitConfig, submit]);
196
+
197
+ // eslint-disable-next-line react-hooks/refs -- ref уходит в createElement внутри bound render
198
+ return withFormRef(children, formRef, {
199
+ component: component,
200
+ args: args,
201
+ render: render,
202
+ allArgs: allArgs,
203
+ context: context
204
+ });
205
+ }
206
+
207
+ exports.FormSubmitWrapper = FormSubmitWrapper;
@@ -0,0 +1,203 @@
1
+ 'use strict';
2
+
3
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
4
+ try {
5
+ var i = n[a](c),
6
+ u = i.value;
7
+ } catch (n) {
8
+ return void e(n);
9
+ }
10
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
11
+ }
12
+ function _asyncToGenerator(n) {
13
+ return function () {
14
+ var t = this,
15
+ e = arguments;
16
+ return new Promise(function (r, o) {
17
+ var a = n.apply(t, e);
18
+ function _next(n) {
19
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
20
+ }
21
+ function _throw(n) {
22
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
23
+ }
24
+ _next(void 0);
25
+ });
26
+ };
27
+ }
28
+ function _defineProperty(e, r, t) {
29
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
30
+ value: t,
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true
34
+ }) : e[r] = t, e;
35
+ }
36
+ function ownKeys(e, r) {
37
+ var t = Object.keys(e);
38
+ if (Object.getOwnPropertySymbols) {
39
+ var o = Object.getOwnPropertySymbols(e);
40
+ r && (o = o.filter(function (r) {
41
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
42
+ })), t.push.apply(t, o);
43
+ }
44
+ return t;
45
+ }
46
+ function _objectSpread2(e) {
47
+ for (var r = 1; r < arguments.length; r++) {
48
+ var t = null != arguments[r] ? arguments[r] : {};
49
+ r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
50
+ _defineProperty(e, r, t[r]);
51
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
52
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
53
+ });
54
+ }
55
+ return e;
56
+ }
57
+ function _objectWithoutProperties(e, t) {
58
+ if (null == e) return {};
59
+ var o,
60
+ r,
61
+ i = _objectWithoutPropertiesLoose(e, t);
62
+ if (Object.getOwnPropertySymbols) {
63
+ var n = Object.getOwnPropertySymbols(e);
64
+ for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
65
+ }
66
+ return i;
67
+ }
68
+ function _objectWithoutPropertiesLoose(r, e) {
69
+ if (null == r) return {};
70
+ var t = {};
71
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
72
+ if (-1 !== e.indexOf(n)) continue;
73
+ t[n] = r[n];
74
+ }
75
+ return t;
76
+ }
77
+ function _regenerator() {
78
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
79
+ var e,
80
+ t,
81
+ r = "function" == typeof Symbol ? Symbol : {},
82
+ n = r.iterator || "@@iterator",
83
+ o = r.toStringTag || "@@toStringTag";
84
+ function i(r, n, o, i) {
85
+ var c = n && n.prototype instanceof Generator ? n : Generator,
86
+ u = Object.create(c.prototype);
87
+ return _regeneratorDefine(u, "_invoke", function (r, n, o) {
88
+ var i,
89
+ c,
90
+ u,
91
+ f = 0,
92
+ p = o || [],
93
+ y = false,
94
+ G = {
95
+ p: 0,
96
+ n: 0,
97
+ v: e,
98
+ a: d,
99
+ f: d.bind(e, 4),
100
+ d: function (t, r) {
101
+ return i = t, c = 0, u = e, G.n = r, a;
102
+ }
103
+ };
104
+ function d(r, n) {
105
+ for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
106
+ var o,
107
+ i = p[t],
108
+ d = G.p,
109
+ l = i[2];
110
+ r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
111
+ }
112
+ if (o || r > 1) return a;
113
+ throw y = true, n;
114
+ }
115
+ return function (o, p, l) {
116
+ if (f > 1) throw TypeError("Generator is already running");
117
+ for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
118
+ i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
119
+ try {
120
+ if (f = 2, i) {
121
+ if (c || (o = "next"), t = i[o]) {
122
+ if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
123
+ if (!t.done) return t;
124
+ u = t.value, c < 2 && (c = 0);
125
+ } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
126
+ i = e;
127
+ } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
128
+ } catch (t) {
129
+ i = e, c = 1, u = t;
130
+ } finally {
131
+ f = 1;
132
+ }
133
+ }
134
+ return {
135
+ value: t,
136
+ done: y
137
+ };
138
+ };
139
+ }(r, o, i), true), u;
140
+ }
141
+ var a = {};
142
+ function Generator() {}
143
+ function GeneratorFunction() {}
144
+ function GeneratorFunctionPrototype() {}
145
+ t = Object.getPrototypeOf;
146
+ var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
147
+ return this;
148
+ }), t),
149
+ u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
150
+ function f(e) {
151
+ return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
152
+ }
153
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
154
+ return this;
155
+ }), _regeneratorDefine(u, "toString", function () {
156
+ return "[object Generator]";
157
+ }), (_regenerator = function () {
158
+ return {
159
+ w: i,
160
+ m: f
161
+ };
162
+ })();
163
+ }
164
+ function _regeneratorDefine(e, r, n, t) {
165
+ var i = Object.defineProperty;
166
+ try {
167
+ i({}, "", {});
168
+ } catch (e) {
169
+ i = 0;
170
+ }
171
+ _regeneratorDefine = function (e, r, n, t) {
172
+ function o(r, n) {
173
+ _regeneratorDefine(e, r, function (e) {
174
+ return this._invoke(r, n, e);
175
+ });
176
+ }
177
+ r ? i ? i(e, r, {
178
+ value: n,
179
+ enumerable: !t,
180
+ configurable: !t,
181
+ writable: !t
182
+ }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
183
+ }, _regeneratorDefine(e, r, n, t);
184
+ }
185
+ function _toPrimitive(t, r) {
186
+ if ("object" != typeof t || !t) return t;
187
+ var e = t[Symbol.toPrimitive];
188
+ if (void 0 !== e) {
189
+ var i = e.call(t, r);
190
+ if ("object" != typeof i) return i;
191
+ throw new TypeError("@@toPrimitive must return a primitive value.");
192
+ }
193
+ return ("string" === r ? String : Number)(t);
194
+ }
195
+ function _toPropertyKey(t) {
196
+ var i = _toPrimitive(t, "string");
197
+ return "symbol" == typeof i ? i : i + "";
198
+ }
199
+
200
+ exports._asyncToGenerator = _asyncToGenerator;
201
+ exports._objectSpread2 = _objectSpread2;
202
+ exports._objectWithoutProperties = _objectWithoutProperties;
203
+ exports._regenerator = _regenerator;
@@ -1,11 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var FormSubmitWrapper = require('../../FormSubmitWrapper-Dg-gYkHi.js');
3
+ var FormSubmitWrapper = require('../../FormSubmitWrapper-i32wPLJH.js');
4
+ require('../../_rollupPluginBabelHelpers-D8XyM9rZ.js');
4
5
  require('react');
5
- require('../../_rollupPluginBabelHelpers-Wvf9ehn_.js');
6
6
 
7
7
 
8
8
 
9
9
  exports.FormSubmitWrapper = FormSubmitWrapper.FormSubmitWrapper;
10
- exports.cloneStoryWithFormRef = FormSubmitWrapper.cloneStoryWithFormRef;
11
- exports.markFormAsDataChanged = FormSubmitWrapper.markFormAsDataChanged;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var _rollupPluginBabelHelpers = require('../../_rollupPluginBabelHelpers-Wvf9ehn_.js');
3
+ var _rollupPluginBabelHelpers = require('../../_rollupPluginBabelHelpers-D8XyM9rZ.js');
4
4
  var React = require('react');
5
5
  var s = require('lodash/castArray');
6
6
 
@@ -1,22 +1,34 @@
1
1
  'use strict';
2
2
 
3
3
  var React = require('react');
4
- var FormSubmitWrapper = require('../../FormSubmitWrapper-Dg-gYkHi.js');
4
+ var FormSubmitWrapper = require('../../FormSubmitWrapper-i32wPLJH.js');
5
5
  require('lodash/camelCase');
6
6
  require('@itcase/common');
7
7
  require('msw');
8
- require('../../_rollupPluginBabelHelpers-Wvf9ehn_.js');
8
+ require('../../_rollupPluginBabelHelpers-D8XyM9rZ.js');
9
9
 
10
10
  function hasFormParameters(parameters) {
11
11
  return Boolean(parameters.require || parameters.validation || parameters.error || parameters.serverError || parameters.serverErrorData);
12
12
  }
13
13
 
14
+ function isVitestEnvironment() {
15
+ var _import$meta$env;
16
+ return Boolean((_import$meta$env = undefined) === null || _import$meta$env === void 0 ? void 0 : _import$meta$env.VITEST);
17
+ }
18
+
14
19
  function withFormSubmitDecorator() {
15
20
  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;
19
- return hasFormParameters(parameters) ? /*#__PURE__*/React.createElement(FormSubmitWrapper.FormSubmitWrapper, context, /*#__PURE__*/React.createElement(Story, context)) : /*#__PURE__*/React.createElement(Story, context);
21
+ var _storyContext$context;
22
+ var parameters = storyContext.parameters;
23
+ var context = (_storyContext$context = storyContext.context) !== null && _storyContext$context !== void 0 ? _storyContext$context : storyContext;
24
+ if (isVitestEnvironment() || !hasFormParameters(parameters)) {
25
+ return /*#__PURE__*/React.createElement(Story, context);
26
+ }
27
+ return /*#__PURE__*/React.createElement(FormSubmitWrapper.FormSubmitWrapper, Object.assign({}, context, {
28
+ parameters: parameters
29
+ }), /*#__PURE__*/React.createElement(Story, Object.assign({}, context, {
30
+ parameters: parameters
31
+ })));
20
32
  };
21
33
  return decorator;
22
34
  }
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var _rollupPluginBabelHelpers = require('../../_rollupPluginBabelHelpers-Wvf9ehn_.js');
3
+ var _rollupPluginBabelHelpers = require('../../_rollupPluginBabelHelpers-D8XyM9rZ.js');
4
4
  var React = require('react');
5
5
  var Notification = require('../../Notification-Cqx2_tCE.js');
6
6
  require('@itcase/common');
@@ -8,9 +8,9 @@ var withLayoutDecorator = require('./decorators/withLayoutDecorator.js');
8
8
  var withNextDecorator = require('./decorators/withNextDecorator.js');
9
9
  var withUiDecorator = require('./decorators/withUiDecorator.js');
10
10
  require('react');
11
- require('../_rollupPluginBabelHelpers-Wvf9ehn_.js');
11
+ require('../_rollupPluginBabelHelpers-D8XyM9rZ.js');
12
12
  require('lodash/castArray');
13
- require('../FormSubmitWrapper-Dg-gYkHi.js');
13
+ require('../FormSubmitWrapper-i32wPLJH.js');
14
14
  require('lodash/camelCase');
15
15
  require('@itcase/common');
16
16
  require('msw');