@kne/form-creator 0.1.17 → 0.1.18
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 +171 -73
- package/dist/index.js +156 -75
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +154 -75
- package/dist/index.modern.js.map +1 -1
- package/dist/locale/en-US.js +21 -0
- package/dist/locale/en-US.js.map +1 -1
- package/dist/locale/en-US.modern.js +21 -0
- package/dist/locale/en-US.modern.js.map +1 -1
- package/dist/locale/zh-CN.js +21 -0
- package/dist/locale/zh-CN.js.map +1 -1
- package/dist/locale/zh-CN.modern.js +21 -0
- package/dist/locale/zh-CN.modern.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -662,87 +662,95 @@ render(<NestedChoiceExample />);
|
|
|
662
662
|
const { default: FormCreator, preset, defaultSchema, createBlock, createField } = _FormCreator;
|
|
663
663
|
const { Rate, Slider } = _ReactFormAntd;
|
|
664
664
|
const { default: JsonView } = _JsonView;
|
|
665
|
-
const { useState } = React;
|
|
665
|
+
const { useRef, useState } = React;
|
|
666
666
|
const { Alert, Typography, Space } = antd;
|
|
667
667
|
const { Text, Paragraph } = Typography;
|
|
668
668
|
|
|
669
|
-
|
|
670
|
-
preset
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
}
|
|
687
|
-
},
|
|
688
|
-
fields: {
|
|
689
|
-
Rate: {
|
|
690
|
-
label: '评分',
|
|
691
|
-
groupName: '评价组件',
|
|
692
|
-
component: Rate,
|
|
693
|
-
defaultProps: { count: 5, allowHalf: false, allowClear: true },
|
|
694
|
-
valueSchema: { type: 'number' },
|
|
695
|
-
propsSchema: [
|
|
696
|
-
{
|
|
697
|
-
name: 'count',
|
|
698
|
-
label: '星星总数',
|
|
699
|
-
type: 'number',
|
|
700
|
-
min: 1,
|
|
701
|
-
max: 10,
|
|
702
|
-
defaultValue: 5
|
|
703
|
-
},
|
|
704
|
-
{
|
|
705
|
-
name: 'allowHalf',
|
|
706
|
-
label: '允许半星',
|
|
707
|
-
type: 'boolean',
|
|
708
|
-
defaultValue: false
|
|
709
|
-
},
|
|
710
|
-
{
|
|
711
|
-
name: 'allowClear',
|
|
712
|
-
label: '允许清除',
|
|
713
|
-
type: 'boolean',
|
|
714
|
-
defaultValue: true
|
|
669
|
+
const applyPresetOnce = () => {
|
|
670
|
+
// 勿放在模块顶层:modules-dev 会加载全部示例,顶层 preset 会污染其它示例的 Field Type 下拉
|
|
671
|
+
preset({
|
|
672
|
+
rules: {
|
|
673
|
+
ID_CARD: {
|
|
674
|
+
label: '身份证格式',
|
|
675
|
+
reg: /^\d{17}[\dXx]$/,
|
|
676
|
+
message: '%s格式不正确'
|
|
677
|
+
},
|
|
678
|
+
RATE_MIN: {
|
|
679
|
+
label: '评分至少3星',
|
|
680
|
+
validator: value => {
|
|
681
|
+
const score = Number(value) || 0;
|
|
682
|
+
return {
|
|
683
|
+
result: score >= 3,
|
|
684
|
+
errMsg: score >= 3 ? '' : '评分至少 3 星'
|
|
685
|
+
};
|
|
715
686
|
}
|
|
716
|
-
|
|
687
|
+
}
|
|
717
688
|
},
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
689
|
+
fields: {
|
|
690
|
+
Rate: {
|
|
691
|
+
label: '评分',
|
|
692
|
+
groupName: '评价组件',
|
|
693
|
+
component: Rate,
|
|
694
|
+
defaultProps: { count: 5, allowHalf: false, allowClear: true },
|
|
695
|
+
valueSchema: { type: 'number' },
|
|
696
|
+
propsSchema: [
|
|
697
|
+
{
|
|
698
|
+
name: 'count',
|
|
699
|
+
label: '星星总数',
|
|
700
|
+
type: 'number',
|
|
701
|
+
min: 1,
|
|
702
|
+
max: 10,
|
|
703
|
+
defaultValue: 5
|
|
704
|
+
},
|
|
705
|
+
{
|
|
706
|
+
name: 'allowHalf',
|
|
707
|
+
label: '允许半星',
|
|
708
|
+
type: 'boolean',
|
|
709
|
+
defaultValue: false
|
|
710
|
+
},
|
|
711
|
+
{
|
|
712
|
+
name: 'allowClear',
|
|
713
|
+
label: '允许清除',
|
|
714
|
+
type: 'boolean',
|
|
715
|
+
defaultValue: true
|
|
716
|
+
}
|
|
717
|
+
]
|
|
718
|
+
},
|
|
719
|
+
Slider: {
|
|
720
|
+
label: '滑块',
|
|
721
|
+
component: Slider,
|
|
722
|
+
defaultProps: { min: 0, max: 100, step: 1 },
|
|
723
|
+
valueSchema: { type: 'number' },
|
|
724
|
+
propsSchema: [
|
|
725
|
+
{ name: 'min', label: '最小值', type: 'number', defaultValue: 0 },
|
|
726
|
+
{ name: 'max', label: '最大值', type: 'number', defaultValue: 100 },
|
|
727
|
+
{ name: 'step', label: '步长', type: 'number', min: 0, defaultValue: 1 },
|
|
728
|
+
{
|
|
729
|
+
name: 'tooltipPlacement',
|
|
730
|
+
label: '提示位置',
|
|
731
|
+
type: 'select',
|
|
732
|
+
defaultValue: 'top',
|
|
733
|
+
options: [
|
|
734
|
+
{ label: '上', value: 'top' },
|
|
735
|
+
{ label: '下', value: 'bottom' },
|
|
736
|
+
{ label: '左', value: 'left' },
|
|
737
|
+
{ label: '右', value: 'right' }
|
|
738
|
+
]
|
|
739
|
+
},
|
|
740
|
+
{ name: 'dots', label: '显示刻度点', type: 'boolean', defaultValue: false }
|
|
741
|
+
]
|
|
742
|
+
}
|
|
741
743
|
}
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
+
});
|
|
745
|
+
};
|
|
744
746
|
|
|
745
747
|
const PresetExtendExample = () => {
|
|
748
|
+
const presetReady = useRef(false);
|
|
749
|
+
if (!presetReady.current) {
|
|
750
|
+
applyPresetOnce();
|
|
751
|
+
presetReady.current = true;
|
|
752
|
+
}
|
|
753
|
+
|
|
746
754
|
const [schema, setSchema] = useState(() => ({
|
|
747
755
|
...defaultSchema(),
|
|
748
756
|
blocks: [
|
|
@@ -1352,6 +1360,96 @@ render(<FormInfoFieldExample />);
|
|
|
1352
1360
|
|
|
1353
1361
|
```
|
|
1354
1362
|
|
|
1363
|
+
- 语言切换(全屏)
|
|
1364
|
+
- FormCreator locale prop 切换中/英;检查内置 Field Type 分组与选项、列表类型 Tag、Select/DatePicker 占位
|
|
1365
|
+
- _FormCreator(@kne/current-lib_form-creator)[import * as _FormCreator from "@kne/form-creator"],(@kne/current-lib_form-creator/dist/index.css)[import "@kne/form-creator/dist/index.css"],antd(antd)[import antd from "antd"]
|
|
1366
|
+
|
|
1367
|
+
```jsx
|
|
1368
|
+
const { default: FormCreator, defaultSchema, createBlock, createField } = _FormCreator;
|
|
1369
|
+
const { useState } = React;
|
|
1370
|
+
const { Radio, Space, Typography, Alert } = antd;
|
|
1371
|
+
|
|
1372
|
+
const { Text, Paragraph } = Typography;
|
|
1373
|
+
|
|
1374
|
+
const demoSchema = () => ({
|
|
1375
|
+
...defaultSchema(),
|
|
1376
|
+
blocks: [
|
|
1377
|
+
createBlock('formInfo', {
|
|
1378
|
+
title: 'Basic Info',
|
|
1379
|
+
column: 2,
|
|
1380
|
+
list: [
|
|
1381
|
+
createField({
|
|
1382
|
+
type: 'Input',
|
|
1383
|
+
name: 'name',
|
|
1384
|
+
label: 'Name',
|
|
1385
|
+
rule: 'REQ'
|
|
1386
|
+
}),
|
|
1387
|
+
createField({
|
|
1388
|
+
type: 'Select',
|
|
1389
|
+
name: 'city',
|
|
1390
|
+
label: 'City',
|
|
1391
|
+
props: {
|
|
1392
|
+
options: [
|
|
1393
|
+
{ label: 'Shanghai', value: 'sh' },
|
|
1394
|
+
{ label: 'Beijing', value: 'bj' }
|
|
1395
|
+
]
|
|
1396
|
+
}
|
|
1397
|
+
}),
|
|
1398
|
+
createField({
|
|
1399
|
+
type: 'DatePicker',
|
|
1400
|
+
name: 'birthday',
|
|
1401
|
+
label: 'Birthday'
|
|
1402
|
+
})
|
|
1403
|
+
]
|
|
1404
|
+
})
|
|
1405
|
+
]
|
|
1406
|
+
});
|
|
1407
|
+
|
|
1408
|
+
/**
|
|
1409
|
+
* 通过 FormCreator 的 locale prop 切换语言,检查:
|
|
1410
|
+
* - 编辑器壳层文案(Add Section / Field Type 等)
|
|
1411
|
+
* - 内置 Field Type 分组与选项(Single-line Text / Dropdown)
|
|
1412
|
+
* - 左侧列表字段类型 Tag、Select/DatePicker 默认占位
|
|
1413
|
+
*
|
|
1414
|
+
* 注意:扩展字段(Rate/Slider)若曾打开过「preset 扩展」示例,会残留中文 label;
|
|
1415
|
+
* 那是全局 registry 污染,不在本示例内重注册(避免热更新循环)。
|
|
1416
|
+
*/
|
|
1417
|
+
const LocaleSwitchExample = () => {
|
|
1418
|
+
const [locale, setLocale] = useState('en-US');
|
|
1419
|
+
const [schema, setSchema] = useState(demoSchema);
|
|
1420
|
+
|
|
1421
|
+
return (
|
|
1422
|
+
<Space direction="vertical" size={16} style={{ width: '100%' }}>
|
|
1423
|
+
<Alert
|
|
1424
|
+
type="info"
|
|
1425
|
+
showIcon
|
|
1426
|
+
message="Language switch"
|
|
1427
|
+
description={
|
|
1428
|
+
<Paragraph style={{ marginBottom: 0 }}>
|
|
1429
|
+
Toggle locale, then open <Text code>Edit Field</Text> and check built-in <Text strong>Field Type</Text>{' '}
|
|
1430
|
+
groups/options, type tags, and Select/DatePicker placeholders.
|
|
1431
|
+
</Paragraph>
|
|
1432
|
+
}
|
|
1433
|
+
/>
|
|
1434
|
+
<Radio.Group
|
|
1435
|
+
optionType="button"
|
|
1436
|
+
buttonStyle="solid"
|
|
1437
|
+
value={locale}
|
|
1438
|
+
onChange={e => setLocale(e.target.value)}
|
|
1439
|
+
options={[
|
|
1440
|
+
{ label: '中文', value: 'zh-CN' },
|
|
1441
|
+
{ label: 'English', value: 'en-US' }
|
|
1442
|
+
]}
|
|
1443
|
+
/>
|
|
1444
|
+
<FormCreator key={locale} locale={locale} value={schema} onChange={setSchema} />
|
|
1445
|
+
</Space>
|
|
1446
|
+
);
|
|
1447
|
+
};
|
|
1448
|
+
|
|
1449
|
+
render(<LocaleSwitchExample />);
|
|
1450
|
+
|
|
1451
|
+
```
|
|
1452
|
+
|
|
1355
1453
|
### API
|
|
1356
1454
|
|
|
1357
1455
|
| 属性 | 类型 | 默认值 | 说明 |
|