@kne/form-creator 0.1.28 → 0.1.29
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/index.js +75 -7
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +70 -4
- package/dist/index.modern.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -7897,22 +7897,41 @@ const FocusStepsActions = ({
|
|
|
7897
7897
|
const isLast = current >= items.length - 1;
|
|
7898
7898
|
const handleNext = function () {
|
|
7899
7899
|
try {
|
|
7900
|
+
let _exit;
|
|
7900
7901
|
if (loading || isLast) {
|
|
7901
7902
|
return Promise.resolve();
|
|
7902
7903
|
}
|
|
7903
7904
|
setLoading(true);
|
|
7904
|
-
|
|
7905
|
-
|
|
7905
|
+
return Promise.resolve(_finallyRethrows(function () {
|
|
7906
|
+
let _exit2;
|
|
7907
|
+
const names = getStepFieldNames(items[current]);
|
|
7908
|
+
// validateFieldsByName 失败时会滚到首个错字段(同提交 ScrollToError);旧版 form-info 无此行为时下方兜底
|
|
7909
|
+
return Promise.resolve(FormInfo.validateFieldsByName(openApi, names)).then(function (_validateFieldsByName) {
|
|
7906
7910
|
if (_validateFieldsByName) {
|
|
7907
7911
|
onChange(current + 1);
|
|
7912
|
+
_exit = 1;
|
|
7913
|
+
return;
|
|
7914
|
+
}
|
|
7915
|
+
const firstInvalid = names.find(name => {
|
|
7916
|
+
const field = openApi?.getField?.({
|
|
7917
|
+
name
|
|
7918
|
+
});
|
|
7919
|
+
return field && field.isPass === false;
|
|
7920
|
+
});
|
|
7921
|
+
const el = firstInvalid ? openApi?.getField?.({
|
|
7922
|
+
name: firstInvalid
|
|
7923
|
+
})?.fieldRef?.current : null;
|
|
7924
|
+
if (el && typeof el.scrollIntoView === 'function') {
|
|
7925
|
+
requestAnimationFrame(() => {
|
|
7926
|
+
el.scrollIntoView();
|
|
7927
|
+
});
|
|
7908
7928
|
}
|
|
7909
7929
|
});
|
|
7910
7930
|
}, function (_wasThrown, _result) {
|
|
7911
7931
|
setLoading(false);
|
|
7912
7932
|
if (_wasThrown) throw _result;
|
|
7913
7933
|
return _result;
|
|
7914
|
-
});
|
|
7915
|
-
return Promise.resolve(_temp && _temp.then ? _temp.then(function () {}) : void 0);
|
|
7934
|
+
}));
|
|
7916
7935
|
} catch (e) {
|
|
7917
7936
|
return Promise.reject(e);
|
|
7918
7937
|
}
|
|
@@ -7964,10 +7983,17 @@ const FocusSteps = ({
|
|
|
7964
7983
|
stepsClassName,
|
|
7965
7984
|
...props
|
|
7966
7985
|
}) => {
|
|
7986
|
+
const {
|
|
7987
|
+
openApi
|
|
7988
|
+
} = reactFormAntd.useFormContext() || {};
|
|
7967
7989
|
const [current, setCurrent] = react.useState(0);
|
|
7968
7990
|
const headerRef = react.useRef(null);
|
|
7969
7991
|
const mountedRef = react.useRef(false);
|
|
7970
7992
|
const safeCurrent = Math.min(current, Math.max(items.length - 1, 0));
|
|
7993
|
+
const currentRef = react.useRef(safeCurrent);
|
|
7994
|
+
currentRef.current = safeCurrent;
|
|
7995
|
+
const itemsRef = react.useRef(items);
|
|
7996
|
+
itemsRef.current = items;
|
|
7971
7997
|
const stepTitle = index => items[index]?.title || formatMessage({
|
|
7972
7998
|
id: 'untitledStep'
|
|
7973
7999
|
}, {
|
|
@@ -7986,6 +8012,38 @@ const FocusSteps = ({
|
|
|
7986
8012
|
});
|
|
7987
8013
|
}
|
|
7988
8014
|
}, [safeCurrent]);
|
|
8015
|
+
|
|
8016
|
+
// 提交失败时:若当前步字段有错则强制留在当前步,避免误跳到后续错步
|
|
8017
|
+
react.useEffect(() => {
|
|
8018
|
+
const emitter = openApi?.emitter;
|
|
8019
|
+
if (!emitter?.addListener) {
|
|
8020
|
+
return undefined;
|
|
8021
|
+
}
|
|
8022
|
+
const stayIfCurrentHasError = errors => {
|
|
8023
|
+
const step = itemsRef.current[currentRef.current];
|
|
8024
|
+
const names = new Set(getStepFieldNames(step));
|
|
8025
|
+
if (!names.size) {
|
|
8026
|
+
return;
|
|
8027
|
+
}
|
|
8028
|
+
const currentHasError = (errors || []).some(item => names.has(item?.name) || names.has(item?.groupName));
|
|
8029
|
+
if (currentHasError) {
|
|
8030
|
+
setCurrent(currentRef.current);
|
|
8031
|
+
}
|
|
8032
|
+
};
|
|
8033
|
+
const errorSub = emitter.addListener('form:submit:error', stayIfCurrentHasError);
|
|
8034
|
+
const completeSub = emitter.addListener('form:submit:complete', ({
|
|
8035
|
+
isPass,
|
|
8036
|
+
errors
|
|
8037
|
+
} = {}) => {
|
|
8038
|
+
if (!isPass) {
|
|
8039
|
+
stayIfCurrentHasError(errors);
|
|
8040
|
+
}
|
|
8041
|
+
});
|
|
8042
|
+
return () => {
|
|
8043
|
+
errorSub?.remove?.();
|
|
8044
|
+
completeSub?.remove?.();
|
|
8045
|
+
};
|
|
8046
|
+
}, [openApi]);
|
|
7989
8047
|
const focusItems = items.map((item, index) => {
|
|
7990
8048
|
if (index !== safeCurrent) {
|
|
7991
8049
|
return item;
|
|
@@ -8006,7 +8064,8 @@ const FocusSteps = ({
|
|
|
8006
8064
|
children: [item.children != null ? item.children : /*#__PURE__*/jsxRuntime.jsx(FormInfo__default["default"], {
|
|
8007
8065
|
column: item.column,
|
|
8008
8066
|
gap: item.gap,
|
|
8009
|
-
list: item.list || []
|
|
8067
|
+
list: item.list || [],
|
|
8068
|
+
className: item.className
|
|
8010
8069
|
}), /*#__PURE__*/jsxRuntime.jsx(FocusStepsActions, {
|
|
8011
8070
|
items: items,
|
|
8012
8071
|
current: safeCurrent,
|
|
@@ -8446,6 +8505,8 @@ const renderBlockElement = (block, preview = false, ctx = {}) => {
|
|
|
8446
8505
|
case 'steps':
|
|
8447
8506
|
{
|
|
8448
8507
|
const isFocusSteps = block.stepsStyle === 'focus';
|
|
8508
|
+
// 与 formInfo 一致:block.showIndex(或 step 上覆盖)时给题干加序号
|
|
8509
|
+
const blockShowIndex = !!block.showIndex;
|
|
8449
8510
|
return withBlockLayout(/*#__PURE__*/react.createElement(isFocusSteps ? FocusSteps$1 : FormInfo.Steps, {
|
|
8450
8511
|
key: block.id,
|
|
8451
8512
|
title: block.title || undefined,
|
|
@@ -8458,10 +8519,15 @@ const renderBlockElement = (block, preview = false, ctx = {}) => {
|
|
|
8458
8519
|
prevIcon: /*#__PURE__*/react.createElement(icons.ArrowLeftOutlined),
|
|
8459
8520
|
nextIcon: /*#__PURE__*/react.createElement(icons.ArrowRightOutlined),
|
|
8460
8521
|
items: (block.items || []).map(step => {
|
|
8461
|
-
const
|
|
8522
|
+
const showIndex = step.showIndex != null ? !!step.showIndex : blockShowIndex;
|
|
8523
|
+
const entries = renderFieldEntries(step.list, preview, {
|
|
8524
|
+
...fieldRenderOpts,
|
|
8525
|
+
showIndex
|
|
8526
|
+
});
|
|
8462
8527
|
const nested = renderChildBlocks(step.blocks || [], nextCtx);
|
|
8463
8528
|
const fieldNames = [...(step.list || []).filter(field => field && !field.hidden && field.name).map(field => field.name), ...collectBlockFieldNames(step.blocks || [])];
|
|
8464
8529
|
const hasConditional = entries.some(entry => entry.visibleWhen);
|
|
8530
|
+
const indexClassName = showIndex ? style['form-info-show-index'] : null;
|
|
8465
8531
|
if (nested.length || hasConditional) {
|
|
8466
8532
|
return {
|
|
8467
8533
|
key: step.id,
|
|
@@ -8474,7 +8540,8 @@ const renderBlockElement = (block, preview = false, ctx = {}) => {
|
|
|
8474
8540
|
}, entries.length ? createFieldsFormInfo({
|
|
8475
8541
|
key: `${step.id}-fields`,
|
|
8476
8542
|
column: step.column,
|
|
8477
|
-
gap: block.gap
|
|
8543
|
+
gap: block.gap,
|
|
8544
|
+
className: indexClassName
|
|
8478
8545
|
}, entries, [], knownNames) : null, ...nested)
|
|
8479
8546
|
};
|
|
8480
8547
|
}
|
|
@@ -8484,6 +8551,7 @@ const renderBlockElement = (block, preview = false, ctx = {}) => {
|
|
|
8484
8551
|
column: step.column,
|
|
8485
8552
|
gap: block.gap,
|
|
8486
8553
|
list: entries.map(entry => entry.element),
|
|
8554
|
+
className: indexClassName,
|
|
8487
8555
|
fieldNames
|
|
8488
8556
|
};
|
|
8489
8557
|
})
|