@itcase/storybook-config 1.2.79 → 1.2.81
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-_VeLgVir.js → FormSubmitWrapper-Bv5qs18h.js} +10 -3
- package/dist/cjs/components/EmailTemplatePreview.js +1 -1
- package/dist/cjs/components/FormSubmitWrapper.js +1 -1
- package/dist/cjs/decorators/withFormSubmitDecorator.js +1 -2
- package/dist/cjs/decorators/withNextDecorator.js +1 -1
- package/dist/cjs/decorators/withUiDecorator.js +1 -1
- package/dist/cjs/decorators.js +2 -3
- package/dist/components/EmailTemplatePreview/index.d.ts +2 -0
- package/dist/components/EmailTemplatePreview/index.js +38 -0
- package/dist/components/EmailTemplatePreview.js +1 -1
- package/dist/components/FormSubmitWrapper/FormSubmitWrapper.d.ts +16 -0
- package/dist/components/FormSubmitWrapper/FormSubmitWrapper.js +88 -0
- package/dist/components/FormSubmitWrapper/autoSubmitForm.d.ts +2 -0
- package/dist/components/FormSubmitWrapper/autoSubmitForm.js +106 -0
- package/dist/components/FormSubmitWrapper/index.d.ts +2 -0
- package/dist/components/FormSubmitWrapper/index.js +2 -0
- package/dist/components/{FormSubmitWrapper-B2tMQZu2.js → FormSubmitWrapper-EwNkaMht.js} +10 -3
- package/dist/components/FormSubmitWrapper.js +1 -1
- package/dist/config/addons/addonThemes.d.ts +15 -0
- package/dist/config/addons/addonThemes.js +14 -15
- package/dist/config/addons/addonsNextJs.d.ts +2 -0
- package/dist/config/addons/addonsNextJs.js +8 -9
- package/dist/config/addons/addonsReactNative.d.ts +2 -0
- package/dist/config/addons/addonsReactNative.js +6 -7
- package/dist/config/addons/addonsReactNativeWeb.d.ts +2 -0
- package/dist/config/addons/addonsReactNativeWeb.js +2 -3
- package/dist/config/addons/addonsVite.d.ts +2 -0
- package/dist/config/addons/addonsVite.js +8 -9
- package/dist/config/addons/addonsWebpack.d.ts +18 -0
- package/dist/config/addons/addonsWebpack.js +26 -27
- package/dist/config/appearance/appearance.d.ts +1 -0
- package/dist/config/appearance/appearance.js +1 -1
- package/dist/config/backgrounds/backgrounds.d.ts +23 -0
- package/dist/config/backgrounds/backgrounds.js +22 -24
- package/dist/config/code/code.d.ts +8 -0
- package/dist/config/code/code.js +18 -22
- package/dist/config/config/mainConfigNextJsVite.d.ts +10 -0
- package/dist/config/config/mainConfigNextJsVite.js +35 -38
- package/dist/config/config/mainConfigReactNative.d.ts +9 -0
- package/dist/config/config/mainConfigReactNative.js +21 -23
- package/dist/config/config/mainConfigReactNativeWeb.d.ts +23 -0
- package/dist/config/config/mainConfigReactNativeWeb.js +42 -46
- package/dist/config/config/mainConfigVite.d.ts +9 -0
- package/dist/config/config/mainConfigVite.js +75 -80
- package/dist/config/config/mainConfigWebpack.d.ts +9 -0
- package/dist/config/config/mainConfigWebpack.js +39 -64
- package/dist/config/framework/frameworkNextJs.d.ts +4 -0
- package/dist/config/framework/frameworkNextJs.js +3 -4
- package/dist/config/framework/frameworkNextJsVite.d.ts +4 -0
- package/dist/config/framework/frameworkNextJsVite.js +3 -4
- package/dist/config/framework/frameworkReactNative.d.ts +4 -0
- package/dist/config/framework/frameworkReactNative.js +3 -4
- package/dist/config/framework/frameworkReactNativeWeb.d.ts +4 -0
- package/dist/config/framework/frameworkReactNativeWeb.js +3 -4
- package/dist/config/framework/frameworkVite.d.ts +4 -0
- package/dist/config/framework/frameworkVite.js +3 -4
- package/dist/config/framework/frameworkWebpack.d.ts +11 -0
- package/dist/config/framework/frameworkWebpack.js +9 -10
- package/dist/config/main/index.d.ts +26 -0
- package/dist/config/main/index.js +26 -53
- package/dist/config/msw/index.d.ts +2 -0
- package/dist/config/msw/index.js +2 -7
- package/dist/config/msw/mswHandlers.d.ts +5 -0
- package/dist/config/msw/mswHandlers.js +20 -24
- package/dist/config/ondevice/ondeviceBackgrounds.d.ts +8 -0
- package/dist/config/ondevice/ondeviceBackgrounds.js +8 -9
- package/dist/config/preview/index.d.ts +6 -0
- package/dist/config/preview/index.js +6 -13
- package/dist/config/refs/refs.d.ts +13 -0
- package/dist/config/refs/refs.js +12 -13
- package/dist/config/sourceLink/sourceLink.d.ts +35 -0
- package/dist/config/sourceLink/sourceLink.js +32 -36
- package/dist/config/static/staticDirsNextJs.d.ts +5 -0
- package/dist/config/static/staticDirsNextJs.js +5 -6
- package/dist/config/static/staticDirsReactNative.d.ts +2 -0
- package/dist/config/static/staticDirsReactNative.js +2 -3
- package/dist/config/static/staticDirsReactNativeWeb.d.ts +2 -0
- package/dist/config/static/staticDirsReactNativeWeb.js +2 -3
- package/dist/config/static/staticDirsVite.d.ts +5 -0
- package/dist/config/static/staticDirsVite.js +2 -3
- package/dist/config/static/staticDirsWebpack.d.ts +5 -0
- package/dist/config/static/staticDirsWebpack.js +2 -3
- package/dist/config/status/status.d.ts +21 -0
- package/dist/config/status/status.js +23 -24
- package/dist/config/users/authorization.d.ts +22 -0
- package/dist/config/users/authorization.js +6 -8
- package/dist/config/users/users.d.ts +18 -0
- package/dist/config/users/users.js +19 -21
- package/dist/config/viewport/viewport.d.ts +264 -0
- package/dist/config/viewport/viewport.js +23 -25
- package/dist/config/vite/getMediaProxyServerConfig.d.ts +13 -0
- package/dist/config/vite/getMediaProxyServerConfig.js +14 -16
- package/dist/decorators/index.d.ts +8 -0
- package/dist/decorators/index.js +8 -0
- package/dist/decorators/withClearStoresDecorator.d.ts +4 -0
- package/dist/decorators/withExtraProviders.d.ts +2 -0
- package/dist/decorators/withFigmaSourceLink.d.ts +5 -0
- package/dist/decorators/withFormSubmitDecorator.d.ts +2 -0
- package/dist/decorators/withFormSubmitDecorator.js +1 -2
- package/dist/decorators/withLayoutDecorator.d.ts +4 -0
- package/dist/decorators/withNextDecorator.d.ts +9 -0
- package/dist/decorators/withNextDecorator.js +1 -1
- package/dist/decorators/withUiDecorator.d.ts +5 -0
- package/dist/decorators/withUiDecorator.js +1 -1
- package/dist/decorators.js +2 -3
- package/dist/utils/getFigmaSourceLink.d.ts +2 -0
- package/dist/utils/getFigmaSourceLink.js +13 -14
- package/dist/utils/getStoryInfoBlocks.d.ts +2 -0
- package/dist/utils/getStoryInfoBlocks.js +45 -55
- package/dist/utils/handleMSWParameters.d.ts +8 -0
- package/dist/utils/handleMSWParameters.js +18 -27
- package/dist/utils/hasFormParameters.d.ts +2 -0
- package/dist/utils/hasFormParameters.js +6 -9
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.js +9 -17
- package/dist/utils/isVitestEnvironment.d.ts +2 -0
- package/dist/utils/isVitestEnvironment.js +2 -3
- package/dist/utils/storybookServerErrorOnSubmit.d.ts +2 -0
- package/dist/utils/storybookServerErrorOnSubmit.js +12 -19
- package/package.json +50 -43
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
var React = require('react');
|
|
4
4
|
|
|
5
|
+
function isVitestEnvironment() {
|
|
6
|
+
return Boolean(undefined?.VITEST);
|
|
7
|
+
}
|
|
8
|
+
|
|
5
9
|
const SUBMIT_POLL_MS = 50;
|
|
6
10
|
function getStoryPreviewDocument() {
|
|
7
11
|
const previewIframe = document.getElementById('storybook-preview-iframe') ?? document.querySelector('iframe[data-is-storybook="true"]');
|
|
@@ -173,7 +177,9 @@ function withFormRef(children, formRef, bindings) {
|
|
|
173
177
|
/**
|
|
174
178
|
* Авто-submit для интерактивного Storybook (Require / Validation / ServerError).
|
|
175
179
|
* При primaryButtonHtmlType="button" — formRef.current.submit() (final-form API),
|
|
176
|
-
* при type="submit" — click по кнопке. В Vitest submit в play
|
|
180
|
+
* при type="submit" — click по кнопке. В Vitest submit в play — auto-submit не
|
|
181
|
+
* запускаем, иначе второй клик из play ставит modifiedSinceLastSubmit и прячет
|
|
182
|
+
* non-field notification.
|
|
177
183
|
*/
|
|
178
184
|
function FormSubmitWrapper(props) {
|
|
179
185
|
const formRef = React.useRef(null);
|
|
@@ -187,8 +193,9 @@ function FormSubmitWrapper(props) {
|
|
|
187
193
|
children
|
|
188
194
|
} = props;
|
|
189
195
|
const storyArgs = args ?? context?.args ?? children?.props?.args ?? {};
|
|
196
|
+
const shouldAutoSubmit = submit && !isVitestEnvironment();
|
|
190
197
|
React.useEffect(() => {
|
|
191
|
-
if (!
|
|
198
|
+
if (!shouldAutoSubmit) {
|
|
192
199
|
return undefined;
|
|
193
200
|
}
|
|
194
201
|
delete formRef.__itcaseDidAutoSubmit;
|
|
@@ -198,7 +205,7 @@ function FormSubmitWrapper(props) {
|
|
|
198
205
|
abortController.abort();
|
|
199
206
|
delete formRef.__itcaseDidAutoSubmit;
|
|
200
207
|
};
|
|
201
|
-
}, [
|
|
208
|
+
}, [shouldAutoSubmit, storyArgs.errors]);
|
|
202
209
|
|
|
203
210
|
// eslint-disable-next-line react-hooks/refs -- ref уходит в cloneElement внутри bound render
|
|
204
211
|
return withFormRef(children, formRef, {
|
|
@@ -11,12 +11,12 @@ function EmailTemplatePreview(props) {
|
|
|
11
11
|
const style = {
|
|
12
12
|
width: '100%',
|
|
13
13
|
height: '100%',
|
|
14
|
-
border: '0',
|
|
15
14
|
position: 'absolute',
|
|
16
15
|
top: '0',
|
|
17
16
|
right: '0',
|
|
18
17
|
bottom: '0',
|
|
19
18
|
left: '0',
|
|
19
|
+
border: '0',
|
|
20
20
|
overflow: 'hidden',
|
|
21
21
|
overflowX: 'hidden',
|
|
22
22
|
overflowY: 'hidden'
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
require('react');
|
|
4
|
-
var FormSubmitWrapper = require('../../FormSubmitWrapper-
|
|
4
|
+
var FormSubmitWrapper = require('../../FormSubmitWrapper-Bv5qs18h.js');
|
|
5
5
|
var isArray = require('../../isArray-DJguRq_2.js');
|
|
6
6
|
require('@itcase/common');
|
|
7
7
|
require('msw');
|
|
8
|
-
require('final-form');
|
|
9
8
|
var jsxRuntime = require('react/jsx-runtime');
|
|
10
9
|
|
|
11
10
|
/** Detect free variable `global` from Node.js. */
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
require('react');
|
|
4
|
-
var Notification = require('@itcase/ui-web/components/Notification');
|
|
5
4
|
var context = require('@itcase/ui-core/context');
|
|
5
|
+
var Notification = require('@itcase/ui-web/components/Notification');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
7
|
|
|
8
8
|
function withNextDecoratorFactory({
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
require('react');
|
|
4
|
-
var Notification = require('@itcase/ui-web/components/Notification');
|
|
5
4
|
var context = require('@itcase/ui-core/context');
|
|
5
|
+
var Notification = require('@itcase/ui-web/components/Notification');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
7
|
|
|
8
8
|
function withUiDecorator(Story, {
|
package/dist/cjs/decorators.js
CHANGED
|
@@ -10,12 +10,11 @@ var withUiDecorator = require('./decorators/withUiDecorator.js');
|
|
|
10
10
|
require('react');
|
|
11
11
|
require('react/jsx-runtime');
|
|
12
12
|
require('../isArray-DJguRq_2.js');
|
|
13
|
-
require('../FormSubmitWrapper-
|
|
13
|
+
require('../FormSubmitWrapper-Bv5qs18h.js');
|
|
14
14
|
require('@itcase/common');
|
|
15
15
|
require('msw');
|
|
16
|
-
require('final-form');
|
|
17
|
-
require('@itcase/ui-web/components/Notification');
|
|
18
16
|
require('@itcase/ui-core/context');
|
|
17
|
+
require('@itcase/ui-web/components/Notification');
|
|
19
18
|
|
|
20
19
|
|
|
21
20
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
let BACKEND_URL = process.env.EMAIL_URL;
|
|
4
|
+
if (process.env.NODE_ENV === 'production' && process.env.REST_BASE_URL) {
|
|
5
|
+
BACKEND_URL = `${process.env.REST_BASE_URL}/storybook`;
|
|
6
|
+
}
|
|
7
|
+
function EmailTemplatePreview(props) {
|
|
8
|
+
const style = {
|
|
9
|
+
width: '100%',
|
|
10
|
+
height: '100%',
|
|
11
|
+
position: 'absolute',
|
|
12
|
+
top: '0',
|
|
13
|
+
right: '0',
|
|
14
|
+
bottom: '0',
|
|
15
|
+
left: '0',
|
|
16
|
+
border: '0',
|
|
17
|
+
overflow: 'hidden',
|
|
18
|
+
overflowX: 'hidden',
|
|
19
|
+
overflowY: 'hidden',
|
|
20
|
+
};
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
const emailPreviewIframe = document.getElementById('emailPreview');
|
|
23
|
+
const loaded = () => {
|
|
24
|
+
const email = emailPreviewIframe.getElementsByClassName('email-body').length;
|
|
25
|
+
if (!email &&
|
|
26
|
+
process.env.EMAIL_URL &&
|
|
27
|
+
process.env.EMAIL_URL.includes('http://')) {
|
|
28
|
+
alert('Need to run the backend server to display email templates, use: python manage.py runserver');
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
emailPreviewIframe?.addEventListener('load', loaded, true);
|
|
32
|
+
});
|
|
33
|
+
if (!BACKEND_URL) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
return (_jsx("iframe", { id: "emailPreview", width: "100%", height: "100%", src: `${BACKEND_URL}${props.url}`, style: style }));
|
|
37
|
+
}
|
|
38
|
+
export { EmailTemplatePreview };
|
|
@@ -9,12 +9,12 @@ function EmailTemplatePreview(props) {
|
|
|
9
9
|
const style = {
|
|
10
10
|
width: '100%',
|
|
11
11
|
height: '100%',
|
|
12
|
-
border: '0',
|
|
13
12
|
position: 'absolute',
|
|
14
13
|
top: '0',
|
|
15
14
|
right: '0',
|
|
16
15
|
bottom: '0',
|
|
17
16
|
left: '0',
|
|
17
|
+
border: '0',
|
|
18
18
|
overflow: 'hidden',
|
|
19
19
|
overflowX: 'hidden',
|
|
20
20
|
overflowY: 'hidden'
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Авто-submit для интерактивного Storybook (Require / Validation / ServerError).
|
|
4
|
+
* При primaryButtonHtmlType="button" — formRef.current.submit() (final-form API),
|
|
5
|
+
* при type="submit" — click по кнопке. В Vitest submit в play — auto-submit не
|
|
6
|
+
* запускаем, иначе второй клик из play ставит modifiedSinceLastSubmit и прячет
|
|
7
|
+
* non-field notification.
|
|
8
|
+
*/
|
|
9
|
+
declare function FormSubmitWrapper(props: any): React.FunctionComponentElement<{
|
|
10
|
+
component: any;
|
|
11
|
+
args: any;
|
|
12
|
+
render: any;
|
|
13
|
+
allArgs: any;
|
|
14
|
+
context: any;
|
|
15
|
+
}>;
|
|
16
|
+
export { FormSubmitWrapper };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
import { isVitestEnvironment } from '../../utils/isVitestEnvironment';
|
|
3
|
+
import { autoSubmitForm } from './autoSubmitForm';
|
|
4
|
+
function wrapRender(component, render, formRef, defaultArgs = {}) {
|
|
5
|
+
if (typeof render !== 'function') {
|
|
6
|
+
return render;
|
|
7
|
+
}
|
|
8
|
+
return function renderWithRef(storyArgs) {
|
|
9
|
+
const args = { ...defaultArgs, ...(storyArgs ?? {}) };
|
|
10
|
+
delete args.ref;
|
|
11
|
+
delete args.errors;
|
|
12
|
+
if (!args.onSubmit && defaultArgs.onSubmit) {
|
|
13
|
+
args.onSubmit = defaultArgs.onSubmit;
|
|
14
|
+
}
|
|
15
|
+
const rendered = render(args);
|
|
16
|
+
if (React.isValidElement(rendered)) {
|
|
17
|
+
return React.cloneElement(rendered, {
|
|
18
|
+
...rendered.props,
|
|
19
|
+
...args,
|
|
20
|
+
ref: formRef,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (component) {
|
|
24
|
+
return React.createElement(component, {
|
|
25
|
+
ref: formRef,
|
|
26
|
+
...args,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return rendered;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function withFormRef(children, formRef, bindings) {
|
|
33
|
+
const { component, args, render: storyRender, allArgs, context } = bindings;
|
|
34
|
+
const storyArgs = args ?? context?.args ?? children?.props?.args ?? {};
|
|
35
|
+
const storyComponent = component ?? context?.component ?? children?.props?.component;
|
|
36
|
+
const storyRenderFn = storyRender ?? context?.render ?? children?.props?.render;
|
|
37
|
+
const boundRender = wrapRender(storyComponent, storyRenderFn, formRef, storyArgs);
|
|
38
|
+
const addRef = (value) => (value ? { ...value, ref: formRef } : value);
|
|
39
|
+
return React.cloneElement(children, {
|
|
40
|
+
component: storyComponent,
|
|
41
|
+
args: addRef(storyArgs),
|
|
42
|
+
render: boundRender,
|
|
43
|
+
allArgs: addRef(allArgs),
|
|
44
|
+
context: context
|
|
45
|
+
? {
|
|
46
|
+
...context,
|
|
47
|
+
component: storyComponent,
|
|
48
|
+
args: addRef(context.args),
|
|
49
|
+
render: boundRender,
|
|
50
|
+
allArgs: addRef(context.allArgs),
|
|
51
|
+
}
|
|
52
|
+
: context,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Авто-submit для интерактивного Storybook (Require / Validation / ServerError).
|
|
57
|
+
* При primaryButtonHtmlType="button" — formRef.current.submit() (final-form API),
|
|
58
|
+
* при type="submit" — click по кнопке. В Vitest submit в play — auto-submit не
|
|
59
|
+
* запускаем, иначе второй клик из play ставит modifiedSinceLastSubmit и прячет
|
|
60
|
+
* non-field notification.
|
|
61
|
+
*/
|
|
62
|
+
function FormSubmitWrapper(props) {
|
|
63
|
+
const formRef = useRef(null);
|
|
64
|
+
const { component, args, render, allArgs, context, submit = true, children, } = props;
|
|
65
|
+
const storyArgs = args ?? context?.args ?? children?.props?.args ?? {};
|
|
66
|
+
const shouldAutoSubmit = submit && !isVitestEnvironment();
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (!shouldAutoSubmit) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
delete formRef.__itcaseDidAutoSubmit;
|
|
72
|
+
const abortController = new AbortController();
|
|
73
|
+
autoSubmitForm(formRef, abortController.signal);
|
|
74
|
+
return () => {
|
|
75
|
+
abortController.abort();
|
|
76
|
+
delete formRef.__itcaseDidAutoSubmit;
|
|
77
|
+
};
|
|
78
|
+
}, [shouldAutoSubmit, storyArgs.errors]);
|
|
79
|
+
// eslint-disable-next-line react-hooks/refs -- ref уходит в cloneElement внутри bound render
|
|
80
|
+
return withFormRef(children, formRef, {
|
|
81
|
+
component,
|
|
82
|
+
args: storyArgs,
|
|
83
|
+
render,
|
|
84
|
+
allArgs,
|
|
85
|
+
context,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
export { FormSubmitWrapper };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
const SUBMIT_POLL_MS = 50;
|
|
2
|
+
function getStoryPreviewDocument() {
|
|
3
|
+
const previewIframe = (document.getElementById('storybook-preview-iframe') ??
|
|
4
|
+
document.querySelector('iframe[data-is-storybook="true"]'));
|
|
5
|
+
return previewIframe?.contentDocument ?? null;
|
|
6
|
+
}
|
|
7
|
+
function getMountRoot() {
|
|
8
|
+
const previewDocument = getStoryPreviewDocument();
|
|
9
|
+
if (previewDocument) {
|
|
10
|
+
return (previewDocument.getElementById('storybook-root') ??
|
|
11
|
+
previewDocument.getElementById('root') ??
|
|
12
|
+
previewDocument.body);
|
|
13
|
+
}
|
|
14
|
+
return (document.getElementById('storybook-root') ??
|
|
15
|
+
document.getElementById('root') ??
|
|
16
|
+
document.body);
|
|
17
|
+
}
|
|
18
|
+
function canSubmitFormApi(form) {
|
|
19
|
+
return (typeof form?.submit === 'function' &&
|
|
20
|
+
typeof form.getRegisteredFields === 'function' &&
|
|
21
|
+
form.getRegisteredFields().length > 0);
|
|
22
|
+
}
|
|
23
|
+
function findSaveDraftButton(root) {
|
|
24
|
+
if (!root) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const saveDraft = root.querySelector('[data-testid$="SaveDraftButton"]');
|
|
28
|
+
if (!saveDraft) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
return saveDraft.tagName === 'BUTTON'
|
|
32
|
+
? saveDraft
|
|
33
|
+
: saveDraft.querySelector('button');
|
|
34
|
+
}
|
|
35
|
+
function findSubmitButton(root) {
|
|
36
|
+
if (!root) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const byType = root.querySelector('button[type="submit"]');
|
|
40
|
+
if (byType) {
|
|
41
|
+
return byType;
|
|
42
|
+
}
|
|
43
|
+
const form = root.querySelector('form[data-testid], form');
|
|
44
|
+
if (!form) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return (form.querySelector('.form__button .form__button-item, .form__button-item') ?? null);
|
|
48
|
+
}
|
|
49
|
+
function touchFieldsBeforeSubmit(form) {
|
|
50
|
+
if (!canSubmitFormApi(form)) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
for (const fieldName of form.getRegisteredFields()) {
|
|
54
|
+
if (!form.getFieldState(fieldName)?.touched) {
|
|
55
|
+
form.blur(fieldName);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function triggerFormSubmit({ form, root, submitButton }) {
|
|
60
|
+
const saveDraftButton = findSaveDraftButton(root ?? getMountRoot());
|
|
61
|
+
if (saveDraftButton) {
|
|
62
|
+
saveDraftButton.click();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (canSubmitFormApi(form)) {
|
|
66
|
+
touchFieldsBeforeSubmit(form);
|
|
67
|
+
form.submit();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (submitButton?.type === 'submit') {
|
|
71
|
+
submitButton.click();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async function autoSubmitForm(formRef, signal) {
|
|
75
|
+
if (formRef.__itcaseDidAutoSubmit) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
while (!signal.aborted) {
|
|
79
|
+
const root = getMountRoot();
|
|
80
|
+
const form = formRef.current;
|
|
81
|
+
const submitButton = findSubmitButton(root);
|
|
82
|
+
const saveDraftButton = findSaveDraftButton(root);
|
|
83
|
+
const canSubmitViaFormApi = canSubmitFormApi(form);
|
|
84
|
+
const canClickNativeSubmit = submitButton?.type === 'submit';
|
|
85
|
+
const canClickSaveDraft = Boolean(saveDraftButton);
|
|
86
|
+
// primaryButtonHtmlType="button": ждём final-form API или кнопку черновика в DOM
|
|
87
|
+
if (!canSubmitViaFormApi && !canClickNativeSubmit && !canClickSaveDraft) {
|
|
88
|
+
await new Promise((resolve) => {
|
|
89
|
+
setTimeout(resolve, SUBMIT_POLL_MS);
|
|
90
|
+
});
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
formRef.__itcaseDidAutoSubmit = true;
|
|
94
|
+
await new Promise((resolve) => {
|
|
95
|
+
requestAnimationFrame(() => {
|
|
96
|
+
requestAnimationFrame(resolve);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
if (signal.aborted) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
triggerFormSubmit({ form: formRef.current, root, submitButton });
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export { autoSubmitForm };
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import React, { useRef, useEffect } from 'react';
|
|
2
2
|
|
|
3
|
+
function isVitestEnvironment() {
|
|
4
|
+
return Boolean(import.meta.env?.VITEST);
|
|
5
|
+
}
|
|
6
|
+
|
|
3
7
|
const SUBMIT_POLL_MS = 50;
|
|
4
8
|
function getStoryPreviewDocument() {
|
|
5
9
|
const previewIframe = document.getElementById('storybook-preview-iframe') ?? document.querySelector('iframe[data-is-storybook="true"]');
|
|
@@ -171,7 +175,9 @@ function withFormRef(children, formRef, bindings) {
|
|
|
171
175
|
/**
|
|
172
176
|
* Авто-submit для интерактивного Storybook (Require / Validation / ServerError).
|
|
173
177
|
* При primaryButtonHtmlType="button" — formRef.current.submit() (final-form API),
|
|
174
|
-
* при type="submit" — click по кнопке. В Vitest submit в play
|
|
178
|
+
* при type="submit" — click по кнопке. В Vitest submit в play — auto-submit не
|
|
179
|
+
* запускаем, иначе второй клик из play ставит modifiedSinceLastSubmit и прячет
|
|
180
|
+
* non-field notification.
|
|
175
181
|
*/
|
|
176
182
|
function FormSubmitWrapper(props) {
|
|
177
183
|
const formRef = useRef(null);
|
|
@@ -185,8 +191,9 @@ function FormSubmitWrapper(props) {
|
|
|
185
191
|
children
|
|
186
192
|
} = props;
|
|
187
193
|
const storyArgs = args ?? context?.args ?? children?.props?.args ?? {};
|
|
194
|
+
const shouldAutoSubmit = submit && !isVitestEnvironment();
|
|
188
195
|
useEffect(() => {
|
|
189
|
-
if (!
|
|
196
|
+
if (!shouldAutoSubmit) {
|
|
190
197
|
return undefined;
|
|
191
198
|
}
|
|
192
199
|
delete formRef.__itcaseDidAutoSubmit;
|
|
@@ -196,7 +203,7 @@ function FormSubmitWrapper(props) {
|
|
|
196
203
|
abortController.abort();
|
|
197
204
|
delete formRef.__itcaseDidAutoSubmit;
|
|
198
205
|
};
|
|
199
|
-
}, [
|
|
206
|
+
}, [shouldAutoSubmit, storyArgs.errors]);
|
|
200
207
|
|
|
201
208
|
// eslint-disable-next-line react-hooks/refs -- ref уходит в cloneElement внутри bound render
|
|
202
209
|
return withFormRef(children, formRef, {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { F as FormSubmitWrapper } from './FormSubmitWrapper-
|
|
1
|
+
export { F as FormSubmitWrapper } from './FormSubmitWrapper-EwNkaMht.js';
|
|
2
2
|
import 'react';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare const ADDON_THEMES: {
|
|
2
|
+
defaultTheme: string;
|
|
3
|
+
themes: {
|
|
4
|
+
AM: string;
|
|
5
|
+
'AM Dark Theme': string;
|
|
6
|
+
'AM Light Theme': string;
|
|
7
|
+
Baikal: string;
|
|
8
|
+
'Baikal Dark Theme': string;
|
|
9
|
+
'Baikal Light Theme': string;
|
|
10
|
+
ITCase: string;
|
|
11
|
+
'ITCase Dark': string;
|
|
12
|
+
'ITCase Light Theme': string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export { ADDON_THEMES };
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
const ADDON_THEMES = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export { ADDON_THEMES }
|
|
2
|
+
defaultTheme: 'AM',
|
|
3
|
+
themes: {
|
|
4
|
+
AM: 'am',
|
|
5
|
+
'AM Dark Theme': 'am dark-theme',
|
|
6
|
+
'AM Light Theme': 'am light-theme',
|
|
7
|
+
Baikal: 'baikal',
|
|
8
|
+
'Baikal Dark Theme': 'baikal dark-theme',
|
|
9
|
+
'Baikal Light Theme': 'baikal light-theme',
|
|
10
|
+
ITCase: 'itcase',
|
|
11
|
+
'ITCase Dark': 'itcase dark-theme',
|
|
12
|
+
'ITCase Light Theme': 'itcase light-theme',
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
export { ADDON_THEMES };
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
const ADDONS_NEXTJS = [
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
]
|
|
9
|
-
|
|
10
|
-
export { ADDONS_NEXTJS }
|
|
2
|
+
'@storybook/addon-links',
|
|
3
|
+
'@storybook/addon-themes',
|
|
4
|
+
'@storybook/addon-designs',
|
|
5
|
+
'@storybook/addon-docs',
|
|
6
|
+
'@storybook/addon-vitest',
|
|
7
|
+
'storybook-addon-source-link',
|
|
8
|
+
];
|
|
9
|
+
export { ADDONS_NEXTJS };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
const ADDONS_REACT_NATIVE = [
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
]
|
|
7
|
-
|
|
8
|
-
export { ADDONS_REACT_NATIVE }
|
|
2
|
+
'@storybook/addon-ondevice-notes',
|
|
3
|
+
'@storybook/addon-ondevice-controls',
|
|
4
|
+
'@storybook/addon-ondevice-backgrounds',
|
|
5
|
+
'@storybook/addon-ondevice-actions',
|
|
6
|
+
];
|
|
7
|
+
export { ADDONS_REACT_NATIVE };
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
const ADDONS_REACT_NATIVE_WEB = ['@storybook/addon-docs']
|
|
2
|
-
|
|
3
|
-
export { ADDONS_REACT_NATIVE_WEB }
|
|
1
|
+
const ADDONS_REACT_NATIVE_WEB = ['@storybook/addon-docs'];
|
|
2
|
+
export { ADDONS_REACT_NATIVE_WEB };
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
const ADDONS_VITE = [
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
]
|
|
9
|
-
|
|
10
|
-
export { ADDONS_VITE }
|
|
2
|
+
'@storybook/addon-links',
|
|
3
|
+
'@storybook/addon-themes',
|
|
4
|
+
'@storybook/addon-designs',
|
|
5
|
+
'@storybook/addon-docs',
|
|
6
|
+
'@storybook/addon-vitest',
|
|
7
|
+
'storybook-addon-source-link',
|
|
8
|
+
];
|
|
9
|
+
export { ADDONS_VITE };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare const ADDONS_WEBPACK: (string | {
|
|
2
|
+
name: string;
|
|
3
|
+
options: {
|
|
4
|
+
rules: {
|
|
5
|
+
test: RegExp;
|
|
6
|
+
use: (string | {
|
|
7
|
+
loader: string;
|
|
8
|
+
options: {
|
|
9
|
+
importLoaders: number;
|
|
10
|
+
};
|
|
11
|
+
} | {
|
|
12
|
+
loader: string;
|
|
13
|
+
options?: undefined;
|
|
14
|
+
})[];
|
|
15
|
+
}[];
|
|
16
|
+
};
|
|
17
|
+
})[];
|
|
18
|
+
export { ADDONS_WEBPACK };
|
|
@@ -1,30 +1,29 @@
|
|
|
1
1
|
const ADDONS_WEBPACK = [
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
2
|
+
'@storybook/addon-webpack5-compiler-swc',
|
|
3
|
+
'@storybook/addon-themes',
|
|
4
|
+
'@storybook/addon-designs',
|
|
5
|
+
'@storybook/addon-docs',
|
|
6
|
+
'@storybook/addon-themes',
|
|
7
|
+
{
|
|
8
|
+
name: '@storybook/addon-styling-webpack',
|
|
9
|
+
options: {
|
|
10
|
+
rules: [
|
|
11
|
+
{
|
|
12
|
+
test: /\.css$/,
|
|
13
|
+
use: [
|
|
14
|
+
'style-loader',
|
|
15
|
+
{
|
|
16
|
+
loader: 'css-loader',
|
|
17
|
+
options: { importLoaders: 1 },
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
loader: 'postcss-loader',
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
],
|
|
23
25
|
},
|
|
24
|
-
],
|
|
25
26
|
},
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
export { ADDONS_WEBPACK }
|
|
27
|
+
'storybook-addon-source-link',
|
|
28
|
+
];
|
|
29
|
+
export { ADDONS_WEBPACK };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|