@itcase/storybook-config 1.2.72 → 1.2.74
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/dist/FormSubmitWrapper-BaqE4w9q.js +248 -0
- package/dist/{_rollupPluginBabelHelpers-D8XyM9rZ.js → _rollupPluginBabelHelpers-B1r4NF8e.js} +61 -0
- package/dist/cjs/components/FormSubmitWrapper.js +2 -2
- package/dist/cjs/decorators/withFigmaSourceLink.js +1 -1
- package/dist/cjs/decorators/withFormSubmitDecorator.js +20 -5
- package/dist/cjs/decorators/withNextDecorator.js +1 -1
- package/dist/cjs/decorators.js +3 -2
- package/dist/components/FormSubmitWrapper-DoGZRTm5.js +246 -0
- package/dist/components/FormSubmitWrapper.js +2 -2
- package/dist/components/{_rollupPluginBabelHelpers-OwKVS06F.js → _rollupPluginBabelHelpers-CEVa9ZMs.js} +61 -1
- package/dist/decorators/withFigmaSourceLink.js +1 -1
- package/dist/decorators/withFormSubmitDecorator.js +20 -5
- package/dist/decorators/withNextDecorator.js +1 -1
- package/dist/decorators.js +3 -2
- package/dist/utils/handleMSWParameters.js +20 -8
- package/dist/utils/index.js +2 -0
- package/dist/utils/storybookServerErrorOnSubmit.js +21 -0
- package/package.json +16 -16
- package/dist/FormSubmitWrapper-DXUEGLuS.js +0 -247
- package/dist/components/FormSubmitWrapper-CytvWwKi.js +0 -245
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _rollupPluginBabelHelpers = require('./_rollupPluginBabelHelpers-B1r4NF8e.js');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
|
|
6
|
+
var SUBMIT_POLL_MS = 50;
|
|
7
|
+
function getStoryPreviewDocument() {
|
|
8
|
+
var _document$getElementB, _previewIframe$conten;
|
|
9
|
+
var previewIframe = (_document$getElementB = document.getElementById('storybook-preview-iframe')) !== null && _document$getElementB !== void 0 ? _document$getElementB : document.querySelector('iframe[data-is-storybook="true"]');
|
|
10
|
+
return (_previewIframe$conten = previewIframe === null || previewIframe === void 0 ? void 0 : previewIframe.contentDocument) !== null && _previewIframe$conten !== void 0 ? _previewIframe$conten : null;
|
|
11
|
+
}
|
|
12
|
+
function getMountRoot() {
|
|
13
|
+
var _ref2, _document$getElementB2;
|
|
14
|
+
var previewDocument = getStoryPreviewDocument();
|
|
15
|
+
if (previewDocument) {
|
|
16
|
+
var _ref, _previewDocument$getE;
|
|
17
|
+
return (_ref = (_previewDocument$getE = previewDocument.getElementById('storybook-root')) !== null && _previewDocument$getE !== void 0 ? _previewDocument$getE : previewDocument.getElementById('root')) !== null && _ref !== void 0 ? _ref : previewDocument.body;
|
|
18
|
+
}
|
|
19
|
+
return (_ref2 = (_document$getElementB2 = document.getElementById('storybook-root')) !== null && _document$getElementB2 !== void 0 ? _document$getElementB2 : document.getElementById('root')) !== null && _ref2 !== void 0 ? _ref2 : document.body;
|
|
20
|
+
}
|
|
21
|
+
function canSubmitFormApi(form) {
|
|
22
|
+
return typeof (form === null || form === void 0 ? void 0 : form.submit) === 'function' && typeof form.getRegisteredFields === 'function' && form.getRegisteredFields().length > 0;
|
|
23
|
+
}
|
|
24
|
+
function findSaveDraftButton(root) {
|
|
25
|
+
if (!root) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
var saveDraft = root.querySelector('[data-testid$="SaveDraftButton"]');
|
|
29
|
+
if (!saveDraft) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return saveDraft.tagName === 'BUTTON' ? saveDraft : saveDraft.querySelector('button');
|
|
33
|
+
}
|
|
34
|
+
function findSubmitButton(root) {
|
|
35
|
+
var _form$querySelector;
|
|
36
|
+
if (!root) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
var byType = root.querySelector('button[type="submit"]');
|
|
40
|
+
if (byType) {
|
|
41
|
+
return byType;
|
|
42
|
+
}
|
|
43
|
+
var form = root.querySelector('form[data-testid], form');
|
|
44
|
+
if (!form) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return (_form$querySelector = form.querySelector('.form__button .form__button-item, .form__button-item')) !== null && _form$querySelector !== void 0 ? _form$querySelector : null;
|
|
48
|
+
}
|
|
49
|
+
function touchFieldsBeforeSubmit(form) {
|
|
50
|
+
if (!canSubmitFormApi(form)) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
var _iterator = _rollupPluginBabelHelpers._createForOfIteratorHelper(form.getRegisteredFields()),
|
|
54
|
+
_step;
|
|
55
|
+
try {
|
|
56
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
57
|
+
var _form$getFieldState;
|
|
58
|
+
var fieldName = _step.value;
|
|
59
|
+
if (!((_form$getFieldState = form.getFieldState(fieldName)) !== null && _form$getFieldState !== void 0 && _form$getFieldState.touched)) {
|
|
60
|
+
form.blur(fieldName);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
} catch (err) {
|
|
64
|
+
_iterator.e(err);
|
|
65
|
+
} finally {
|
|
66
|
+
_iterator.f();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function triggerFormSubmit(_ref3) {
|
|
70
|
+
var form = _ref3.form,
|
|
71
|
+
root = _ref3.root,
|
|
72
|
+
submitButton = _ref3.submitButton;
|
|
73
|
+
var saveDraftButton = findSaveDraftButton(root !== null && root !== void 0 ? root : getMountRoot());
|
|
74
|
+
if (saveDraftButton) {
|
|
75
|
+
saveDraftButton.click();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (canSubmitFormApi(form)) {
|
|
79
|
+
touchFieldsBeforeSubmit(form);
|
|
80
|
+
form.submit();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if ((submitButton === null || submitButton === void 0 ? void 0 : submitButton.type) === 'submit') {
|
|
84
|
+
submitButton.click();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function autoSubmitForm(_x, _x2) {
|
|
88
|
+
return _autoSubmitForm.apply(this, arguments);
|
|
89
|
+
}
|
|
90
|
+
function _autoSubmitForm() {
|
|
91
|
+
_autoSubmitForm = _rollupPluginBabelHelpers._asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers._regenerator().m(function _callee(formRef, signal) {
|
|
92
|
+
var root, form, submitButton, saveDraftButton, canSubmitViaFormApi, canClickNativeSubmit, canClickSaveDraft;
|
|
93
|
+
return _rollupPluginBabelHelpers._regenerator().w(function (_context) {
|
|
94
|
+
while (1) switch (_context.n) {
|
|
95
|
+
case 0:
|
|
96
|
+
if (!formRef.__itcaseDidAutoSubmit) {
|
|
97
|
+
_context.n = 1;
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
return _context.a(2);
|
|
101
|
+
case 1:
|
|
102
|
+
if (signal.aborted) {
|
|
103
|
+
_context.n = 6;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
root = getMountRoot();
|
|
107
|
+
form = formRef.current;
|
|
108
|
+
submitButton = findSubmitButton(root);
|
|
109
|
+
saveDraftButton = findSaveDraftButton(root);
|
|
110
|
+
canSubmitViaFormApi = canSubmitFormApi(form);
|
|
111
|
+
canClickNativeSubmit = (submitButton === null || submitButton === void 0 ? void 0 : submitButton.type) === 'submit';
|
|
112
|
+
canClickSaveDraft = Boolean(saveDraftButton); // primaryButtonHtmlType="button": ждём final-form API или кнопку черновика в DOM
|
|
113
|
+
if (!(!canSubmitViaFormApi && !canClickNativeSubmit && !canClickSaveDraft)) {
|
|
114
|
+
_context.n = 3;
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
_context.n = 2;
|
|
118
|
+
return new Promise(function (resolve) {
|
|
119
|
+
setTimeout(resolve, SUBMIT_POLL_MS);
|
|
120
|
+
});
|
|
121
|
+
case 2:
|
|
122
|
+
return _context.a(3, 1);
|
|
123
|
+
case 3:
|
|
124
|
+
formRef.__itcaseDidAutoSubmit = true;
|
|
125
|
+
_context.n = 4;
|
|
126
|
+
return new Promise(function (resolve) {
|
|
127
|
+
requestAnimationFrame(function () {
|
|
128
|
+
requestAnimationFrame(resolve);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
case 4:
|
|
132
|
+
if (!signal.aborted) {
|
|
133
|
+
_context.n = 5;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
return _context.a(2);
|
|
137
|
+
case 5:
|
|
138
|
+
triggerFormSubmit({
|
|
139
|
+
form: formRef.current,
|
|
140
|
+
root: root,
|
|
141
|
+
submitButton: submitButton
|
|
142
|
+
});
|
|
143
|
+
return _context.a(2);
|
|
144
|
+
case 6:
|
|
145
|
+
return _context.a(2);
|
|
146
|
+
}
|
|
147
|
+
}, _callee);
|
|
148
|
+
}));
|
|
149
|
+
return _autoSubmitForm.apply(this, arguments);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function wrapRender(component, render, formRef) {
|
|
153
|
+
var defaultArgs = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
154
|
+
if (typeof render !== 'function') {
|
|
155
|
+
return render;
|
|
156
|
+
}
|
|
157
|
+
return function renderWithRef(storyArgs) {
|
|
158
|
+
var args = _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({}, defaultArgs), storyArgs !== null && storyArgs !== void 0 ? storyArgs : {});
|
|
159
|
+
delete args.ref;
|
|
160
|
+
delete args.errors;
|
|
161
|
+
if (!args.onSubmit && defaultArgs.onSubmit) {
|
|
162
|
+
args.onSubmit = defaultArgs.onSubmit;
|
|
163
|
+
}
|
|
164
|
+
var rendered = render(args);
|
|
165
|
+
if (/*#__PURE__*/React.isValidElement(rendered)) {
|
|
166
|
+
return /*#__PURE__*/React.cloneElement(rendered, _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({}, rendered.props), args), {}, {
|
|
167
|
+
ref: formRef
|
|
168
|
+
}));
|
|
169
|
+
}
|
|
170
|
+
if (component) {
|
|
171
|
+
return /*#__PURE__*/React.createElement(component, _rollupPluginBabelHelpers._objectSpread2({
|
|
172
|
+
ref: formRef
|
|
173
|
+
}, args));
|
|
174
|
+
}
|
|
175
|
+
return rendered;
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function withFormRef(children, formRef, bindings) {
|
|
179
|
+
var _ref, _ref2, _children$props, _ref3, _children$props2, _ref4, _children$props3;
|
|
180
|
+
var component = bindings.component,
|
|
181
|
+
args = bindings.args,
|
|
182
|
+
storyRender = bindings.render,
|
|
183
|
+
allArgs = bindings.allArgs,
|
|
184
|
+
context = bindings.context;
|
|
185
|
+
var storyArgs = (_ref = (_ref2 = args !== null && args !== void 0 ? args : context === null || context === void 0 ? void 0 : context.args) !== null && _ref2 !== void 0 ? _ref2 : children === null || children === void 0 || (_children$props = children.props) === null || _children$props === void 0 ? void 0 : _children$props.args) !== null && _ref !== void 0 ? _ref : {};
|
|
186
|
+
var storyComponent = (_ref3 = component !== null && component !== void 0 ? component : context === null || context === void 0 ? void 0 : context.component) !== null && _ref3 !== void 0 ? _ref3 : children === null || children === void 0 || (_children$props2 = children.props) === null || _children$props2 === void 0 ? void 0 : _children$props2.component;
|
|
187
|
+
var storyRenderFn = (_ref4 = storyRender !== null && storyRender !== void 0 ? storyRender : context === null || context === void 0 ? void 0 : context.render) !== null && _ref4 !== void 0 ? _ref4 : children === null || children === void 0 || (_children$props3 = children.props) === null || _children$props3 === void 0 ? void 0 : _children$props3.render;
|
|
188
|
+
var boundRender = wrapRender(storyComponent, storyRenderFn, formRef, storyArgs);
|
|
189
|
+
var addRef = function addRef(value) {
|
|
190
|
+
return value ? _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({}, value), {}, {
|
|
191
|
+
ref: formRef
|
|
192
|
+
}) : value;
|
|
193
|
+
};
|
|
194
|
+
return /*#__PURE__*/React.cloneElement(children, {
|
|
195
|
+
component: storyComponent,
|
|
196
|
+
args: addRef(storyArgs),
|
|
197
|
+
render: boundRender,
|
|
198
|
+
allArgs: addRef(allArgs),
|
|
199
|
+
context: context ? _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({}, context), {}, {
|
|
200
|
+
component: storyComponent,
|
|
201
|
+
args: addRef(context.args),
|
|
202
|
+
render: boundRender,
|
|
203
|
+
allArgs: addRef(context.allArgs)
|
|
204
|
+
}) : context
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Авто-submit для интерактивного Storybook (Require / Validation / ServerError).
|
|
210
|
+
* При primaryButtonHtmlType="button" — formRef.current.submit() (final-form API),
|
|
211
|
+
* при type="submit" — click по кнопке. В Vitest submit в play.
|
|
212
|
+
*/
|
|
213
|
+
function FormSubmitWrapper(props) {
|
|
214
|
+
var _ref5, _ref6, _children$props4;
|
|
215
|
+
var formRef = React.useRef(null);
|
|
216
|
+
var component = props.component,
|
|
217
|
+
args = props.args,
|
|
218
|
+
render = props.render,
|
|
219
|
+
allArgs = props.allArgs,
|
|
220
|
+
context = props.context,
|
|
221
|
+
_props$submit = props.submit,
|
|
222
|
+
submit = _props$submit === void 0 ? true : _props$submit,
|
|
223
|
+
children = props.children;
|
|
224
|
+
var storyArgs = (_ref5 = (_ref6 = args !== null && args !== void 0 ? args : context === null || context === void 0 ? void 0 : context.args) !== null && _ref6 !== void 0 ? _ref6 : children === null || children === void 0 || (_children$props4 = children.props) === null || _children$props4 === void 0 ? void 0 : _children$props4.args) !== null && _ref5 !== void 0 ? _ref5 : {};
|
|
225
|
+
React.useEffect(function () {
|
|
226
|
+
if (!submit) {
|
|
227
|
+
return undefined;
|
|
228
|
+
}
|
|
229
|
+
delete formRef.__itcaseDidAutoSubmit;
|
|
230
|
+
var abortController = new AbortController();
|
|
231
|
+
autoSubmitForm(formRef, abortController.signal);
|
|
232
|
+
return function () {
|
|
233
|
+
abortController.abort();
|
|
234
|
+
delete formRef.__itcaseDidAutoSubmit;
|
|
235
|
+
};
|
|
236
|
+
}, [submit, storyArgs.errors]);
|
|
237
|
+
|
|
238
|
+
// eslint-disable-next-line react-hooks/refs -- ref уходит в cloneElement внутри bound render
|
|
239
|
+
return withFormRef(children, formRef, {
|
|
240
|
+
component: component,
|
|
241
|
+
args: storyArgs,
|
|
242
|
+
render: render,
|
|
243
|
+
allArgs: allArgs,
|
|
244
|
+
context: context
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
exports.FormSubmitWrapper = FormSubmitWrapper;
|
package/dist/{_rollupPluginBabelHelpers-D8XyM9rZ.js → _rollupPluginBabelHelpers-B1r4NF8e.js}
RENAMED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
function _arrayLikeToArray(r, a) {
|
|
4
|
+
(null == a || a > r.length) && (a = r.length);
|
|
5
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
6
|
+
return n;
|
|
7
|
+
}
|
|
3
8
|
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
4
9
|
try {
|
|
5
10
|
var i = n[a](c),
|
|
@@ -25,6 +30,54 @@ function _asyncToGenerator(n) {
|
|
|
25
30
|
});
|
|
26
31
|
};
|
|
27
32
|
}
|
|
33
|
+
function _createForOfIteratorHelper(r, e) {
|
|
34
|
+
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
35
|
+
if (!t) {
|
|
36
|
+
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) {
|
|
37
|
+
t && (r = t);
|
|
38
|
+
var n = 0,
|
|
39
|
+
F = function () {};
|
|
40
|
+
return {
|
|
41
|
+
s: F,
|
|
42
|
+
n: function () {
|
|
43
|
+
return n >= r.length ? {
|
|
44
|
+
done: true
|
|
45
|
+
} : {
|
|
46
|
+
done: false,
|
|
47
|
+
value: r[n++]
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
e: function (r) {
|
|
51
|
+
throw r;
|
|
52
|
+
},
|
|
53
|
+
f: F
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
57
|
+
}
|
|
58
|
+
var o,
|
|
59
|
+
a = true,
|
|
60
|
+
u = false;
|
|
61
|
+
return {
|
|
62
|
+
s: function () {
|
|
63
|
+
t = t.call(r);
|
|
64
|
+
},
|
|
65
|
+
n: function () {
|
|
66
|
+
var r = t.next();
|
|
67
|
+
return a = r.done, r;
|
|
68
|
+
},
|
|
69
|
+
e: function (r) {
|
|
70
|
+
u = true, o = r;
|
|
71
|
+
},
|
|
72
|
+
f: function () {
|
|
73
|
+
try {
|
|
74
|
+
a || null == t.return || t.return();
|
|
75
|
+
} finally {
|
|
76
|
+
if (u) throw o;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
28
81
|
function _defineProperty(e, r, t) {
|
|
29
82
|
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
30
83
|
value: t,
|
|
@@ -196,8 +249,16 @@ function _toPropertyKey(t) {
|
|
|
196
249
|
var i = _toPrimitive(t, "string");
|
|
197
250
|
return "symbol" == typeof i ? i : i + "";
|
|
198
251
|
}
|
|
252
|
+
function _unsupportedIterableToArray(r, a) {
|
|
253
|
+
if (r) {
|
|
254
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
255
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
256
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
199
259
|
|
|
200
260
|
exports._asyncToGenerator = _asyncToGenerator;
|
|
261
|
+
exports._createForOfIteratorHelper = _createForOfIteratorHelper;
|
|
201
262
|
exports._objectSpread2 = _objectSpread2;
|
|
202
263
|
exports._objectWithoutProperties = _objectWithoutProperties;
|
|
203
264
|
exports._regenerator = _regenerator;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var FormSubmitWrapper = require('../../FormSubmitWrapper-
|
|
4
|
-
require('../../_rollupPluginBabelHelpers-
|
|
3
|
+
var FormSubmitWrapper = require('../../FormSubmitWrapper-BaqE4w9q.js');
|
|
4
|
+
require('../../_rollupPluginBabelHelpers-B1r4NF8e.js');
|
|
5
5
|
require('react');
|
|
6
6
|
|
|
7
7
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var _rollupPluginBabelHelpers = require('../../_rollupPluginBabelHelpers-
|
|
3
|
+
var _rollupPluginBabelHelpers = require('../../_rollupPluginBabelHelpers-B1r4NF8e.js');
|
|
4
4
|
var React = require('react');
|
|
5
5
|
var isArray = require('../../isArray-DJguRq_2.js');
|
|
6
6
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var _rollupPluginBabelHelpers = require('../../_rollupPluginBabelHelpers-B1r4NF8e.js');
|
|
3
4
|
var React = require('react');
|
|
4
|
-
var FormSubmitWrapper = require('../../FormSubmitWrapper-
|
|
5
|
+
var FormSubmitWrapper = require('../../FormSubmitWrapper-BaqE4w9q.js');
|
|
5
6
|
var isArray = require('../../isArray-DJguRq_2.js');
|
|
6
7
|
require('@itcase/common');
|
|
7
8
|
require('msw');
|
|
8
|
-
require('
|
|
9
|
+
require('final-form');
|
|
9
10
|
|
|
10
11
|
/** Detect free variable `global` from Node.js. */
|
|
11
12
|
|
|
@@ -1123,13 +1124,27 @@ function isVitestEnvironment() {
|
|
|
1123
1124
|
return Boolean((_import$meta$env = undefined) === null || _import$meta$env === void 0 ? void 0 : _import$meta$env.VITEST);
|
|
1124
1125
|
}
|
|
1125
1126
|
|
|
1127
|
+
function getStoryArgs(storyContext) {
|
|
1128
|
+
var _storyContext$context, _storyContext$initial, _baseContext$args, _storyContext$args;
|
|
1129
|
+
var baseContext = (_storyContext$context = storyContext.context) !== null && _storyContext$context !== void 0 ? _storyContext$context : storyContext;
|
|
1130
|
+
return _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({}, (_storyContext$initial = storyContext.initialArgs) !== null && _storyContext$initial !== void 0 ? _storyContext$initial : {}), (_baseContext$args = baseContext.args) !== null && _baseContext$args !== void 0 ? _baseContext$args : {}), (_storyContext$args = storyContext.args) !== null && _storyContext$args !== void 0 ? _storyContext$args : {});
|
|
1131
|
+
}
|
|
1132
|
+
function enhanceStoryContext(storyContext) {
|
|
1133
|
+
var _storyContext$context2;
|
|
1134
|
+
var baseContext = (_storyContext$context2 = storyContext.context) !== null && _storyContext$context2 !== void 0 ? _storyContext$context2 : storyContext;
|
|
1135
|
+
var args = getStoryArgs(storyContext);
|
|
1136
|
+
return _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({}, baseContext), {}, {
|
|
1137
|
+
args: args
|
|
1138
|
+
});
|
|
1139
|
+
}
|
|
1126
1140
|
function withFormSubmitDecorator() {
|
|
1127
1141
|
var decorator = function decorator(Story, storyContext) {
|
|
1128
|
-
var _storyContext$context;
|
|
1129
1142
|
var parameters = storyContext.parameters;
|
|
1130
|
-
var context = (
|
|
1143
|
+
var context = enhanceStoryContext(storyContext);
|
|
1131
1144
|
if (isVitestEnvironment() || !hasFormParameters(parameters)) {
|
|
1132
|
-
return /*#__PURE__*/React.createElement(Story, context
|
|
1145
|
+
return /*#__PURE__*/React.createElement(Story, Object.assign({}, context, {
|
|
1146
|
+
parameters: parameters
|
|
1147
|
+
}));
|
|
1133
1148
|
}
|
|
1134
1149
|
return /*#__PURE__*/React.createElement(FormSubmitWrapper.FormSubmitWrapper, Object.assign({}, context, {
|
|
1135
1150
|
parameters: parameters
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var _rollupPluginBabelHelpers = require('../../_rollupPluginBabelHelpers-
|
|
3
|
+
var _rollupPluginBabelHelpers = require('../../_rollupPluginBabelHelpers-B1r4NF8e.js');
|
|
4
4
|
var React = require('react');
|
|
5
5
|
var Notification = require('@itcase/ui-web/components/Notification');
|
|
6
6
|
var context = require('@itcase/ui-core/context');
|
package/dist/cjs/decorators.js
CHANGED
|
@@ -8,11 +8,12 @@ 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-
|
|
11
|
+
require('../_rollupPluginBabelHelpers-B1r4NF8e.js');
|
|
12
12
|
require('../isArray-DJguRq_2.js');
|
|
13
|
-
require('../FormSubmitWrapper-
|
|
13
|
+
require('../FormSubmitWrapper-BaqE4w9q.js');
|
|
14
14
|
require('@itcase/common');
|
|
15
15
|
require('msw');
|
|
16
|
+
require('final-form');
|
|
16
17
|
require('@itcase/ui-web/components/Notification');
|
|
17
18
|
require('@itcase/ui-core/context');
|
|
18
19
|
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { a as _asyncToGenerator, b as _regenerator, c as _createForOfIteratorHelper, d as _objectSpread2 } from './_rollupPluginBabelHelpers-CEVa9ZMs.js';
|
|
2
|
+
import React, { useRef, useEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
var SUBMIT_POLL_MS = 50;
|
|
5
|
+
function getStoryPreviewDocument() {
|
|
6
|
+
var _document$getElementB, _previewIframe$conten;
|
|
7
|
+
var previewIframe = (_document$getElementB = document.getElementById('storybook-preview-iframe')) !== null && _document$getElementB !== void 0 ? _document$getElementB : document.querySelector('iframe[data-is-storybook="true"]');
|
|
8
|
+
return (_previewIframe$conten = previewIframe === null || previewIframe === void 0 ? void 0 : previewIframe.contentDocument) !== null && _previewIframe$conten !== void 0 ? _previewIframe$conten : null;
|
|
9
|
+
}
|
|
10
|
+
function getMountRoot() {
|
|
11
|
+
var _ref2, _document$getElementB2;
|
|
12
|
+
var previewDocument = getStoryPreviewDocument();
|
|
13
|
+
if (previewDocument) {
|
|
14
|
+
var _ref, _previewDocument$getE;
|
|
15
|
+
return (_ref = (_previewDocument$getE = previewDocument.getElementById('storybook-root')) !== null && _previewDocument$getE !== void 0 ? _previewDocument$getE : previewDocument.getElementById('root')) !== null && _ref !== void 0 ? _ref : previewDocument.body;
|
|
16
|
+
}
|
|
17
|
+
return (_ref2 = (_document$getElementB2 = document.getElementById('storybook-root')) !== null && _document$getElementB2 !== void 0 ? _document$getElementB2 : document.getElementById('root')) !== null && _ref2 !== void 0 ? _ref2 : document.body;
|
|
18
|
+
}
|
|
19
|
+
function canSubmitFormApi(form) {
|
|
20
|
+
return typeof (form === null || form === void 0 ? void 0 : form.submit) === 'function' && typeof form.getRegisteredFields === 'function' && form.getRegisteredFields().length > 0;
|
|
21
|
+
}
|
|
22
|
+
function findSaveDraftButton(root) {
|
|
23
|
+
if (!root) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
var saveDraft = root.querySelector('[data-testid$="SaveDraftButton"]');
|
|
27
|
+
if (!saveDraft) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return saveDraft.tagName === 'BUTTON' ? saveDraft : saveDraft.querySelector('button');
|
|
31
|
+
}
|
|
32
|
+
function findSubmitButton(root) {
|
|
33
|
+
var _form$querySelector;
|
|
34
|
+
if (!root) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
var byType = root.querySelector('button[type="submit"]');
|
|
38
|
+
if (byType) {
|
|
39
|
+
return byType;
|
|
40
|
+
}
|
|
41
|
+
var form = root.querySelector('form[data-testid], form');
|
|
42
|
+
if (!form) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
return (_form$querySelector = form.querySelector('.form__button .form__button-item, .form__button-item')) !== null && _form$querySelector !== void 0 ? _form$querySelector : null;
|
|
46
|
+
}
|
|
47
|
+
function touchFieldsBeforeSubmit(form) {
|
|
48
|
+
if (!canSubmitFormApi(form)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
var _iterator = _createForOfIteratorHelper(form.getRegisteredFields()),
|
|
52
|
+
_step;
|
|
53
|
+
try {
|
|
54
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
55
|
+
var _form$getFieldState;
|
|
56
|
+
var fieldName = _step.value;
|
|
57
|
+
if (!((_form$getFieldState = form.getFieldState(fieldName)) !== null && _form$getFieldState !== void 0 && _form$getFieldState.touched)) {
|
|
58
|
+
form.blur(fieldName);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
} catch (err) {
|
|
62
|
+
_iterator.e(err);
|
|
63
|
+
} finally {
|
|
64
|
+
_iterator.f();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function triggerFormSubmit(_ref3) {
|
|
68
|
+
var form = _ref3.form,
|
|
69
|
+
root = _ref3.root,
|
|
70
|
+
submitButton = _ref3.submitButton;
|
|
71
|
+
var saveDraftButton = findSaveDraftButton(root !== null && root !== void 0 ? root : getMountRoot());
|
|
72
|
+
if (saveDraftButton) {
|
|
73
|
+
saveDraftButton.click();
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (canSubmitFormApi(form)) {
|
|
77
|
+
touchFieldsBeforeSubmit(form);
|
|
78
|
+
form.submit();
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if ((submitButton === null || submitButton === void 0 ? void 0 : submitButton.type) === 'submit') {
|
|
82
|
+
submitButton.click();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function autoSubmitForm(_x, _x2) {
|
|
86
|
+
return _autoSubmitForm.apply(this, arguments);
|
|
87
|
+
}
|
|
88
|
+
function _autoSubmitForm() {
|
|
89
|
+
_autoSubmitForm = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(formRef, signal) {
|
|
90
|
+
var root, form, submitButton, saveDraftButton, canSubmitViaFormApi, canClickNativeSubmit, canClickSaveDraft;
|
|
91
|
+
return _regenerator().w(function (_context) {
|
|
92
|
+
while (1) switch (_context.n) {
|
|
93
|
+
case 0:
|
|
94
|
+
if (!formRef.__itcaseDidAutoSubmit) {
|
|
95
|
+
_context.n = 1;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
return _context.a(2);
|
|
99
|
+
case 1:
|
|
100
|
+
if (signal.aborted) {
|
|
101
|
+
_context.n = 6;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
root = getMountRoot();
|
|
105
|
+
form = formRef.current;
|
|
106
|
+
submitButton = findSubmitButton(root);
|
|
107
|
+
saveDraftButton = findSaveDraftButton(root);
|
|
108
|
+
canSubmitViaFormApi = canSubmitFormApi(form);
|
|
109
|
+
canClickNativeSubmit = (submitButton === null || submitButton === void 0 ? void 0 : submitButton.type) === 'submit';
|
|
110
|
+
canClickSaveDraft = Boolean(saveDraftButton); // primaryButtonHtmlType="button": ждём final-form API или кнопку черновика в DOM
|
|
111
|
+
if (!(!canSubmitViaFormApi && !canClickNativeSubmit && !canClickSaveDraft)) {
|
|
112
|
+
_context.n = 3;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
_context.n = 2;
|
|
116
|
+
return new Promise(function (resolve) {
|
|
117
|
+
setTimeout(resolve, SUBMIT_POLL_MS);
|
|
118
|
+
});
|
|
119
|
+
case 2:
|
|
120
|
+
return _context.a(3, 1);
|
|
121
|
+
case 3:
|
|
122
|
+
formRef.__itcaseDidAutoSubmit = true;
|
|
123
|
+
_context.n = 4;
|
|
124
|
+
return new Promise(function (resolve) {
|
|
125
|
+
requestAnimationFrame(function () {
|
|
126
|
+
requestAnimationFrame(resolve);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
case 4:
|
|
130
|
+
if (!signal.aborted) {
|
|
131
|
+
_context.n = 5;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
return _context.a(2);
|
|
135
|
+
case 5:
|
|
136
|
+
triggerFormSubmit({
|
|
137
|
+
form: formRef.current,
|
|
138
|
+
root: root,
|
|
139
|
+
submitButton: submitButton
|
|
140
|
+
});
|
|
141
|
+
return _context.a(2);
|
|
142
|
+
case 6:
|
|
143
|
+
return _context.a(2);
|
|
144
|
+
}
|
|
145
|
+
}, _callee);
|
|
146
|
+
}));
|
|
147
|
+
return _autoSubmitForm.apply(this, arguments);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function wrapRender(component, render, formRef) {
|
|
151
|
+
var defaultArgs = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
152
|
+
if (typeof render !== 'function') {
|
|
153
|
+
return render;
|
|
154
|
+
}
|
|
155
|
+
return function renderWithRef(storyArgs) {
|
|
156
|
+
var args = _objectSpread2(_objectSpread2({}, defaultArgs), storyArgs !== null && storyArgs !== void 0 ? storyArgs : {});
|
|
157
|
+
delete args.ref;
|
|
158
|
+
delete args.errors;
|
|
159
|
+
if (!args.onSubmit && defaultArgs.onSubmit) {
|
|
160
|
+
args.onSubmit = defaultArgs.onSubmit;
|
|
161
|
+
}
|
|
162
|
+
var rendered = render(args);
|
|
163
|
+
if (/*#__PURE__*/React.isValidElement(rendered)) {
|
|
164
|
+
return /*#__PURE__*/React.cloneElement(rendered, _objectSpread2(_objectSpread2(_objectSpread2({}, rendered.props), args), {}, {
|
|
165
|
+
ref: formRef
|
|
166
|
+
}));
|
|
167
|
+
}
|
|
168
|
+
if (component) {
|
|
169
|
+
return /*#__PURE__*/React.createElement(component, _objectSpread2({
|
|
170
|
+
ref: formRef
|
|
171
|
+
}, args));
|
|
172
|
+
}
|
|
173
|
+
return rendered;
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function withFormRef(children, formRef, bindings) {
|
|
177
|
+
var _ref, _ref2, _children$props, _ref3, _children$props2, _ref4, _children$props3;
|
|
178
|
+
var component = bindings.component,
|
|
179
|
+
args = bindings.args,
|
|
180
|
+
storyRender = bindings.render,
|
|
181
|
+
allArgs = bindings.allArgs,
|
|
182
|
+
context = bindings.context;
|
|
183
|
+
var storyArgs = (_ref = (_ref2 = args !== null && args !== void 0 ? args : context === null || context === void 0 ? void 0 : context.args) !== null && _ref2 !== void 0 ? _ref2 : children === null || children === void 0 || (_children$props = children.props) === null || _children$props === void 0 ? void 0 : _children$props.args) !== null && _ref !== void 0 ? _ref : {};
|
|
184
|
+
var storyComponent = (_ref3 = component !== null && component !== void 0 ? component : context === null || context === void 0 ? void 0 : context.component) !== null && _ref3 !== void 0 ? _ref3 : children === null || children === void 0 || (_children$props2 = children.props) === null || _children$props2 === void 0 ? void 0 : _children$props2.component;
|
|
185
|
+
var storyRenderFn = (_ref4 = storyRender !== null && storyRender !== void 0 ? storyRender : context === null || context === void 0 ? void 0 : context.render) !== null && _ref4 !== void 0 ? _ref4 : children === null || children === void 0 || (_children$props3 = children.props) === null || _children$props3 === void 0 ? void 0 : _children$props3.render;
|
|
186
|
+
var boundRender = wrapRender(storyComponent, storyRenderFn, formRef, storyArgs);
|
|
187
|
+
var addRef = function addRef(value) {
|
|
188
|
+
return value ? _objectSpread2(_objectSpread2({}, value), {}, {
|
|
189
|
+
ref: formRef
|
|
190
|
+
}) : value;
|
|
191
|
+
};
|
|
192
|
+
return /*#__PURE__*/React.cloneElement(children, {
|
|
193
|
+
component: storyComponent,
|
|
194
|
+
args: addRef(storyArgs),
|
|
195
|
+
render: boundRender,
|
|
196
|
+
allArgs: addRef(allArgs),
|
|
197
|
+
context: context ? _objectSpread2(_objectSpread2({}, context), {}, {
|
|
198
|
+
component: storyComponent,
|
|
199
|
+
args: addRef(context.args),
|
|
200
|
+
render: boundRender,
|
|
201
|
+
allArgs: addRef(context.allArgs)
|
|
202
|
+
}) : context
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Авто-submit для интерактивного Storybook (Require / Validation / ServerError).
|
|
208
|
+
* При primaryButtonHtmlType="button" — formRef.current.submit() (final-form API),
|
|
209
|
+
* при type="submit" — click по кнопке. В Vitest submit в play.
|
|
210
|
+
*/
|
|
211
|
+
function FormSubmitWrapper(props) {
|
|
212
|
+
var _ref5, _ref6, _children$props4;
|
|
213
|
+
var formRef = useRef(null);
|
|
214
|
+
var component = props.component,
|
|
215
|
+
args = props.args,
|
|
216
|
+
render = props.render,
|
|
217
|
+
allArgs = props.allArgs,
|
|
218
|
+
context = props.context,
|
|
219
|
+
_props$submit = props.submit,
|
|
220
|
+
submit = _props$submit === void 0 ? true : _props$submit,
|
|
221
|
+
children = props.children;
|
|
222
|
+
var storyArgs = (_ref5 = (_ref6 = args !== null && args !== void 0 ? args : context === null || context === void 0 ? void 0 : context.args) !== null && _ref6 !== void 0 ? _ref6 : children === null || children === void 0 || (_children$props4 = children.props) === null || _children$props4 === void 0 ? void 0 : _children$props4.args) !== null && _ref5 !== void 0 ? _ref5 : {};
|
|
223
|
+
useEffect(function () {
|
|
224
|
+
if (!submit) {
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
delete formRef.__itcaseDidAutoSubmit;
|
|
228
|
+
var abortController = new AbortController();
|
|
229
|
+
autoSubmitForm(formRef, abortController.signal);
|
|
230
|
+
return function () {
|
|
231
|
+
abortController.abort();
|
|
232
|
+
delete formRef.__itcaseDidAutoSubmit;
|
|
233
|
+
};
|
|
234
|
+
}, [submit, storyArgs.errors]);
|
|
235
|
+
|
|
236
|
+
// eslint-disable-next-line react-hooks/refs -- ref уходит в cloneElement внутри bound render
|
|
237
|
+
return withFormRef(children, formRef, {
|
|
238
|
+
component: component,
|
|
239
|
+
args: storyArgs,
|
|
240
|
+
render: render,
|
|
241
|
+
allArgs: allArgs,
|
|
242
|
+
context: context
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export { FormSubmitWrapper as F };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { F as FormSubmitWrapper } from './FormSubmitWrapper-
|
|
2
|
-
import './_rollupPluginBabelHelpers-
|
|
1
|
+
export { F as FormSubmitWrapper } from './FormSubmitWrapper-DoGZRTm5.js';
|
|
2
|
+
import './_rollupPluginBabelHelpers-CEVa9ZMs.js';
|
|
3
3
|
import 'react';
|