@kne/form-creator 0.1.8 → 0.1.12
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/README.md +268 -1
- package/dist/index.css +23 -2
- package/dist/index.css.map +1 -1
- package/dist/index.js +575 -119
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +573 -125
- package/dist/index.modern.js.map +1 -1
- package/package.json +3 -2
package/dist/index.modern.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import '@kne/form-info/dist/index.css';
|
|
2
2
|
import '@kne/info-page/dist/index.css';
|
|
3
|
-
import { useState, useMemo, useEffect, createElement, Fragment } from 'react';
|
|
3
|
+
import { useState, useRef, useMemo, useEffect, useCallback, createElement, Fragment } from 'react';
|
|
4
4
|
import { Space, Tag, Button, Typography, Flex, Dropdown, Empty, message, Checkbox as Checkbox$1, Input as Input$1, InputNumber as InputNumber$1, Card, Tooltip } from 'antd';
|
|
5
5
|
import { createWithIntlProvider, useIntl } from '@kne/react-intl';
|
|
6
6
|
import { useIsMobile, RESPONSIVE_BOUNDARY_CLASS } from '@kne/responsive-utils';
|
|
@@ -14,7 +14,7 @@ import { jsxs, jsx } from 'react/jsx-runtime';
|
|
|
14
14
|
import FormInfo, { FormModal, Form, Steps, MultiField, TableList, List } from '@kne/form-info';
|
|
15
15
|
import InfoPage from '@kne/info-page';
|
|
16
16
|
|
|
17
|
-
var style = {"kne-responsive-boundary":"kne-form-creator_gh14z","kne-responsive-scroll":"kne-form-creator_Kfn6L","form-creator":"kne-form-creator_Xrjrk","editor-pane":"kne-form-creator_Skfuv","preview-pane":"kne-form-creator_v4Lsp","editor-header":"kne-form-creator_WaSS-","block-list-panel":"kne-form-creator_lx8An","form-actions-setting-btn":"kne-form-creator_NekU2","panel-toolbar":"kne-form-creator_t0WxZ","add-block-btn":"kne-form-creator_16Zre","add-inline-btn":"kne-form-creator_iCYdB","ant-btn-disabled":"kne-form-creator_LdGtv","block-list":"kne-form-creator_wK5eK","block-section":"kne-form-creator_15IiK","block-kind-formInfo":"kne-form-creator_D0hoK","block-kind-list":"kne-form-creator_JdPhy","block-kind-tableList":"kne-form-creator_gzd64","block-kind-multiField":"kne-form-creator_t0iOJ","block-kind-steps":"kne-form-creator_QNF9W","step-section":"kne-form-creator_22ajp","block-section-header":"kne-form-creator_wS4rL","block-header-left":"kne-form-creator_t4awC","block-title":"kne-form-creator_wSVJf","block-summary":"kne-form-creator_GzeW8","block-header-actions":"kne-form-creator_Ue-nT","block-body":"kne-form-creator_je1H0","item-blocks-section":"kne-form-creator_wq4bT","nested-block-list":"kne-form-creator_4NWH4","block-section-nested":"kne-form-creator_mUKom","add-field-dropdown":"kne-form-creator_9JS0d","add-field-dropdown-item":"kne-form-creator_Ql1z3","add-field-dropdown-item-icon":"kne-form-creator_ZHB5O","add-field-dropdown-item-desc":"kne-form-creator_dcsOS","add-field-dropdown-divider":"kne-form-creator_CUK0H","add-field-dropdown-label":"kne-form-creator_bPJ-2","section-toolbar":"kne-form-creator_LUO8S","section-toolbar-label":"kne-form-creator_7KQ79","field-list":"kne-form-creator_-B7WZ","step-list":"kne-form-creator_kc1pH","step-section-header":"kne-form-creator_wkhEX","step-section-title":"kne-form-creator_NBinE","step-index":"kne-form-creator_CCKZZ","field-row":"kne-form-creator_XMkdt","field-row-index":"kne-form-creator_a-cDo","field-row-main":"kne-form-creator_ftlwp","inline-empty":"kne-form-creator_yP-RF","action-group":"kne-form-creator_773yo","hover-reveal":"kne-form-creator_S234h","hover-reveal-active":"kne-form-creator_AE-6r","action-btn":"kne-form-creator_mLgqh","add-block-dropdown":"kne-form-creator_vmS-e","add-block-option":"kne-form-creator_gjg2Y","add-block-option-icon":"kne-form-creator_qh1hh","add-block-option-text":"kne-form-creator_G8iJO","add-block-option-title":"kne-form-creator_ETSvm","add-block-option-desc":"kne-form-creator_O0C3l","field-empty":"kne-form-creator_Nmpfl","field-label-tips-icon":"kne-form-creator_0VVaO","preview-header":"kne-form-creator_c4BT0","preview-title":"kne-form-creator_fPkK4","preview-body":"kne-form-creator_6JntQ","schema-form":"kne-form-creator_MxCWP","schema-body":"kne-form-creator_q9ydz","schema-actions":"kne-form-creator_Y4eEH","schema-actions-inner":"kne-form-creator_FT9Zf","choice-block":"kne-form-creator_RllJe","choice-selector":"kne-form-creator_5A1eM","choice-panels":"kne-form-creator_IO0MY","choice-panels-empty":"kne-form-creator_T0nND","choice-option-panel":"kne-form-creator_FQixN","choice-option-panel-title":"kne-form-creator_ofRo2","choice-option-summary":"kne-form-creator_pksH8","field-editor-form":"kne-form-creator_PGPHL","form-actions-editor":"kne-form-creator_fchMy","form-actions-switch-field":"kne-form-creator_6JE9x","form-actions-layout-panel":"kne-form-creator_rtm9D","form-actions-align-group":"kne-form-creator_51ZsV","form-actions-layout-title":"kne-form-creator_hFeiC","form-actions-gap-slider":"kne-form-creator_Gq0bk","editor-section":"kne-form-creator_jJy85","section-divider":"kne-form-creator_zA7L-","rule-editor":"kne-form-creator_bAlGU","options-editor":"kne-form-creator_AK4yO","super-select-props":"kne-form-creator_Iawhh","field-props-editor":"kne-form-creator_Gabf2","columns-editor":"kne-form-creator_DQW1N","prop-row":"kne-form-creator_7K54P","prop-label":"kne-form-creator_HAAyH","options-item":"kne-form-creator_dnOd2","table-row-card":"kne-form-creator_cwCYp","tree-options-editor":"kne-form-creator_s3nHO","tree-options-list":"kne-form-creator_Djs-E","tree-option-node":"kne-form-creator_XAcut","tree-option-row":"kne-form-creator_4K4Rj","tree-option-fields":"kne-form-creator_-4cjc","tree-option-actions":"kne-form-creator_IjCNI","tree-option-children":"kne-form-creator_pVPGJ","tree-add-sibling":"kne-form-creator_bl46P","rule-checkbox-group":"kne-form-creator_tDgVP","rule-len-row":"kne-form-creator_ATsae","rule-len-input":"kne-form-creator_jY4Ld","rule-len-sep":"kne-form-creator_jBDC8","options-list":"kne-form-creator_GUBNS","options-row":"kne-form-creator_uohD0","options-tip":"kne-form-creator_vrTmK","icon-square-btn":"kne-form-creator_DZjCf","icon-square-btn-sm":"kne-form-creator_GAh-t","is-mobile":"kne-form-creator_LtgJz"};
|
|
17
|
+
var style = {"kne-responsive-boundary":"kne-form-creator_gh14z","kne-responsive-scroll":"kne-form-creator_Kfn6L","form-creator":"kne-form-creator_Xrjrk","editor-pane":"kne-form-creator_Skfuv","preview-pane":"kne-form-creator_v4Lsp","editor-header":"kne-form-creator_WaSS-","block-list-panel":"kne-form-creator_lx8An","form-actions-setting-btn":"kne-form-creator_NekU2","panel-toolbar":"kne-form-creator_t0WxZ","add-block-btn":"kne-form-creator_16Zre","add-inline-btn":"kne-form-creator_iCYdB","ant-btn-disabled":"kne-form-creator_LdGtv","block-list":"kne-form-creator_wK5eK","block-section":"kne-form-creator_15IiK","block-kind-formInfo":"kne-form-creator_D0hoK","block-kind-list":"kne-form-creator_JdPhy","block-kind-tableList":"kne-form-creator_gzd64","block-kind-multiField":"kne-form-creator_t0iOJ","block-kind-steps":"kne-form-creator_QNF9W","step-section":"kne-form-creator_22ajp","block-section-header":"kne-form-creator_wS4rL","block-header-left":"kne-form-creator_t4awC","block-title":"kne-form-creator_wSVJf","block-summary":"kne-form-creator_GzeW8","block-header-actions":"kne-form-creator_Ue-nT","block-body":"kne-form-creator_je1H0","item-blocks-section":"kne-form-creator_wq4bT","nested-block-list":"kne-form-creator_4NWH4","block-section-nested":"kne-form-creator_mUKom","add-field-dropdown":"kne-form-creator_9JS0d","add-field-dropdown-item":"kne-form-creator_Ql1z3","add-field-dropdown-item-icon":"kne-form-creator_ZHB5O","add-field-dropdown-item-desc":"kne-form-creator_dcsOS","add-field-dropdown-divider":"kne-form-creator_CUK0H","add-field-dropdown-label":"kne-form-creator_bPJ-2","section-toolbar":"kne-form-creator_LUO8S","section-toolbar-label":"kne-form-creator_7KQ79","field-list":"kne-form-creator_-B7WZ","step-list":"kne-form-creator_kc1pH","step-section-header":"kne-form-creator_wkhEX","step-section-title":"kne-form-creator_NBinE","step-section-actions":"kne-form-creator_es-FC","step-index":"kne-form-creator_CCKZZ","field-row":"kne-form-creator_XMkdt","field-row-index":"kne-form-creator_a-cDo","field-row-main":"kne-form-creator_ftlwp","inline-empty":"kne-form-creator_yP-RF","action-group":"kne-form-creator_773yo","hover-reveal":"kne-form-creator_S234h","hover-reveal-active":"kne-form-creator_AE-6r","action-btn":"kne-form-creator_mLgqh","add-block-dropdown":"kne-form-creator_vmS-e","add-block-option":"kne-form-creator_gjg2Y","add-block-option-icon":"kne-form-creator_qh1hh","add-block-option-text":"kne-form-creator_G8iJO","add-block-option-title":"kne-form-creator_ETSvm","add-block-option-desc":"kne-form-creator_O0C3l","field-empty":"kne-form-creator_Nmpfl","field-label-tips-icon":"kne-form-creator_0VVaO","preview-header":"kne-form-creator_c4BT0","preview-title":"kne-form-creator_fPkK4","preview-body":"kne-form-creator_6JntQ","schema-form":"kne-form-creator_MxCWP","schema-body":"kne-form-creator_q9ydz","schema-actions":"kne-form-creator_Y4eEH","schema-actions-inner":"kne-form-creator_FT9Zf","choice-block":"kne-form-creator_RllJe","choice-selector":"kne-form-creator_5A1eM","choice-panels":"kne-form-creator_IO0MY","choice-panels-empty":"kne-form-creator_T0nND","choice-option-panel":"kne-form-creator_FQixN","choice-option-panel-title":"kne-form-creator_ofRo2","choice-option-summary":"kne-form-creator_pksH8","field-editor-form":"kne-form-creator_PGPHL","form-actions-editor":"kne-form-creator_fchMy","form-actions-switch-field":"kne-form-creator_6JE9x","form-actions-layout-panel":"kne-form-creator_rtm9D","form-actions-align-group":"kne-form-creator_51ZsV","form-actions-layout-title":"kne-form-creator_hFeiC","form-actions-gap-slider":"kne-form-creator_Gq0bk","editor-section":"kne-form-creator_jJy85","section-divider":"kne-form-creator_zA7L-","rule-editor":"kne-form-creator_bAlGU","options-editor":"kne-form-creator_AK4yO","super-select-props":"kne-form-creator_Iawhh","field-props-editor":"kne-form-creator_Gabf2","columns-editor":"kne-form-creator_DQW1N","prop-row":"kne-form-creator_7K54P","prop-label":"kne-form-creator_HAAyH","options-item":"kne-form-creator_dnOd2","table-row-card":"kne-form-creator_cwCYp","tree-options-editor":"kne-form-creator_s3nHO","tree-options-list":"kne-form-creator_Djs-E","tree-option-node":"kne-form-creator_XAcut","tree-option-row":"kne-form-creator_4K4Rj","tree-option-fields":"kne-form-creator_-4cjc","tree-option-actions":"kne-form-creator_IjCNI","tree-option-children":"kne-form-creator_pVPGJ","tree-add-sibling":"kne-form-creator_bl46P","rule-checkbox-group":"kne-form-creator_tDgVP","rule-len-row":"kne-form-creator_ATsae","rule-len-input":"kne-form-creator_jY4Ld","rule-len-sep":"kne-form-creator_jBDC8","options-list":"kne-form-creator_GUBNS","options-row":"kne-form-creator_uohD0","options-tip":"kne-form-creator_vrTmK","icon-square-btn":"kne-form-creator_DZjCf","icon-square-btn-sm":"kne-form-creator_GAh-t","is-mobile":"kne-form-creator_LtgJz"};
|
|
18
18
|
|
|
19
19
|
function _extends() {
|
|
20
20
|
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
@@ -1379,6 +1379,39 @@ const FIELD_GROUPS = [{
|
|
|
1379
1379
|
label: '业务选择',
|
|
1380
1380
|
types: ['SelectFunction', 'SelectIndustry', 'SelectAddress']
|
|
1381
1381
|
}];
|
|
1382
|
+
const optionEnumValues = field => {
|
|
1383
|
+
var _field$props;
|
|
1384
|
+
const options = field == null || (_field$props = field.props) == null ? void 0 : _field$props.options;
|
|
1385
|
+
if (!Array.isArray(options) || !options.length) {
|
|
1386
|
+
return undefined;
|
|
1387
|
+
}
|
|
1388
|
+
const values = options.map(item => item == null ? void 0 : item.value).filter(value => value !== undefined && value !== null && value !== '');
|
|
1389
|
+
return values.length ? values : undefined;
|
|
1390
|
+
};
|
|
1391
|
+
const stringWithEnumSchema = field => {
|
|
1392
|
+
const schema = {
|
|
1393
|
+
type: 'string'
|
|
1394
|
+
};
|
|
1395
|
+
const enums = optionEnumValues(field);
|
|
1396
|
+
if (enums) {
|
|
1397
|
+
schema.enum = enums;
|
|
1398
|
+
}
|
|
1399
|
+
return schema;
|
|
1400
|
+
};
|
|
1401
|
+
const superSelectValueSchema = field => {
|
|
1402
|
+
var _field$props2;
|
|
1403
|
+
if (field != null && (_field$props2 = field.props) != null && _field$props2.single) {
|
|
1404
|
+
return {
|
|
1405
|
+
type: 'object'
|
|
1406
|
+
};
|
|
1407
|
+
}
|
|
1408
|
+
return {
|
|
1409
|
+
type: 'array',
|
|
1410
|
+
items: {
|
|
1411
|
+
type: 'object'
|
|
1412
|
+
}
|
|
1413
|
+
};
|
|
1414
|
+
};
|
|
1382
1415
|
defineField('Input', {
|
|
1383
1416
|
label: '单行文本',
|
|
1384
1417
|
group: '基础字段',
|
|
@@ -1386,7 +1419,10 @@ defineField('Input', {
|
|
|
1386
1419
|
defaultProps: {
|
|
1387
1420
|
allowClear: true
|
|
1388
1421
|
},
|
|
1389
|
-
hasFieldProps: true
|
|
1422
|
+
hasFieldProps: true,
|
|
1423
|
+
valueSchema: {
|
|
1424
|
+
type: 'string'
|
|
1425
|
+
}
|
|
1390
1426
|
});
|
|
1391
1427
|
defineField('TextArea', {
|
|
1392
1428
|
label: '多行文本',
|
|
@@ -1398,14 +1434,20 @@ defineField('TextArea', {
|
|
|
1398
1434
|
defaults: {
|
|
1399
1435
|
block: true
|
|
1400
1436
|
},
|
|
1401
|
-
hasFieldProps: true
|
|
1437
|
+
hasFieldProps: true,
|
|
1438
|
+
valueSchema: {
|
|
1439
|
+
type: 'string'
|
|
1440
|
+
}
|
|
1402
1441
|
});
|
|
1403
1442
|
defineField('InputNumber', {
|
|
1404
1443
|
label: '数字',
|
|
1405
1444
|
group: '基础字段',
|
|
1406
1445
|
component: InputNumber,
|
|
1407
1446
|
defaultProps: {},
|
|
1408
|
-
hasFieldProps: true
|
|
1447
|
+
hasFieldProps: true,
|
|
1448
|
+
valueSchema: {
|
|
1449
|
+
type: 'number'
|
|
1450
|
+
}
|
|
1409
1451
|
});
|
|
1410
1452
|
defineField('Select', {
|
|
1411
1453
|
label: '下拉选择',
|
|
@@ -1416,7 +1458,8 @@ defineField('Select', {
|
|
|
1416
1458
|
allowClear: true
|
|
1417
1459
|
},
|
|
1418
1460
|
hasOptions: true,
|
|
1419
|
-
hasFieldProps: true
|
|
1461
|
+
hasFieldProps: true,
|
|
1462
|
+
valueSchema: stringWithEnumSchema
|
|
1420
1463
|
});
|
|
1421
1464
|
defineField('RadioGroup', {
|
|
1422
1465
|
label: '单选组',
|
|
@@ -1425,7 +1468,8 @@ defineField('RadioGroup', {
|
|
|
1425
1468
|
defaultProps: {
|
|
1426
1469
|
options: []
|
|
1427
1470
|
},
|
|
1428
|
-
hasOptions: true
|
|
1471
|
+
hasOptions: true,
|
|
1472
|
+
valueSchema: stringWithEnumSchema
|
|
1429
1473
|
});
|
|
1430
1474
|
defineField('CheckboxGroup', {
|
|
1431
1475
|
label: '复选组',
|
|
@@ -1434,7 +1478,20 @@ defineField('CheckboxGroup', {
|
|
|
1434
1478
|
defaultProps: {
|
|
1435
1479
|
options: []
|
|
1436
1480
|
},
|
|
1437
|
-
hasOptions: true
|
|
1481
|
+
hasOptions: true,
|
|
1482
|
+
valueSchema: field => {
|
|
1483
|
+
const items = {
|
|
1484
|
+
type: 'string'
|
|
1485
|
+
};
|
|
1486
|
+
const enums = optionEnumValues(field);
|
|
1487
|
+
if (enums) {
|
|
1488
|
+
items.enum = enums;
|
|
1489
|
+
}
|
|
1490
|
+
return {
|
|
1491
|
+
type: 'array',
|
|
1492
|
+
items
|
|
1493
|
+
};
|
|
1494
|
+
}
|
|
1438
1495
|
});
|
|
1439
1496
|
defineField('SuperSelectList', {
|
|
1440
1497
|
label: '普通下拉',
|
|
@@ -1449,7 +1506,8 @@ defineField('SuperSelectList', {
|
|
|
1449
1506
|
},
|
|
1450
1507
|
isSuperSelect: true,
|
|
1451
1508
|
hasOptions: true,
|
|
1452
|
-
optionsAllowDescription: true
|
|
1509
|
+
optionsAllowDescription: true,
|
|
1510
|
+
valueSchema: superSelectValueSchema
|
|
1453
1511
|
});
|
|
1454
1512
|
defineField('SuperSelectTableList', {
|
|
1455
1513
|
label: '表格选择',
|
|
@@ -1466,7 +1524,8 @@ defineField('SuperSelectTableList', {
|
|
|
1466
1524
|
isSuperSelect: true,
|
|
1467
1525
|
hasOptions: true,
|
|
1468
1526
|
hasColumns: true,
|
|
1469
|
-
optionsAllowDescription: true
|
|
1527
|
+
optionsAllowDescription: true,
|
|
1528
|
+
valueSchema: superSelectValueSchema
|
|
1470
1529
|
});
|
|
1471
1530
|
defineField('SuperSelectTree', {
|
|
1472
1531
|
label: '树形选择',
|
|
@@ -1482,7 +1541,8 @@ defineField('SuperSelectTree', {
|
|
|
1482
1541
|
isSuperSelect: true,
|
|
1483
1542
|
hasOptions: true,
|
|
1484
1543
|
optionsAllowChildren: true,
|
|
1485
|
-
optionsAllowDescription: true
|
|
1544
|
+
optionsAllowDescription: true,
|
|
1545
|
+
valueSchema: superSelectValueSchema
|
|
1486
1546
|
});
|
|
1487
1547
|
defineField('SuperSelectCascader', {
|
|
1488
1548
|
label: '级联选择',
|
|
@@ -1500,7 +1560,8 @@ defineField('SuperSelectCascader', {
|
|
|
1500
1560
|
hasOptions: true,
|
|
1501
1561
|
hasOnlyLastLevel: true,
|
|
1502
1562
|
optionsAllowChildren: true,
|
|
1503
|
-
optionsAllowDescription: true
|
|
1563
|
+
optionsAllowDescription: true,
|
|
1564
|
+
valueSchema: superSelectValueSchema
|
|
1504
1565
|
});
|
|
1505
1566
|
defineField('SelectFunction', {
|
|
1506
1567
|
label: '职能选择',
|
|
@@ -1511,7 +1572,8 @@ defineField('SelectFunction', {
|
|
|
1511
1572
|
allowClear: true
|
|
1512
1573
|
},
|
|
1513
1574
|
isSuperSelect: true,
|
|
1514
|
-
hasBuiltinData: true
|
|
1575
|
+
hasBuiltinData: true,
|
|
1576
|
+
valueSchema: superSelectValueSchema
|
|
1515
1577
|
});
|
|
1516
1578
|
defineField('SelectIndustry', {
|
|
1517
1579
|
label: '行业选择',
|
|
@@ -1522,7 +1584,8 @@ defineField('SelectIndustry', {
|
|
|
1522
1584
|
allowClear: true
|
|
1523
1585
|
},
|
|
1524
1586
|
isSuperSelect: true,
|
|
1525
|
-
hasBuiltinData: true
|
|
1587
|
+
hasBuiltinData: true,
|
|
1588
|
+
valueSchema: superSelectValueSchema
|
|
1526
1589
|
});
|
|
1527
1590
|
defineField('SelectAddress', {
|
|
1528
1591
|
label: '地址选择',
|
|
@@ -1533,14 +1596,18 @@ defineField('SelectAddress', {
|
|
|
1533
1596
|
allowClear: true
|
|
1534
1597
|
},
|
|
1535
1598
|
isSuperSelect: true,
|
|
1536
|
-
hasBuiltinData: true
|
|
1599
|
+
hasBuiltinData: true,
|
|
1600
|
+
valueSchema: superSelectValueSchema
|
|
1537
1601
|
});
|
|
1538
1602
|
defineField('Switch', {
|
|
1539
1603
|
label: '开关',
|
|
1540
1604
|
group: '基础字段',
|
|
1541
1605
|
component: Switch,
|
|
1542
1606
|
defaultProps: {},
|
|
1543
|
-
hasFieldProps: true
|
|
1607
|
+
hasFieldProps: true,
|
|
1608
|
+
valueSchema: {
|
|
1609
|
+
type: 'boolean'
|
|
1610
|
+
}
|
|
1544
1611
|
});
|
|
1545
1612
|
defineField('Checkbox', {
|
|
1546
1613
|
label: '复选框',
|
|
@@ -1548,6 +1615,9 @@ defineField('Checkbox', {
|
|
|
1548
1615
|
component: Checkbox,
|
|
1549
1616
|
defaultProps: {
|
|
1550
1617
|
children: ''
|
|
1618
|
+
},
|
|
1619
|
+
valueSchema: {
|
|
1620
|
+
type: 'boolean'
|
|
1551
1621
|
}
|
|
1552
1622
|
});
|
|
1553
1623
|
defineField('DatePicker', {
|
|
@@ -1562,7 +1632,20 @@ defineField('DatePicker', {
|
|
|
1562
1632
|
showTime: false
|
|
1563
1633
|
},
|
|
1564
1634
|
hasFieldProps: true,
|
|
1565
|
-
resolveComponent: props => props != null && props.range ? DatePicker.RangePicker || DatePicker : DatePicker
|
|
1635
|
+
resolveComponent: props => props != null && props.range ? DatePicker.RangePicker || DatePicker : DatePicker,
|
|
1636
|
+
valueSchema: field => {
|
|
1637
|
+
var _field$props3;
|
|
1638
|
+
return field != null && (_field$props3 = field.props) != null && _field$props3.range ? {
|
|
1639
|
+
type: 'array',
|
|
1640
|
+
items: {
|
|
1641
|
+
type: 'string'
|
|
1642
|
+
},
|
|
1643
|
+
minItems: 2,
|
|
1644
|
+
maxItems: 2
|
|
1645
|
+
} : {
|
|
1646
|
+
type: 'string'
|
|
1647
|
+
};
|
|
1648
|
+
}
|
|
1566
1649
|
});
|
|
1567
1650
|
|
|
1568
1651
|
/**
|
|
@@ -1577,6 +1660,7 @@ defineField('DatePicker', {
|
|
|
1577
1660
|
*
|
|
1578
1661
|
* preset({ type, definition }) 的 fields 项还可传:
|
|
1579
1662
|
* - groupName?: string 自定义类型下拉分组名;不传则归入「扩展字段」
|
|
1663
|
+
* - valueSchema?: object | (field) => object 提交值的 JSON Schema 片段;缺省回退 { type: 'string' }
|
|
1580
1664
|
*/
|
|
1581
1665
|
const registerField = (type, definition) => {
|
|
1582
1666
|
var _definition$hasFieldP;
|
|
@@ -1641,6 +1725,46 @@ const applyFromPropsSchema = (props, values = {}, propsSchema = []) => {
|
|
|
1641
1725
|
});
|
|
1642
1726
|
};
|
|
1643
1727
|
const getFieldDefinition = type => registry.get(type);
|
|
1728
|
+
|
|
1729
|
+
/**
|
|
1730
|
+
* 解析字段提交值的 JSON Schema 片段。
|
|
1731
|
+
* 优先用 definition.valueSchema(对象或 (field)=>schema);缺省 { type: 'string' }。
|
|
1732
|
+
*/
|
|
1733
|
+
const resolveFieldValueSchema = field => {
|
|
1734
|
+
if (!field || !field.type) {
|
|
1735
|
+
return {
|
|
1736
|
+
type: 'string'
|
|
1737
|
+
};
|
|
1738
|
+
}
|
|
1739
|
+
const definition = registry.get(field.type);
|
|
1740
|
+
const raw = definition == null ? void 0 : definition.valueSchema;
|
|
1741
|
+
let schema;
|
|
1742
|
+
if (typeof raw === 'function') {
|
|
1743
|
+
schema = raw(field);
|
|
1744
|
+
} else if (raw && typeof raw === 'object') {
|
|
1745
|
+
schema = _extends({}, raw);
|
|
1746
|
+
} else {
|
|
1747
|
+
schema = {
|
|
1748
|
+
type: 'string'
|
|
1749
|
+
};
|
|
1750
|
+
}
|
|
1751
|
+
if (!schema || typeof schema !== 'object') {
|
|
1752
|
+
schema = {
|
|
1753
|
+
type: 'string'
|
|
1754
|
+
};
|
|
1755
|
+
} else {
|
|
1756
|
+
schema = _extends({}, schema);
|
|
1757
|
+
}
|
|
1758
|
+
const title = field.label != null && String(field.label).trim() ? String(field.label).trim() : undefined;
|
|
1759
|
+
const description = field.description != null && String(field.description).trim() ? String(field.description).trim() : undefined;
|
|
1760
|
+
if (title && schema.title == null) {
|
|
1761
|
+
schema.title = title;
|
|
1762
|
+
}
|
|
1763
|
+
if (description && schema.description == null) {
|
|
1764
|
+
schema.description = description;
|
|
1765
|
+
}
|
|
1766
|
+
return schema;
|
|
1767
|
+
};
|
|
1644
1768
|
const getFieldComponent = (type, field) => {
|
|
1645
1769
|
const definition = registry.get(type);
|
|
1646
1770
|
if (!definition) {
|
|
@@ -1945,16 +2069,16 @@ const applyFieldProps = (props, values, definition) => {
|
|
|
1945
2069
|
}
|
|
1946
2070
|
};
|
|
1947
2071
|
const fieldToFormValues = field => {
|
|
1948
|
-
var _field$
|
|
2072
|
+
var _field$props4, _field$props5, _field$props6;
|
|
1949
2073
|
const definition = getFieldDefinition(field.type);
|
|
1950
2074
|
const ruleConfig = parseRuleString(field.rule);
|
|
1951
2075
|
const allowChildren = !!(definition != null && definition.optionsAllowChildren);
|
|
1952
|
-
const columns = definition != null && definition.hasColumns ? normalizeColumns((_field$
|
|
1953
|
-
const options = normalizeOptions((_field$
|
|
2076
|
+
const columns = definition != null && definition.hasColumns ? normalizeColumns((_field$props4 = field.props) == null ? void 0 : _field$props4.columns) : [];
|
|
2077
|
+
const options = normalizeOptions((_field$props5 = field.props) == null ? void 0 : _field$props5.options, {
|
|
1954
2078
|
allowChildren,
|
|
1955
2079
|
columns
|
|
1956
2080
|
});
|
|
1957
|
-
const rawPlaceholder = (_field$
|
|
2081
|
+
const rawPlaceholder = (_field$props6 = field.props) == null ? void 0 : _field$props6.placeholder;
|
|
1958
2082
|
const placeholder = Array.isArray(rawPlaceholder) ? rawPlaceholder[0] || '' : rawPlaceholder || '';
|
|
1959
2083
|
return {
|
|
1960
2084
|
type: field.type,
|
|
@@ -2202,6 +2326,7 @@ const BlockListPanel = ({
|
|
|
2202
2326
|
} = useIntl();
|
|
2203
2327
|
const [addMenuOpen, setAddMenuOpen] = useState(false);
|
|
2204
2328
|
const [addFieldMenuId, setAddFieldMenuId] = useState(null);
|
|
2329
|
+
const keepAddFieldMenuOpenRef = useRef(false);
|
|
2205
2330
|
const renderAddBlockMenu = (options, {
|
|
2206
2331
|
onSelect,
|
|
2207
2332
|
className
|
|
@@ -2260,8 +2385,19 @@ const BlockListPanel = ({
|
|
|
2260
2385
|
}
|
|
2261
2386
|
return /*#__PURE__*/jsx(Dropdown, {
|
|
2262
2387
|
open: menuOpen,
|
|
2263
|
-
onOpenChange: open =>
|
|
2264
|
-
|
|
2388
|
+
onOpenChange: open => {
|
|
2389
|
+
if (open) {
|
|
2390
|
+
setAddFieldMenuId(menuKey);
|
|
2391
|
+
return;
|
|
2392
|
+
}
|
|
2393
|
+
// 已打开时再点触发器:antd 会 toggle 关闭,这里忽略,保持展开
|
|
2394
|
+
if (keepAddFieldMenuOpenRef.current) {
|
|
2395
|
+
keepAddFieldMenuOpenRef.current = false;
|
|
2396
|
+
return;
|
|
2397
|
+
}
|
|
2398
|
+
setAddFieldMenuId(null);
|
|
2399
|
+
},
|
|
2400
|
+
trigger: ['hover', 'click'],
|
|
2265
2401
|
mouseEnterDelay: 0.1,
|
|
2266
2402
|
mouseLeaveDelay: 0.15,
|
|
2267
2403
|
getPopupContainer: trigger => trigger.parentElement || document.body,
|
|
@@ -2331,10 +2467,12 @@ const BlockListPanel = ({
|
|
|
2331
2467
|
size: "small",
|
|
2332
2468
|
icon: /*#__PURE__*/jsx(PlusOutlined, {}),
|
|
2333
2469
|
className: btnClass,
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2470
|
+
onMouseDown: () => {
|
|
2471
|
+
if (menuOpen) {
|
|
2472
|
+
keepAddFieldMenuOpenRef.current = true;
|
|
2473
|
+
}
|
|
2337
2474
|
},
|
|
2475
|
+
onClick: () => setAddFieldMenuId(menuKey),
|
|
2338
2476
|
children: formatMessage({
|
|
2339
2477
|
id: 'addField'
|
|
2340
2478
|
})
|
|
@@ -2420,6 +2558,7 @@ const BlockListPanel = ({
|
|
|
2420
2558
|
className: style['step-section-header'],
|
|
2421
2559
|
children: [/*#__PURE__*/jsxs(Space, {
|
|
2422
2560
|
size: 8,
|
|
2561
|
+
wrap: true,
|
|
2423
2562
|
className: style['step-section-title'],
|
|
2424
2563
|
children: [/*#__PURE__*/jsx("span", {
|
|
2425
2564
|
className: style['step-index'],
|
|
@@ -2444,45 +2583,50 @@ const BlockListPanel = ({
|
|
|
2444
2583
|
count: ((_step$list2 = step.list) == null ? void 0 : _step$list2.length) || 0
|
|
2445
2584
|
})
|
|
2446
2585
|
})]
|
|
2447
|
-
}), /*#__PURE__*/jsxs(
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2586
|
+
}), /*#__PURE__*/jsxs(Space, {
|
|
2587
|
+
size: 4,
|
|
2588
|
+
wrap: true,
|
|
2589
|
+
className: style['step-section-actions'],
|
|
2590
|
+
children: [/*#__PURE__*/jsxs(ActionGroup, {
|
|
2591
|
+
children: [/*#__PURE__*/jsx(IconBtn, {
|
|
2592
|
+
title: formatMessage({
|
|
2593
|
+
id: 'moveUp'
|
|
2594
|
+
}),
|
|
2595
|
+
icon: /*#__PURE__*/jsx(ArrowUpOutlined, {}),
|
|
2596
|
+
disabled: stepIndex === 0,
|
|
2597
|
+
onClick: () => onMoveStep(block.id, step.id, 'up')
|
|
2598
|
+
}), /*#__PURE__*/jsx(IconBtn, {
|
|
2599
|
+
title: formatMessage({
|
|
2600
|
+
id: 'moveDown'
|
|
2601
|
+
}),
|
|
2602
|
+
icon: /*#__PURE__*/jsx(ArrowDownOutlined, {}),
|
|
2603
|
+
disabled: stepIndex === (((_block$items = block.items) == null ? void 0 : _block$items.length) || 0) - 1,
|
|
2604
|
+
onClick: () => onMoveStep(block.id, step.id, 'down')
|
|
2605
|
+
}), /*#__PURE__*/jsx(IconBtn, {
|
|
2606
|
+
title: formatMessage({
|
|
2607
|
+
id: 'editStep'
|
|
2608
|
+
}),
|
|
2609
|
+
icon: /*#__PURE__*/jsx(EditOutlined, {}),
|
|
2610
|
+
onClick: () => onEditStep(block.id, step)
|
|
2611
|
+
}), /*#__PURE__*/jsx(IconBtn, {
|
|
2612
|
+
title: formatMessage({
|
|
2613
|
+
id: 'deleteStep'
|
|
2614
|
+
}),
|
|
2615
|
+
danger: true,
|
|
2616
|
+
icon: /*#__PURE__*/jsx(DeleteOutlined, {}),
|
|
2617
|
+
onClick: () => onDeleteStep(block.id, step.id)
|
|
2618
|
+
})]
|
|
2619
|
+
}), renderAddFieldButton({
|
|
2620
|
+
menuKey: `${block.id}:${step.id}`,
|
|
2621
|
+
depth,
|
|
2622
|
+
onAddFieldClick: () => onAddField(block.id, {
|
|
2623
|
+
stepId: step.id
|
|
2471
2624
|
}),
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2625
|
+
onAddChildBlock: kind => onAddBlock(kind, {
|
|
2626
|
+
parentBlockId: block.id,
|
|
2627
|
+
stepId: step.id
|
|
2628
|
+
})
|
|
2475
2629
|
})]
|
|
2476
|
-
}), renderAddFieldButton({
|
|
2477
|
-
menuKey: `${block.id}:${step.id}`,
|
|
2478
|
-
depth,
|
|
2479
|
-
onAddFieldClick: () => onAddField(block.id, {
|
|
2480
|
-
stepId: step.id
|
|
2481
|
-
}),
|
|
2482
|
-
onAddChildBlock: kind => onAddBlock(kind, {
|
|
2483
|
-
parentBlockId: block.id,
|
|
2484
|
-
stepId: step.id
|
|
2485
|
-
})
|
|
2486
2630
|
})]
|
|
2487
2631
|
}), renderFieldList(step.list, block.id, {
|
|
2488
2632
|
stepId: step.id
|
|
@@ -2540,6 +2684,7 @@ const BlockListPanel = ({
|
|
|
2540
2684
|
className: style['step-section-header'],
|
|
2541
2685
|
children: [/*#__PURE__*/jsxs(Space, {
|
|
2542
2686
|
size: 8,
|
|
2687
|
+
wrap: true,
|
|
2543
2688
|
className: style['step-section-title'],
|
|
2544
2689
|
children: [/*#__PURE__*/jsx("span", {
|
|
2545
2690
|
className: style['step-index'],
|
|
@@ -2564,45 +2709,50 @@ const BlockListPanel = ({
|
|
|
2564
2709
|
count: ((_option$list2 = option.list) == null ? void 0 : _option$list2.length) || 0
|
|
2565
2710
|
})
|
|
2566
2711
|
})]
|
|
2567
|
-
}), /*#__PURE__*/jsxs(
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2712
|
+
}), /*#__PURE__*/jsxs(Space, {
|
|
2713
|
+
size: 4,
|
|
2714
|
+
wrap: true,
|
|
2715
|
+
className: style['step-section-actions'],
|
|
2716
|
+
children: [/*#__PURE__*/jsxs(ActionGroup, {
|
|
2717
|
+
children: [/*#__PURE__*/jsx(IconBtn, {
|
|
2718
|
+
title: formatMessage({
|
|
2719
|
+
id: 'moveUp'
|
|
2720
|
+
}),
|
|
2721
|
+
icon: /*#__PURE__*/jsx(ArrowUpOutlined, {}),
|
|
2722
|
+
disabled: optionIndex === 0,
|
|
2723
|
+
onClick: () => onMoveChoiceOption(block.id, option.id, 'up')
|
|
2724
|
+
}), /*#__PURE__*/jsx(IconBtn, {
|
|
2725
|
+
title: formatMessage({
|
|
2726
|
+
id: 'moveDown'
|
|
2727
|
+
}),
|
|
2728
|
+
icon: /*#__PURE__*/jsx(ArrowDownOutlined, {}),
|
|
2729
|
+
disabled: optionIndex === (((_block$options = block.options) == null ? void 0 : _block$options.length) || 0) - 1,
|
|
2730
|
+
onClick: () => onMoveChoiceOption(block.id, option.id, 'down')
|
|
2731
|
+
}), /*#__PURE__*/jsx(IconBtn, {
|
|
2732
|
+
title: formatMessage({
|
|
2733
|
+
id: 'editChoiceOption'
|
|
2734
|
+
}),
|
|
2735
|
+
icon: /*#__PURE__*/jsx(EditOutlined, {}),
|
|
2736
|
+
onClick: () => onEditChoiceOption(block.id, option)
|
|
2737
|
+
}), /*#__PURE__*/jsx(IconBtn, {
|
|
2738
|
+
title: formatMessage({
|
|
2739
|
+
id: 'deleteChoiceOption'
|
|
2740
|
+
}),
|
|
2741
|
+
danger: true,
|
|
2742
|
+
icon: /*#__PURE__*/jsx(DeleteOutlined, {}),
|
|
2743
|
+
onClick: () => onDeleteChoiceOption(block.id, option.id)
|
|
2744
|
+
})]
|
|
2745
|
+
}), renderAddFieldButton({
|
|
2746
|
+
menuKey: `${block.id}:opt:${option.id}`,
|
|
2747
|
+
depth,
|
|
2748
|
+
onAddFieldClick: () => onAddField(block.id, {
|
|
2749
|
+
optionId: option.id
|
|
2585
2750
|
}),
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
id: 'deleteChoiceOption'
|
|
2591
|
-
}),
|
|
2592
|
-
danger: true,
|
|
2593
|
-
icon: /*#__PURE__*/jsx(DeleteOutlined, {}),
|
|
2594
|
-
onClick: () => onDeleteChoiceOption(block.id, option.id)
|
|
2751
|
+
onAddChildBlock: kind => onAddBlock(kind, {
|
|
2752
|
+
parentBlockId: block.id,
|
|
2753
|
+
optionId: option.id
|
|
2754
|
+
})
|
|
2595
2755
|
})]
|
|
2596
|
-
}), renderAddFieldButton({
|
|
2597
|
-
menuKey: `${block.id}:opt:${option.id}`,
|
|
2598
|
-
depth,
|
|
2599
|
-
onAddFieldClick: () => onAddField(block.id, {
|
|
2600
|
-
optionId: option.id
|
|
2601
|
-
}),
|
|
2602
|
-
onAddChildBlock: kind => onAddBlock(kind, {
|
|
2603
|
-
parentBlockId: block.id,
|
|
2604
|
-
optionId: option.id
|
|
2605
|
-
})
|
|
2606
2756
|
})]
|
|
2607
2757
|
}), renderFieldList(option.list, block.id, {
|
|
2608
2758
|
optionId: option.id
|
|
@@ -4612,7 +4762,7 @@ const resolveSelectedIds = (value, mode) => {
|
|
|
4612
4762
|
}
|
|
4613
4763
|
return [String(value)];
|
|
4614
4764
|
};
|
|
4615
|
-
const clearUnselectedOptionFields = (openApi, keepIds, allOptions) => {
|
|
4765
|
+
const clearUnselectedOptionFields = (openApi, formData, keepIds, allOptions) => {
|
|
4616
4766
|
if (!(openApi != null && openApi.setFields)) {
|
|
4617
4767
|
return;
|
|
4618
4768
|
}
|
|
@@ -4622,7 +4772,11 @@ const clearUnselectedOptionFields = (openApi, keepIds, allOptions) => {
|
|
|
4622
4772
|
return;
|
|
4623
4773
|
}
|
|
4624
4774
|
(option.list || []).forEach(field => {
|
|
4625
|
-
if (field != null && field.name) {
|
|
4775
|
+
if (!(field != null && field.name)) {
|
|
4776
|
+
return;
|
|
4777
|
+
}
|
|
4778
|
+
const current = getByPath(formData, field.name);
|
|
4779
|
+
if (current !== undefined) {
|
|
4626
4780
|
entries.push({
|
|
4627
4781
|
name: field.name,
|
|
4628
4782
|
value: undefined
|
|
@@ -4630,10 +4784,13 @@ const clearUnselectedOptionFields = (openApi, keepIds, allOptions) => {
|
|
|
4630
4784
|
}
|
|
4631
4785
|
});
|
|
4632
4786
|
collectBlockFieldNames(option.blocks || []).forEach(name => {
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4787
|
+
const current = getByPath(formData, name);
|
|
4788
|
+
if (current !== undefined) {
|
|
4789
|
+
entries.push({
|
|
4790
|
+
name,
|
|
4791
|
+
value: undefined
|
|
4792
|
+
});
|
|
4793
|
+
}
|
|
4637
4794
|
});
|
|
4638
4795
|
});
|
|
4639
4796
|
if (!entries.length) {
|
|
@@ -4710,14 +4867,16 @@ const ChoiceBlock = ({
|
|
|
4710
4867
|
maxLength
|
|
4711
4868
|
} = mode === 'multiple' ? resolveSelectLimits(block) : {};
|
|
4712
4869
|
const firstOptionId = options[0] != null ? String(options[0].id) : undefined;
|
|
4870
|
+
const rawValue = getByPath(formData || {}, selectorName);
|
|
4871
|
+
// 仅随 selector 值变化;勿依赖整个 formData,否则清空未选支字段会触发 options 重算 → CheckboxGroup 死循环
|
|
4872
|
+
const selectorValueKey = mode === 'multiple' ? Array.isArray(rawValue) ? rawValue.map(String).join('\0') : String(rawValue != null ? rawValue : '') : String(rawValue != null ? rawValue : '');
|
|
4713
4873
|
|
|
4714
4874
|
// 单选且未选时,写入第一项,保证预览/提交与选项面板一致
|
|
4715
4875
|
useEffect(() => {
|
|
4716
4876
|
if (mode !== 'single' || !firstOptionId || !(openApi != null && openApi.setFields)) {
|
|
4717
4877
|
return;
|
|
4718
4878
|
}
|
|
4719
|
-
|
|
4720
|
-
if (current != null && current !== '') {
|
|
4879
|
+
if (selectorValueKey !== '') {
|
|
4721
4880
|
return;
|
|
4722
4881
|
}
|
|
4723
4882
|
openApi.setFields([{
|
|
@@ -4726,11 +4885,10 @@ const ChoiceBlock = ({
|
|
|
4726
4885
|
}], {
|
|
4727
4886
|
runValidate: false
|
|
4728
4887
|
});
|
|
4729
|
-
}, [mode, firstOptionId, selectorName, openApi,
|
|
4888
|
+
}, [mode, firstOptionId, selectorName, openApi, selectorValueKey]);
|
|
4889
|
+
const selectedIdsFromValue = useMemo(() => resolveSelectedIds(rawValue, mode), [selectorValueKey, mode]);
|
|
4730
4890
|
const selectorOptions = useMemo(() => {
|
|
4731
|
-
const
|
|
4732
|
-
const selectedIds = resolveSelectedIds(rawValue, mode);
|
|
4733
|
-
const atMax = mode === 'multiple' && maxLength != null && selectedIds.length >= maxLength;
|
|
4891
|
+
const atMax = mode === 'multiple' && maxLength != null && selectedIdsFromValue.length >= maxLength;
|
|
4734
4892
|
return options.map((option, index) => {
|
|
4735
4893
|
const value = String(option.id);
|
|
4736
4894
|
return {
|
|
@@ -4740,17 +4898,16 @@ const ChoiceBlock = ({
|
|
|
4740
4898
|
index: index + 1
|
|
4741
4899
|
}) : `选项${index + 1}`),
|
|
4742
4900
|
value,
|
|
4743
|
-
disabled: atMax && !
|
|
4901
|
+
disabled: atMax && !selectedIdsFromValue.includes(value)
|
|
4744
4902
|
};
|
|
4745
4903
|
});
|
|
4746
|
-
}, [options, formatMessage,
|
|
4747
|
-
|
|
4748
|
-
let selectedIds = resolveSelectedIds(rawValue, mode);
|
|
4904
|
+
}, [options, formatMessage, selectedIdsFromValue, mode, maxLength]);
|
|
4905
|
+
let selectedIds = selectedIdsFromValue;
|
|
4749
4906
|
if (mode === 'single' && !selectedIds.length && firstOptionId) {
|
|
4750
4907
|
selectedIds = [firstOptionId];
|
|
4751
4908
|
}
|
|
4752
4909
|
const activeOptions = options.filter(option => selectedIds.includes(String(option.id)));
|
|
4753
|
-
const handleChange = value => {
|
|
4910
|
+
const handleChange = useCallback(value => {
|
|
4754
4911
|
let nextIds = resolveSelectedIds(value, mode);
|
|
4755
4912
|
if (mode === 'multiple' && maxLength != null && nextIds.length > maxLength) {
|
|
4756
4913
|
nextIds = nextIds.slice(0, maxLength);
|
|
@@ -4761,9 +4918,9 @@ const ChoiceBlock = ({
|
|
|
4761
4918
|
runValidate: false
|
|
4762
4919
|
});
|
|
4763
4920
|
}
|
|
4764
|
-
clearUnselectedOptionFields(openApi, nextIds, options);
|
|
4765
|
-
};
|
|
4766
|
-
const selectorRule =
|
|
4921
|
+
clearUnselectedOptionFields(openApi, formData, nextIds, options);
|
|
4922
|
+
}, [mode, maxLength, openApi, selectorName, formData, options]);
|
|
4923
|
+
const selectorRule = useCallback(value => {
|
|
4767
4924
|
const ids = resolveSelectedIds(value, 'multiple');
|
|
4768
4925
|
if (minLength != null && ids.length < minLength) {
|
|
4769
4926
|
return {
|
|
@@ -4789,10 +4946,11 @@ const ChoiceBlock = ({
|
|
|
4789
4946
|
result: true,
|
|
4790
4947
|
errMsg: ''
|
|
4791
4948
|
};
|
|
4792
|
-
}
|
|
4949
|
+
}, [minLength, maxLength, formatMessage]);
|
|
4950
|
+
const hasSelectLimitRule = mode === 'multiple' && (minLength != null || maxLength != null);
|
|
4793
4951
|
const Selector = mode === 'multiple' ? CheckboxGroup : RadioGroup;
|
|
4794
4952
|
const selectorProps = _extends({
|
|
4795
|
-
key:
|
|
4953
|
+
key: `choice-selector-${mode}`,
|
|
4796
4954
|
name: selectorName,
|
|
4797
4955
|
label: titleText || (formatMessage ? formatMessage({
|
|
4798
4956
|
id: 'choiceAreaTitle'
|
|
@@ -4800,14 +4958,17 @@ const ChoiceBlock = ({
|
|
|
4800
4958
|
labelHidden: true,
|
|
4801
4959
|
options: selectorOptions,
|
|
4802
4960
|
onChange: handleChange
|
|
4803
|
-
},
|
|
4961
|
+
}, hasSelectLimitRule ? {
|
|
4804
4962
|
rule: selectorRule
|
|
4805
4963
|
} : {}, mode === 'single' ? _extends({
|
|
4806
4964
|
optionType: 'button',
|
|
4807
4965
|
buttonStyle: 'solid'
|
|
4808
4966
|
}, firstOptionId ? {
|
|
4809
4967
|
defaultValue: firstOptionId
|
|
4810
|
-
} : {}) : {
|
|
4968
|
+
} : {}) : {
|
|
4969
|
+
// CheckboxGroup 需要数组初值,避免 undefined↔[] 来回同步
|
|
4970
|
+
defaultValue: []
|
|
4971
|
+
});
|
|
4811
4972
|
const contentChildren = [];
|
|
4812
4973
|
activeOptions.forEach(option => {
|
|
4813
4974
|
const nodes = (typeof renderOptionContent === 'function' ? renderOptionContent(option, {
|
|
@@ -5736,5 +5897,292 @@ const preset = ({
|
|
|
5736
5897
|
});
|
|
5737
5898
|
};
|
|
5738
5899
|
|
|
5739
|
-
|
|
5900
|
+
const createObjectLayer = () => ({
|
|
5901
|
+
properties: {},
|
|
5902
|
+
required: [],
|
|
5903
|
+
composites: []
|
|
5904
|
+
});
|
|
5905
|
+
const isReq = rule => parseRuleString(rule).presets.includes('REQ');
|
|
5906
|
+
const resolveChoiceSelectorName = block => {
|
|
5907
|
+
var _block$discriminator;
|
|
5908
|
+
if (block.selectorName != null && String(block.selectorName).trim()) {
|
|
5909
|
+
return String(block.selectorName).trim();
|
|
5910
|
+
}
|
|
5911
|
+
if ((_block$discriminator = block.discriminator) != null && _block$discriminator.propertyName) {
|
|
5912
|
+
return String(block.discriminator.propertyName).trim();
|
|
5913
|
+
}
|
|
5914
|
+
return `__choice_${block.id}`;
|
|
5915
|
+
};
|
|
5916
|
+
const mergeFieldIntoLayer = (layer, field, {
|
|
5917
|
+
allowRequired: _allowRequired = true
|
|
5918
|
+
} = {}) => {
|
|
5919
|
+
if (!(field != null && field.name)) {
|
|
5920
|
+
return;
|
|
5921
|
+
}
|
|
5922
|
+
const name = String(field.name).trim();
|
|
5923
|
+
if (!name) {
|
|
5924
|
+
return;
|
|
5925
|
+
}
|
|
5926
|
+
layer.properties[name] = resolveFieldValueSchema(field);
|
|
5927
|
+
if (_allowRequired && isReq(field.rule) && !layer.required.includes(name)) {
|
|
5928
|
+
layer.required.push(name);
|
|
5929
|
+
}
|
|
5930
|
+
};
|
|
5931
|
+
const mergeFieldsIntoLayer = (layer, fields, options) => {
|
|
5932
|
+
(fields || []).forEach(field => mergeFieldIntoLayer(layer, field, options));
|
|
5933
|
+
};
|
|
5934
|
+
const toFiniteInt = (value, minAllowed) => {
|
|
5935
|
+
if (value == null || value === '') {
|
|
5936
|
+
return undefined;
|
|
5937
|
+
}
|
|
5938
|
+
const num = Number(value);
|
|
5939
|
+
if (!Number.isFinite(num)) {
|
|
5940
|
+
return undefined;
|
|
5941
|
+
}
|
|
5942
|
+
const int = Math.floor(num);
|
|
5943
|
+
return int < minAllowed ? minAllowed : int;
|
|
5944
|
+
};
|
|
5945
|
+
const finalizeObjectSchema = (layer, {
|
|
5946
|
+
title,
|
|
5947
|
+
description
|
|
5948
|
+
} = {}) => {
|
|
5949
|
+
const schema = {
|
|
5950
|
+
type: 'object',
|
|
5951
|
+
properties: _extends({}, layer.properties)
|
|
5952
|
+
};
|
|
5953
|
+
if (layer.required.length) {
|
|
5954
|
+
schema.required = layer.required.slice();
|
|
5955
|
+
}
|
|
5956
|
+
if (title) {
|
|
5957
|
+
schema.title = title;
|
|
5958
|
+
}
|
|
5959
|
+
if (description) {
|
|
5960
|
+
schema.description = description;
|
|
5961
|
+
}
|
|
5962
|
+
if (layer.composites.length === 1) {
|
|
5963
|
+
Object.assign(schema, layer.composites[0]);
|
|
5964
|
+
} else if (layer.composites.length > 1) {
|
|
5965
|
+
schema.allOf = layer.composites.slice();
|
|
5966
|
+
}
|
|
5967
|
+
return schema;
|
|
5968
|
+
};
|
|
5969
|
+
const walkBlocks = (blocks, layer, depth = 0) => {
|
|
5970
|
+
(blocks || []).forEach(block => {
|
|
5971
|
+
if (!block) {
|
|
5972
|
+
return;
|
|
5973
|
+
}
|
|
5974
|
+
walkBlock(block, layer, depth);
|
|
5975
|
+
});
|
|
5976
|
+
};
|
|
5977
|
+
const walkBlock = (block, layer, depth = 0) => {
|
|
5978
|
+
switch (block.kind) {
|
|
5979
|
+
case 'formInfo':
|
|
5980
|
+
{
|
|
5981
|
+
mergeFieldsIntoLayer(layer, block.list);
|
|
5982
|
+
walkBlocks(block.blocks, layer, depth + 1);
|
|
5983
|
+
return;
|
|
5984
|
+
}
|
|
5985
|
+
case 'object':
|
|
5986
|
+
{
|
|
5987
|
+
const name = block.name != null && String(block.name).trim() ? String(block.name).trim() : '';
|
|
5988
|
+
if (!name) {
|
|
5989
|
+
mergeFieldsIntoLayer(layer, block.list);
|
|
5990
|
+
walkBlocks(block.blocks, layer, depth + 1);
|
|
5991
|
+
return;
|
|
5992
|
+
}
|
|
5993
|
+
const nested = createObjectLayer();
|
|
5994
|
+
mergeFieldsIntoLayer(nested, block.list);
|
|
5995
|
+
walkBlocks(block.blocks, nested, depth + 1);
|
|
5996
|
+
layer.properties[name] = finalizeObjectSchema(nested, {
|
|
5997
|
+
title: block.title || undefined,
|
|
5998
|
+
description: block.subtitle || undefined
|
|
5999
|
+
});
|
|
6000
|
+
return;
|
|
6001
|
+
}
|
|
6002
|
+
case 'list':
|
|
6003
|
+
case 'tableList':
|
|
6004
|
+
{
|
|
6005
|
+
const name = block.name != null && String(block.name).trim() ? String(block.name).trim() : '';
|
|
6006
|
+
if (!name) {
|
|
6007
|
+
return;
|
|
6008
|
+
}
|
|
6009
|
+
const itemLayer = createObjectLayer();
|
|
6010
|
+
mergeFieldsIntoLayer(itemLayer, block.list);
|
|
6011
|
+
if (block.kind === 'list') {
|
|
6012
|
+
walkBlocks(block.itemBlocks, itemLayer, depth + 1);
|
|
6013
|
+
}
|
|
6014
|
+
const items = finalizeObjectSchema(itemLayer);
|
|
6015
|
+
const arraySchema = {
|
|
6016
|
+
type: 'array',
|
|
6017
|
+
items
|
|
6018
|
+
};
|
|
6019
|
+
if (block.title) {
|
|
6020
|
+
arraySchema.title = block.title;
|
|
6021
|
+
}
|
|
6022
|
+
const minItems = toFiniteInt(block.minLength, 0);
|
|
6023
|
+
const maxItems = toFiniteInt(block.maxLength, 1);
|
|
6024
|
+
if (minItems != null) {
|
|
6025
|
+
arraySchema.minItems = minItems;
|
|
6026
|
+
}
|
|
6027
|
+
if (maxItems != null) {
|
|
6028
|
+
arraySchema.maxItems = maxItems;
|
|
6029
|
+
}
|
|
6030
|
+
layer.properties[name] = arraySchema;
|
|
6031
|
+
return;
|
|
6032
|
+
}
|
|
6033
|
+
case 'multiField':
|
|
6034
|
+
{
|
|
6035
|
+
const name = block.name != null && String(block.name).trim() ? String(block.name).trim() : '';
|
|
6036
|
+
if (!name) {
|
|
6037
|
+
return;
|
|
6038
|
+
}
|
|
6039
|
+
const itemField = {
|
|
6040
|
+
type: block.fieldType || 'Input',
|
|
6041
|
+
label: block.label,
|
|
6042
|
+
props: {}
|
|
6043
|
+
};
|
|
6044
|
+
const arraySchema = {
|
|
6045
|
+
type: 'array',
|
|
6046
|
+
items: resolveFieldValueSchema(itemField)
|
|
6047
|
+
};
|
|
6048
|
+
if (block.label) {
|
|
6049
|
+
arraySchema.title = block.label;
|
|
6050
|
+
}
|
|
6051
|
+
layer.properties[name] = arraySchema;
|
|
6052
|
+
return;
|
|
6053
|
+
}
|
|
6054
|
+
case 'steps':
|
|
6055
|
+
{
|
|
6056
|
+
(block.items || []).forEach(step => {
|
|
6057
|
+
mergeFieldsIntoLayer(layer, step == null ? void 0 : step.list);
|
|
6058
|
+
walkBlocks(step == null ? void 0 : step.blocks, layer, depth + 1);
|
|
6059
|
+
});
|
|
6060
|
+
return;
|
|
6061
|
+
}
|
|
6062
|
+
case 'choice':
|
|
6063
|
+
{
|
|
6064
|
+
mergeChoiceIntoLayer(layer, block, depth);
|
|
6065
|
+
return;
|
|
6066
|
+
}
|
|
6067
|
+
default:
|
|
6068
|
+
return;
|
|
6069
|
+
}
|
|
6070
|
+
};
|
|
6071
|
+
|
|
6072
|
+
/**
|
|
6073
|
+
* choice:single → oneOf;multiple → anyOf。
|
|
6074
|
+
* 每支为 object:单选支含 selector const;多选支为该 option 字段,selector 数组放在当前层。
|
|
6075
|
+
* 支内 REQ 可进 required;hidden 字段仍进入 schema。
|
|
6076
|
+
*/
|
|
6077
|
+
const mergeChoiceIntoLayer = (layer, block, depth) => {
|
|
6078
|
+
const mode = block.mode === 'multiple' ? 'multiple' : 'single';
|
|
6079
|
+
const selectorInData = block.selectorInData !== false;
|
|
6080
|
+
const selectorName = resolveChoiceSelectorName(block);
|
|
6081
|
+
const options = block.options || [];
|
|
6082
|
+
const optionIds = options.map(option => String(option.id));
|
|
6083
|
+
const branches = options.map((option, index) => {
|
|
6084
|
+
const branch = createObjectLayer();
|
|
6085
|
+
const optionTitle = option.title || `选项${index + 1}`;
|
|
6086
|
+
if (selectorInData && mode === 'single') {
|
|
6087
|
+
branch.properties[selectorName] = {
|
|
6088
|
+
const: String(option.id),
|
|
6089
|
+
title: optionTitle
|
|
6090
|
+
};
|
|
6091
|
+
branch.required.push(selectorName);
|
|
6092
|
+
}
|
|
6093
|
+
mergeFieldsIntoLayer(branch, option.list, {
|
|
6094
|
+
allowRequired: true
|
|
6095
|
+
});
|
|
6096
|
+
walkBlocks(option.blocks, branch, depth + 1);
|
|
6097
|
+
return finalizeObjectSchema(branch, {
|
|
6098
|
+
title: optionTitle
|
|
6099
|
+
});
|
|
6100
|
+
});
|
|
6101
|
+
if (!branches.length) {
|
|
6102
|
+
if (selectorInData) {
|
|
6103
|
+
if (mode === 'multiple') {
|
|
6104
|
+
const selectorSchema = {
|
|
6105
|
+
type: 'array',
|
|
6106
|
+
items: {
|
|
6107
|
+
type: 'string'
|
|
6108
|
+
},
|
|
6109
|
+
uniqueItems: true
|
|
6110
|
+
};
|
|
6111
|
+
if (block.title) {
|
|
6112
|
+
selectorSchema.title = block.title;
|
|
6113
|
+
}
|
|
6114
|
+
const minItems = toFiniteInt(block.minLength, 0);
|
|
6115
|
+
const maxItems = toFiniteInt(block.maxLength, 1);
|
|
6116
|
+
if (minItems != null) {
|
|
6117
|
+
selectorSchema.minItems = minItems;
|
|
6118
|
+
}
|
|
6119
|
+
if (maxItems != null) {
|
|
6120
|
+
selectorSchema.maxItems = maxItems;
|
|
6121
|
+
}
|
|
6122
|
+
layer.properties[selectorName] = selectorSchema;
|
|
6123
|
+
} else {
|
|
6124
|
+
layer.properties[selectorName] = {
|
|
6125
|
+
type: 'string',
|
|
6126
|
+
title: block.title || undefined
|
|
6127
|
+
};
|
|
6128
|
+
}
|
|
6129
|
+
}
|
|
6130
|
+
return;
|
|
6131
|
+
}
|
|
6132
|
+
if (mode === 'multiple') {
|
|
6133
|
+
if (selectorInData) {
|
|
6134
|
+
const selectorSchema = {
|
|
6135
|
+
type: 'array',
|
|
6136
|
+
items: _extends({
|
|
6137
|
+
type: 'string'
|
|
6138
|
+
}, optionIds.length ? {
|
|
6139
|
+
enum: optionIds
|
|
6140
|
+
} : {}),
|
|
6141
|
+
uniqueItems: true
|
|
6142
|
+
};
|
|
6143
|
+
if (block.title) {
|
|
6144
|
+
selectorSchema.title = block.title;
|
|
6145
|
+
}
|
|
6146
|
+
const minItems = toFiniteInt(block.minLength, 0);
|
|
6147
|
+
const maxItems = toFiniteInt(block.maxLength, 1);
|
|
6148
|
+
if (minItems != null) {
|
|
6149
|
+
selectorSchema.minItems = minItems;
|
|
6150
|
+
}
|
|
6151
|
+
if (maxItems != null) {
|
|
6152
|
+
selectorSchema.maxItems = maxItems;
|
|
6153
|
+
}
|
|
6154
|
+
layer.properties[selectorName] = selectorSchema;
|
|
6155
|
+
}
|
|
6156
|
+
layer.composites.push({
|
|
6157
|
+
anyOf: branches
|
|
6158
|
+
});
|
|
6159
|
+
return;
|
|
6160
|
+
}
|
|
6161
|
+
layer.composites.push({
|
|
6162
|
+
oneOf: branches
|
|
6163
|
+
});
|
|
6164
|
+
};
|
|
6165
|
+
|
|
6166
|
+
/**
|
|
6167
|
+
* 将搭建 Schema 转为描述表单提交数据形状的 JSON Schema。
|
|
6168
|
+
* - 内置字段:fieldRegistry.valueSchema
|
|
6169
|
+
* - 扩展字段:registerField / preset 的 valueSchema;缺省 { type: 'string' }
|
|
6170
|
+
* - hidden 字段仍进入 data schema(可提交)
|
|
6171
|
+
* - choice:single → oneOf,multiple → anyOf
|
|
6172
|
+
*/
|
|
6173
|
+
const schemaToDataSchema = (schema, options = {}) => {
|
|
6174
|
+
const normalized = normalizeSchema(schema || {});
|
|
6175
|
+
const layer = createObjectLayer();
|
|
6176
|
+
walkBlocks(normalized.blocks, layer, 0);
|
|
6177
|
+
const root = finalizeObjectSchema(layer, {
|
|
6178
|
+
title: normalized.title || undefined,
|
|
6179
|
+
description: options.description
|
|
6180
|
+
});
|
|
6181
|
+
if (options.$schema) {
|
|
6182
|
+
root.$schema = options.$schema;
|
|
6183
|
+
}
|
|
6184
|
+
return root;
|
|
6185
|
+
};
|
|
6186
|
+
|
|
6187
|
+
export { FormCreator$1 as FormCreator, MAX_BLOCK_DEPTH, RULE_LEN_PRESET, RULE_PRESET_ITEMS, SchemaRenderer$1 as SchemaRenderer, SchemaRendererInner, applyFromPropsSchema, blockToFormValues, buildRuleString, collectBlockFieldNames, collectSchemaFields, createBlock, createChoiceOption, createField$1 as createField, createFieldId, createStep, FormCreator$1 as default, defaultFormActions, defaultSchema, fieldToFormValues, findBlock, findBlockInTree, formValuesToBlock, formValuesToField, getBlockDefinition, getBlockKindOptions, getFieldComponent, getFieldDefinition, getFieldTypes, getRulePresetItems, hasRenderableContent, isFieldNameUnique, mapBlocks, moveBlockInTree, moveItem, normalizeBlock, normalizeFormActions, normalizeOptions, normalizeSchema, parseRuleString, pickFieldProps, pickFromPropsSchema, preset, removeBlockInTree, resolveFieldValueSchema, schemaToDataSchema, updateBlocks };
|
|
5740
6188
|
//# sourceMappingURL=index.modern.js.map
|