amis-core 2.6.0 → 2.7.0
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/package.json +2 -2
- package/esm/Root.d.ts +0 -46
- package/esm/Root.js +0 -89
- package/esm/RootRenderer.d.ts +0 -27
- package/esm/RootRenderer.js +0 -279
- package/esm/SchemaRenderer.d.ts +0 -37
- package/esm/SchemaRenderer.js +0 -332
- package/esm/Scoped.d.ts +0 -38
- package/esm/Scoped.js +0 -262
- package/esm/WithRootStore.d.ts +0 -719
- package/esm/WithRootStore.js +0 -34
- package/esm/WithStore.d.ts +0 -5
- package/esm/WithStore.js +0 -181
- package/esm/actions/Action.d.ts +0 -40
- package/esm/actions/Action.js +0 -186
- package/esm/actions/AjaxAction.d.ts +0 -27
- package/esm/actions/AjaxAction.js +0 -96
- package/esm/actions/BreakAction.d.ts +0 -15
- package/esm/actions/BreakAction.js +0 -31
- package/esm/actions/BroadcastAction.d.ts +0 -19
- package/esm/actions/BroadcastAction.js +0 -46
- package/esm/actions/CmptAction.d.ts +0 -21
- package/esm/actions/CmptAction.js +0 -66
- package/esm/actions/ContinueAction.d.ts +0 -15
- package/esm/actions/ContinueAction.js +0 -31
- package/esm/actions/CopyAction.d.ts +0 -20
- package/esm/actions/CopyAction.js +0 -39
- package/esm/actions/CustomAction.d.ts +0 -22
- package/esm/actions/CustomAction.js +0 -74
- package/esm/actions/DialogAction.d.ts +0 -60
- package/esm/actions/DialogAction.js +0 -101
- package/esm/actions/DrawerAction.d.ts +0 -33
- package/esm/actions/DrawerAction.js +0 -65
- package/esm/actions/EmailAction.d.ts +0 -23
- package/esm/actions/EmailAction.js +0 -39
- package/esm/actions/LinkAction.d.ts +0 -24
- package/esm/actions/LinkAction.js +0 -43
- package/esm/actions/LoopAction.d.ts +0 -19
- package/esm/actions/LoopAction.js +0 -103
- package/esm/actions/PageAction.d.ts +0 -39
- package/esm/actions/PageAction.js +0 -74
- package/esm/actions/ParallelAction.d.ts +0 -8
- package/esm/actions/ParallelAction.js +0 -36
- package/esm/actions/SwitchAction.d.ts +0 -11
- package/esm/actions/SwitchAction.js +0 -48
- package/esm/actions/ToastAction.d.ts +0 -19
- package/esm/actions/ToastAction.js +0 -31
- package/esm/actions/index.d.ts +0 -20
- package/esm/components/LazyComponent.d.ts +0 -32
- package/esm/components/LazyComponent.js +0 -90
- package/esm/components/Overlay.d.ts +0 -44
- package/esm/components/Overlay.js +0 -255
- package/esm/components/PopOver.d.ts +0 -90
- package/esm/components/PopOver.js +0 -120
- package/esm/env.d.ts +0 -176
- package/esm/env.js +0 -12
- package/esm/envOverwrite.d.ts +0 -4
- package/esm/envOverwrite.js +0 -39
- package/esm/factory.d.ts +0 -85
- package/esm/factory.js +0 -301
- package/esm/index.d.ts +0 -44
- package/esm/index.js +0 -174
- package/esm/locale.d.ts +0 -84
- package/esm/locale.js +0 -117
- package/esm/renderers/Form.d.ts +0 -389
- package/esm/renderers/Form.js +0 -1221
- package/esm/renderers/Item.d.ts +0 -906
- package/esm/renderers/Item.js +0 -863
- package/esm/renderers/Options.d.ts +0 -158
- package/esm/renderers/Options.js +0 -908
- package/esm/renderers/Placeholder.d.ts +0 -6
- package/esm/renderers/Placeholder.js +0 -23
- package/esm/renderers/builtin.d.ts +0 -1
- package/esm/renderers/builtin.js +0 -25
- package/esm/renderers/register.d.ts +0 -6
- package/esm/renderers/register.js +0 -79
- package/esm/renderers/wrapControl.d.ts +0 -437
- package/esm/renderers/wrapControl.js +0 -509
- package/esm/store/app.d.ts +0 -92
- package/esm/store/app.js +0 -189
- package/esm/store/combo.d.ts +0 -10223
- package/esm/store/combo.js +0 -149
- package/esm/store/crud.d.ts +0 -128
- package/esm/store/crud.js +0 -447
- package/esm/store/form.d.ts +0 -4252
- package/esm/store/form.js +0 -650
- package/esm/store/formItem.d.ts +0 -133
- package/esm/store/formItem.js +0 -847
- package/esm/store/iRenderer.d.ts +0 -46
- package/esm/store/iRenderer.js +0 -185
- package/esm/store/index.d.ts +0 -125
- package/esm/store/index.js +0 -90
- package/esm/store/list.d.ts +0 -272
- package/esm/store/list.js +0 -246
- package/esm/store/manager.d.ts +0 -115
- package/esm/store/manager.js +0 -49
- package/esm/store/modal.d.ts +0 -84
- package/esm/store/modal.js +0 -50
- package/esm/store/node.d.ts +0 -22
- package/esm/store/node.js +0 -89
- package/esm/store/pagination.d.ts +0 -58
- package/esm/store/pagination.js +0 -56
- package/esm/store/root.d.ts +0 -85
- package/esm/store/root.js +0 -53
- package/esm/store/service.d.ts +0 -71
- package/esm/store/service.js +0 -411
- package/esm/store/table.d.ts +0 -10085
- package/esm/store/table.js +0 -1136
- package/esm/store/table2.d.ts +0 -474
- package/esm/store/table2.js +0 -560
- package/esm/theme.d.ts +0 -89
- package/esm/theme.js +0 -127
- package/esm/types.d.ts +0 -489
- package/esm/utils/Animation.d.ts +0 -22
- package/esm/utils/Animation.js +0 -285
- package/esm/utils/ColorScale.d.ts +0 -19
- package/esm/utils/ColorScale.js +0 -100
- package/esm/utils/DataSchema.d.ts +0 -25
- package/esm/utils/DataSchema.js +0 -112
- package/esm/utils/DataScope.d.ts +0 -26
- package/esm/utils/DataScope.js +0 -158
- package/esm/utils/RootClose.d.ts +0 -4
- package/esm/utils/RootClose.js +0 -22
- package/esm/utils/SimpleMap.d.ts +0 -8
- package/esm/utils/SimpleMap.js +0 -37
- package/esm/utils/api.d.ts +0 -34
- package/esm/utils/api.js +0 -595
- package/esm/utils/attachmentAdpator.d.ts +0 -8
- package/esm/utils/attachmentAdpator.js +0 -86
- package/esm/utils/autobind.d.ts +0 -7
- package/esm/utils/autobind.js +0 -89
- package/esm/utils/columnsSplit.d.ts +0 -1
- package/esm/utils/columnsSplit.js +0 -42
- package/esm/utils/dataMapping.d.ts +0 -9
- package/esm/utils/dataMapping.js +0 -141
- package/esm/utils/date.d.ts +0 -4
- package/esm/utils/date.js +0 -80
- package/esm/utils/debug.d.ts +0 -29
- package/esm/utils/debug.js +0 -379
- package/esm/utils/decodeEntity.d.ts +0 -5
- package/esm/utils/decodeEntity.js +0 -16
- package/esm/utils/dom.d.ts +0 -13
- package/esm/utils/dom.js +0 -188
- package/esm/utils/errors.d.ts +0 -6
- package/esm/utils/errors.js +0 -19
- package/esm/utils/escapeHtml.d.ts +0 -1
- package/esm/utils/escapeHtml.js +0 -20
- package/esm/utils/filter-schema.d.ts +0 -13
- package/esm/utils/filter-schema.js +0 -68
- package/esm/utils/filter.d.ts +0 -1
- package/esm/utils/filter.js +0 -493
- package/esm/utils/formatDuration.d.ts +0 -1
- package/esm/utils/formatDuration.js +0 -23
- package/esm/utils/formula.d.ts +0 -16
- package/esm/utils/formula.js +0 -219
- package/esm/utils/getVariable.d.ts +0 -3
- package/esm/utils/getVariable.js +0 -25
- package/esm/utils/grammar.d.ts +0 -4
- package/esm/utils/grammar.js +0 -50
- package/esm/utils/handleAction.d.ts +0 -7
- package/esm/utils/handleAction.js +0 -34
- package/esm/utils/helper.d.ts +0 -323
- package/esm/utils/helper.js +0 -1261
- package/esm/utils/highlight.d.ts +0 -1
- package/esm/utils/highlight.js +0 -44
- package/esm/utils/icon.d.ts +0 -16
- package/esm/utils/icon.js +0 -35
- package/esm/utils/image.d.ts +0 -18
- package/esm/utils/image.js +0 -47
- package/esm/utils/index.d.ts +0 -55
- package/esm/utils/isPureVariable.d.ts +0 -1
- package/esm/utils/isPureVariable.js +0 -22
- package/esm/utils/json-schema-2-amis-schema.d.ts +0 -6
- package/esm/utils/json-schema-2-amis-schema.js +0 -56
- package/esm/utils/keyToPath.d.ts +0 -6
- package/esm/utils/keyToPath.js +0 -30
- package/esm/utils/makeSorter.d.ts +0 -1
- package/esm/utils/makeSorter.js +0 -26
- package/esm/utils/normalizeLink.d.ts +0 -1
- package/esm/utils/normalizeLink.js +0 -43
- package/esm/utils/normalizeOptions.d.ts +0 -7
- package/esm/utils/normalizeOptions.js +0 -84
- package/esm/utils/object.d.ts +0 -15
- package/esm/utils/object.js +0 -142
- package/esm/utils/offset.d.ts +0 -15
- package/esm/utils/offset.js +0 -32
- package/esm/utils/offsetParent.d.ts +0 -5
- package/esm/utils/offsetParent.js +0 -23
- package/esm/utils/optionValueCompare.d.ts +0 -3
- package/esm/utils/optionValueCompare.js +0 -25
- package/esm/utils/position.d.ts +0 -26
- package/esm/utils/position.js +0 -54
- package/esm/utils/prettyBytes.d.ts +0 -1
- package/esm/utils/prettyBytes.js +0 -25
- package/esm/utils/renderer-event.d.ts +0 -62
- package/esm/utils/renderer-event.js +0 -206
- package/esm/utils/replaceText.d.ts +0 -3
- package/esm/utils/replaceText.js +0 -38
- package/esm/utils/resize-sensor.d.ts +0 -6
- package/esm/utils/resize-sensor.js +0 -172
- package/esm/utils/resolveVariable.d.ts +0 -1
- package/esm/utils/resolveVariable.js +0 -35
- package/esm/utils/resolveVariableAndFilter.d.ts +0 -1
- package/esm/utils/resolveVariableAndFilter.js +0 -33
- package/esm/utils/scrollPosition.d.ts +0 -16
- package/esm/utils/scrollPosition.js +0 -33
- package/esm/utils/string2regExp.d.ts +0 -1
- package/esm/utils/string2regExp.js +0 -14
- package/esm/utils/stripNumber.d.ts +0 -1
- package/esm/utils/stripNumber.js +0 -16
- package/esm/utils/style.d.ts +0 -10
- package/esm/utils/style.js +0 -58
- package/esm/utils/toNumber.d.ts +0 -7
- package/esm/utils/toNumber.js +0 -18
- package/esm/utils/tokenize.d.ts +0 -1
- package/esm/utils/tokenize.js +0 -29
- package/esm/utils/tpl-builtin.d.ts +0 -18
- package/esm/utils/tpl-builtin.js +0 -59
- package/esm/utils/tpl-lodash.d.ts +0 -4
- package/esm/utils/tpl-lodash.js +0 -62
- package/esm/utils/tpl.d.ts +0 -11
- package/esm/utils/tpl.js +0 -131
- package/esm/utils/uncontrollable.d.ts +0 -4
- package/esm/utils/uncontrollable.js +0 -14
- package/esm/utils/validations.d.ts +0 -39
- package/esm/utils/validations.js +0 -440
- package/lib/Root.d.ts +0 -46
- package/lib/Root.js +0 -102
- package/lib/RootRenderer.d.ts +0 -27
- package/lib/RootRenderer.js +0 -290
- package/lib/SchemaRenderer.d.ts +0 -37
- package/lib/SchemaRenderer.js +0 -342
- package/lib/Scoped.d.ts +0 -38
- package/lib/Scoped.js +0 -274
- package/lib/WithRootStore.d.ts +0 -719
- package/lib/WithRootStore.js +0 -44
- package/lib/WithStore.d.ts +0 -5
- package/lib/WithStore.js +0 -190
- package/lib/actions/Action.d.ts +0 -40
- package/lib/actions/Action.js +0 -197
- package/lib/actions/AjaxAction.d.ts +0 -27
- package/lib/actions/AjaxAction.js +0 -100
- package/lib/actions/BreakAction.d.ts +0 -15
- package/lib/actions/BreakAction.js +0 -35
- package/lib/actions/BroadcastAction.d.ts +0 -19
- package/lib/actions/BroadcastAction.js +0 -50
- package/lib/actions/CmptAction.d.ts +0 -21
- package/lib/actions/CmptAction.js +0 -70
- package/lib/actions/ContinueAction.d.ts +0 -15
- package/lib/actions/ContinueAction.js +0 -35
- package/lib/actions/CopyAction.d.ts +0 -20
- package/lib/actions/CopyAction.js +0 -43
- package/lib/actions/CustomAction.d.ts +0 -22
- package/lib/actions/CustomAction.js +0 -78
- package/lib/actions/DialogAction.d.ts +0 -60
- package/lib/actions/DialogAction.js +0 -108
- package/lib/actions/DrawerAction.d.ts +0 -33
- package/lib/actions/DrawerAction.js +0 -70
- package/lib/actions/EmailAction.d.ts +0 -23
- package/lib/actions/EmailAction.js +0 -48
- package/lib/actions/LinkAction.d.ts +0 -24
- package/lib/actions/LinkAction.js +0 -47
- package/lib/actions/LoopAction.d.ts +0 -19
- package/lib/actions/LoopAction.js +0 -107
- package/lib/actions/PageAction.d.ts +0 -39
- package/lib/actions/PageAction.js +0 -80
- package/lib/actions/ParallelAction.d.ts +0 -8
- package/lib/actions/ParallelAction.js +0 -40
- package/lib/actions/SwitchAction.d.ts +0 -11
- package/lib/actions/SwitchAction.js +0 -52
- package/lib/actions/ToastAction.d.ts +0 -19
- package/lib/actions/ToastAction.js +0 -35
- package/lib/actions/index.d.ts +0 -20
- package/lib/components/LazyComponent.d.ts +0 -32
- package/lib/components/LazyComponent.js +0 -99
- package/lib/components/Overlay.d.ts +0 -44
- package/lib/components/Overlay.js +0 -266
- package/lib/components/PopOver.d.ts +0 -90
- package/lib/components/PopOver.js +0 -129
- package/lib/env.d.ts +0 -176
- package/lib/env.js +0 -20
- package/lib/envOverwrite.d.ts +0 -4
- package/lib/envOverwrite.js +0 -43
- package/lib/factory.d.ts +0 -85
- package/lib/factory.js +0 -324
- package/lib/index.d.ts +0 -44
- package/lib/index.js +0 -460
- package/lib/locale.d.ts +0 -84
- package/lib/locale.js +0 -133
- package/lib/renderers/Form.d.ts +0 -389
- package/lib/renderers/Form.js +0 -1234
- package/lib/renderers/Item.d.ts +0 -906
- package/lib/renderers/Item.js +0 -879
- package/lib/renderers/Options.d.ts +0 -158
- package/lib/renderers/Options.js +0 -920
- package/lib/renderers/Placeholder.d.ts +0 -6
- package/lib/renderers/Placeholder.js +0 -31
- package/lib/renderers/builtin.d.ts +0 -1
- package/lib/renderers/builtin.js +0 -27
- package/lib/renderers/register.d.ts +0 -6
- package/lib/renderers/register.js +0 -83
- package/lib/renderers/wrapControl.d.ts +0 -437
- package/lib/renderers/wrapControl.js +0 -520
- package/lib/store/app.d.ts +0 -92
- package/lib/store/app.js +0 -193
- package/lib/store/combo.d.ts +0 -10223
- package/lib/store/combo.js +0 -154
- package/lib/store/crud.d.ts +0 -128
- package/lib/store/crud.js +0 -455
- package/lib/store/form.d.ts +0 -4252
- package/lib/store/form.js +0 -664
- package/lib/store/formItem.d.ts +0 -133
- package/lib/store/formItem.js +0 -858
- package/lib/store/iRenderer.d.ts +0 -46
- package/lib/store/iRenderer.js +0 -189
- package/lib/store/index.d.ts +0 -125
- package/lib/store/index.js +0 -101
- package/lib/store/list.d.ts +0 -272
- package/lib/store/list.js +0 -256
- package/lib/store/manager.d.ts +0 -115
- package/lib/store/manager.js +0 -56
- package/lib/store/modal.d.ts +0 -84
- package/lib/store/modal.js +0 -54
- package/lib/store/node.d.ts +0 -22
- package/lib/store/node.js +0 -93
- package/lib/store/pagination.d.ts +0 -58
- package/lib/store/pagination.js +0 -60
- package/lib/store/root.d.ts +0 -85
- package/lib/store/root.js +0 -57
- package/lib/store/service.d.ts +0 -71
- package/lib/store/service.js +0 -415
- package/lib/store/table.d.ts +0 -10085
- package/lib/store/table.js +0 -1148
- package/lib/store/table2.d.ts +0 -474
- package/lib/store/table2.js +0 -571
- package/lib/theme.d.ts +0 -89
- package/lib/theme.js +0 -145
- package/lib/types.d.ts +0 -489
- package/lib/utils/Animation.d.ts +0 -22
- package/lib/utils/Animation.js +0 -290
- package/lib/utils/ColorScale.d.ts +0 -19
- package/lib/utils/ColorScale.js +0 -105
- package/lib/utils/DataSchema.d.ts +0 -25
- package/lib/utils/DataSchema.js +0 -116
- package/lib/utils/DataScope.d.ts +0 -26
- package/lib/utils/DataScope.js +0 -162
- package/lib/utils/RootClose.d.ts +0 -4
- package/lib/utils/RootClose.js +0 -30
- package/lib/utils/SimpleMap.d.ts +0 -8
- package/lib/utils/SimpleMap.js +0 -46
- package/lib/utils/api.d.ts +0 -34
- package/lib/utils/api.js +0 -621
- package/lib/utils/attachmentAdpator.d.ts +0 -8
- package/lib/utils/attachmentAdpator.js +0 -91
- package/lib/utils/autobind.d.ts +0 -7
- package/lib/utils/autobind.js +0 -94
- package/lib/utils/columnsSplit.d.ts +0 -1
- package/lib/utils/columnsSplit.js +0 -51
- package/lib/utils/dataMapping.d.ts +0 -9
- package/lib/utils/dataMapping.js +0 -151
- package/lib/utils/date.d.ts +0 -4
- package/lib/utils/date.js +0 -90
- package/lib/utils/debug.d.ts +0 -29
- package/lib/utils/debug.js +0 -392
- package/lib/utils/decodeEntity.d.ts +0 -5
- package/lib/utils/decodeEntity.js +0 -20
- package/lib/utils/dom.d.ts +0 -13
- package/lib/utils/dom.js +0 -199
- package/lib/utils/errors.d.ts +0 -6
- package/lib/utils/errors.js +0 -23
- package/lib/utils/escapeHtml.d.ts +0 -1
- package/lib/utils/escapeHtml.js +0 -24
- package/lib/utils/filter-schema.d.ts +0 -13
- package/lib/utils/filter-schema.js +0 -78
- package/lib/utils/filter.d.ts +0 -1
- package/lib/utils/filter.js +0 -503
- package/lib/utils/formatDuration.d.ts +0 -1
- package/lib/utils/formatDuration.js +0 -27
- package/lib/utils/formula.d.ts +0 -16
- package/lib/utils/formula.js +0 -234
- package/lib/utils/getVariable.d.ts +0 -3
- package/lib/utils/getVariable.js +0 -29
- package/lib/utils/grammar.d.ts +0 -4
- package/lib/utils/grammar.js +0 -54
- package/lib/utils/handleAction.d.ts +0 -7
- package/lib/utils/handleAction.js +0 -39
- package/lib/utils/helper.d.ts +0 -323
- package/lib/utils/helper.js +0 -1361
- package/lib/utils/highlight.d.ts +0 -1
- package/lib/utils/highlight.js +0 -52
- package/lib/utils/icon.d.ts +0 -16
- package/lib/utils/icon.js +0 -43
- package/lib/utils/image.d.ts +0 -18
- package/lib/utils/image.js +0 -56
- package/lib/utils/index.d.ts +0 -55
- package/lib/utils/isPureVariable.d.ts +0 -1
- package/lib/utils/isPureVariable.js +0 -26
- package/lib/utils/json-schema-2-amis-schema.d.ts +0 -6
- package/lib/utils/json-schema-2-amis-schema.js +0 -60
- package/lib/utils/keyToPath.d.ts +0 -6
- package/lib/utils/keyToPath.js +0 -34
- package/lib/utils/makeSorter.d.ts +0 -1
- package/lib/utils/makeSorter.js +0 -30
- package/lib/utils/normalizeLink.d.ts +0 -1
- package/lib/utils/normalizeLink.js +0 -47
- package/lib/utils/normalizeOptions.d.ts +0 -7
- package/lib/utils/normalizeOptions.js +0 -92
- package/lib/utils/object.d.ts +0 -15
- package/lib/utils/object.js +0 -156
- package/lib/utils/offset.d.ts +0 -15
- package/lib/utils/offset.js +0 -37
- package/lib/utils/offsetParent.d.ts +0 -5
- package/lib/utils/offsetParent.js +0 -28
- package/lib/utils/optionValueCompare.d.ts +0 -3
- package/lib/utils/optionValueCompare.js +0 -30
- package/lib/utils/position.d.ts +0 -26
- package/lib/utils/position.js +0 -59
- package/lib/utils/prettyBytes.d.ts +0 -1
- package/lib/utils/prettyBytes.js +0 -29
- package/lib/utils/renderer-event.d.ts +0 -62
- package/lib/utils/renderer-event.js +0 -218
- package/lib/utils/replaceText.d.ts +0 -3
- package/lib/utils/replaceText.js +0 -46
- package/lib/utils/resize-sensor.d.ts +0 -6
- package/lib/utils/resize-sensor.js +0 -177
- package/lib/utils/resolveVariable.d.ts +0 -1
- package/lib/utils/resolveVariable.js +0 -39
- package/lib/utils/resolveVariableAndFilter.d.ts +0 -1
- package/lib/utils/resolveVariableAndFilter.js +0 -37
- package/lib/utils/scrollPosition.d.ts +0 -16
- package/lib/utils/scrollPosition.js +0 -37
- package/lib/utils/string2regExp.d.ts +0 -1
- package/lib/utils/string2regExp.js +0 -18
- package/lib/utils/stripNumber.d.ts +0 -1
- package/lib/utils/stripNumber.js +0 -20
- package/lib/utils/style.d.ts +0 -10
- package/lib/utils/style.js +0 -67
- package/lib/utils/toNumber.d.ts +0 -7
- package/lib/utils/toNumber.js +0 -22
- package/lib/utils/tokenize.d.ts +0 -1
- package/lib/utils/tokenize.js +0 -33
- package/lib/utils/tpl-builtin.d.ts +0 -18
- package/lib/utils/tpl-builtin.js +0 -75
- package/lib/utils/tpl-lodash.d.ts +0 -4
- package/lib/utils/tpl-lodash.js +0 -71
- package/lib/utils/tpl.d.ts +0 -11
- package/lib/utils/tpl.js +0 -140
- package/lib/utils/uncontrollable.d.ts +0 -4
- package/lib/utils/uncontrollable.js +0 -22
- package/lib/utils/validations.d.ts +0 -39
- package/lib/utils/validations.js +0 -455
package/esm/renderers/Form.js
DELETED
|
@@ -1,1221 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* amis-core v2.6.0
|
|
3
|
-
* Copyright 2018-2022 fex
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { __extends, __awaiter, __generator, __assign, __decorate, __metadata } from 'tslib';
|
|
7
|
-
import React from 'react';
|
|
8
|
-
import extend from 'lodash/extend';
|
|
9
|
-
import { Renderer } from '../factory.js';
|
|
10
|
-
import { FormStore } from '../store/form.js';
|
|
11
|
-
import { evalExpression, filter } from '../utils/tpl.js';
|
|
12
|
-
import { getExprProperties } from '../utils/filter-schema.js';
|
|
13
|
-
import { promisify, isEmpty, until, noop, isVisible, SkipOperation, difference, repeatCount, qsparse, isObjectShallowModified } from '../utils/helper.js';
|
|
14
|
-
import debounce from 'lodash/debounce';
|
|
15
|
-
import flatten from 'lodash/flatten';
|
|
16
|
-
import find from 'lodash/find';
|
|
17
|
-
import { ScopedContext } from '../Scoped.js';
|
|
18
|
-
import 'amis-formula';
|
|
19
|
-
import 'moment';
|
|
20
|
-
import { isObject, createObject, cloneObject } from '../utils/object.js';
|
|
21
|
-
import { getVariable } from '../utils/getVariable.js';
|
|
22
|
-
import { dataMapping } from '../utils/dataMapping.js';
|
|
23
|
-
import '../utils/filter.js';
|
|
24
|
-
import { isEffectiveApi, isApiOutdated } from '../utils/api.js';
|
|
25
|
-
import LazyComponent from '../components/LazyComponent.js';
|
|
26
|
-
import { isAlive } from 'mobx-state-tree';
|
|
27
|
-
|
|
28
|
-
var Form = /** @class */ (function (_super) {
|
|
29
|
-
__extends(Form, _super);
|
|
30
|
-
function Form(props) {
|
|
31
|
-
var _this = _super.call(this, props) || this;
|
|
32
|
-
_this.hooks = {};
|
|
33
|
-
_this.shouldLoadInitApi = false;
|
|
34
|
-
_this.lazyEmitChange = debounce(_this.emitChange.bind(_this), 250, {
|
|
35
|
-
trailing: true,
|
|
36
|
-
leading: false
|
|
37
|
-
});
|
|
38
|
-
_this.onInit = _this.onInit.bind(_this);
|
|
39
|
-
_this.handleAction = _this.handleAction.bind(_this);
|
|
40
|
-
_this.handleQuery = _this.handleQuery.bind(_this);
|
|
41
|
-
_this.handleChange = _this.handleChange.bind(_this);
|
|
42
|
-
_this.handleDialogConfirm = _this.handleDialogConfirm.bind(_this);
|
|
43
|
-
_this.handleDialogClose = _this.handleDialogClose.bind(_this);
|
|
44
|
-
_this.handleDrawerConfirm = _this.handleDrawerConfirm.bind(_this);
|
|
45
|
-
_this.handleDrawerClose = _this.handleDrawerClose.bind(_this);
|
|
46
|
-
_this.handleFormSubmit = _this.handleFormSubmit.bind(_this);
|
|
47
|
-
_this.validate = _this.validate.bind(_this);
|
|
48
|
-
_this.submit = _this.submit.bind(_this);
|
|
49
|
-
_this.addHook = _this.addHook.bind(_this);
|
|
50
|
-
_this.removeHook = _this.removeHook.bind(_this);
|
|
51
|
-
_this.emitChange = _this.emitChange.bind(_this);
|
|
52
|
-
_this.handleBulkChange = _this.handleBulkChange.bind(_this);
|
|
53
|
-
_this.renderFormItems = _this.renderFormItems.bind(_this);
|
|
54
|
-
_this.reload = _this.reload.bind(_this);
|
|
55
|
-
_this.silentReload = _this.silentReload.bind(_this);
|
|
56
|
-
_this.initInterval = _this.initInterval.bind(_this);
|
|
57
|
-
_this.blockRouting = _this.blockRouting.bind(_this);
|
|
58
|
-
_this.beforePageUnload = _this.beforePageUnload.bind(_this);
|
|
59
|
-
var store = props.store, canAccessSuperData = props.canAccessSuperData, persistData = props.persistData, simpleMode = props.simpleMode;
|
|
60
|
-
store.setCanAccessSuperData(canAccessSuperData !== false);
|
|
61
|
-
store.setPersistData(persistData);
|
|
62
|
-
if (simpleMode) {
|
|
63
|
-
store.setInited(true);
|
|
64
|
-
}
|
|
65
|
-
if (store &&
|
|
66
|
-
store.parentStore &&
|
|
67
|
-
store.parentStore.storeType === 'ComboStore') {
|
|
68
|
-
var combo = store.parentStore;
|
|
69
|
-
combo.addForm(store);
|
|
70
|
-
combo.forms.forEach(function (form) {
|
|
71
|
-
return form.items.forEach(function (item) { return item.unique && item.syncOptions(undefined, form.data); });
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
return _this;
|
|
75
|
-
}
|
|
76
|
-
Form.prototype.componentDidMount = function () {
|
|
77
|
-
var _this = this;
|
|
78
|
-
var _a, _b;
|
|
79
|
-
var _c = this.props, initApi = _c.initApi, initFetch = _c.initFetch, initFetchOn = _c.initFetchOn, initAsyncApi = _c.initAsyncApi, initFinishedField = _c.initFinishedField, initCheckInterval = _c.initCheckInterval, store = _c.store, _d = _c.messages, fetchSuccess = _d.fetchSuccess, fetchFailed = _d.fetchFailed, onValidate = _c.onValidate, promptPageLeave = _c.promptPageLeave, env = _c.env, rules = _c.rules;
|
|
80
|
-
this.mounted = true;
|
|
81
|
-
if (onValidate) {
|
|
82
|
-
var finalValidate_1 = promisify(onValidate);
|
|
83
|
-
this.disposeOnValidate = this.addHook(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
84
|
-
var result;
|
|
85
|
-
return __generator(this, function (_a) {
|
|
86
|
-
switch (_a.label) {
|
|
87
|
-
case 0: return [4 /*yield*/, finalValidate_1(store.data, store)];
|
|
88
|
-
case 1:
|
|
89
|
-
result = _a.sent();
|
|
90
|
-
if (result && isObject(result)) {
|
|
91
|
-
Object.keys(result).forEach(function (key) {
|
|
92
|
-
var msg = result[key];
|
|
93
|
-
var items = store.getItemsByPath(key);
|
|
94
|
-
// 没有找到
|
|
95
|
-
if (!Array.isArray(items) || !items.length) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
// 在setError之前,提前把残留的error信息清除掉,否则每次onValidate后都会一直把报错 append 上去
|
|
99
|
-
items.forEach(function (item) { return item.clearError(); });
|
|
100
|
-
if (msg) {
|
|
101
|
-
msg = Array.isArray(msg) ? msg : [msg];
|
|
102
|
-
items.forEach(function (item) { return item.addError(msg); });
|
|
103
|
-
}
|
|
104
|
-
delete result[key];
|
|
105
|
-
});
|
|
106
|
-
isEmpty(result)
|
|
107
|
-
? store.clearRestError()
|
|
108
|
-
: store.setRestError(Object.keys(result).map(function (key) { return result[key]; }));
|
|
109
|
-
}
|
|
110
|
-
return [2 /*return*/];
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
}); });
|
|
114
|
-
}
|
|
115
|
-
if (Array.isArray(rules) && rules.length) {
|
|
116
|
-
this.disposeRulesValidate = this.addHook(function () {
|
|
117
|
-
if (!store.valid) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
rules.forEach(function (item) {
|
|
121
|
-
return !evalExpression(item.rule, store.data) &&
|
|
122
|
-
store.addRestError(item.message, item.name);
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
if (isEffectiveApi(initApi, store.data, initFetch, initFetchOn)) {
|
|
127
|
-
store
|
|
128
|
-
.fetchInitData(initApi, store.data, {
|
|
129
|
-
successMessage: fetchSuccess,
|
|
130
|
-
errorMessage: fetchFailed,
|
|
131
|
-
onSuccess: function () {
|
|
132
|
-
if (!isEffectiveApi(initAsyncApi, store.data) ||
|
|
133
|
-
store.data[initFinishedField || 'finished']) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
return until(function () { return store.checkRemote(initAsyncApi, store.data); }, function (ret) { return ret && ret[initFinishedField || 'finished']; }, function (cancel) { return (_this.asyncCancel = cancel); }, initCheckInterval);
|
|
137
|
-
}
|
|
138
|
-
})
|
|
139
|
-
.then(this.initInterval)
|
|
140
|
-
.then(this.onInit);
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
setTimeout(this.onInit.bind(this), 4);
|
|
144
|
-
}
|
|
145
|
-
if (promptPageLeave) {
|
|
146
|
-
window.addEventListener('beforeunload', this.beforePageUnload);
|
|
147
|
-
this.unBlockRouting = (_b = (_a = env.blockRouting) === null || _a === void 0 ? void 0 : _a.call(env, this.blockRouting)) !== null && _b !== void 0 ? _b : undefined;
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
Form.prototype.componentDidUpdate = function (prevProps) {
|
|
151
|
-
var props = this.props;
|
|
152
|
-
var store = props.store;
|
|
153
|
-
if (isApiOutdated(prevProps.initApi, props.initApi, prevProps.data, props.data)) {
|
|
154
|
-
var fetchSuccess = props.fetchSuccess, fetchFailed = props.fetchFailed;
|
|
155
|
-
store[store.hasRemoteData ? 'fetchData' : 'fetchInitData'](props.initApi, store.data, {
|
|
156
|
-
successMessage: fetchSuccess,
|
|
157
|
-
errorMessage: fetchFailed
|
|
158
|
-
}).then(this.initInterval);
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
Form.prototype.componentWillUnmount = function () {
|
|
162
|
-
var _a;
|
|
163
|
-
this.mounted = false;
|
|
164
|
-
clearTimeout(this.timer);
|
|
165
|
-
// this.lazyHandleChange.flush();
|
|
166
|
-
this.lazyEmitChange.cancel();
|
|
167
|
-
this.asyncCancel && this.asyncCancel();
|
|
168
|
-
this.disposeOnValidate && this.disposeOnValidate();
|
|
169
|
-
this.disposeRulesValidate && this.disposeRulesValidate();
|
|
170
|
-
window.removeEventListener('beforeunload', this.beforePageUnload);
|
|
171
|
-
(_a = this.unBlockRouting) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
172
|
-
};
|
|
173
|
-
Form.prototype.blockRouting = function () {
|
|
174
|
-
var store = this.props.store;
|
|
175
|
-
var _a = this.props, promptPageLeaveMessage = _a.promptPageLeaveMessage, promptPageLeave = _a.promptPageLeave;
|
|
176
|
-
if (promptPageLeave && store.modified) {
|
|
177
|
-
return promptPageLeaveMessage || '新的修改没有保存,确认要离开?';
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
Form.prototype.beforePageUnload = function (e) {
|
|
181
|
-
var blocked = this.blockRouting();
|
|
182
|
-
if (blocked) {
|
|
183
|
-
e.preventDefault();
|
|
184
|
-
e.returnValue = '';
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
Form.prototype.onInit = function () {
|
|
188
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
189
|
-
var _a, onInit, store, persistData, submitOnInit, dispatchEvent, data, initedAt, hooks, dispatcher;
|
|
190
|
-
return __generator(this, function (_b) {
|
|
191
|
-
switch (_b.label) {
|
|
192
|
-
case 0:
|
|
193
|
-
_a = this.props, onInit = _a.onInit, store = _a.store, persistData = _a.persistData, submitOnInit = _a.submitOnInit, dispatchEvent = _a.dispatchEvent;
|
|
194
|
-
if (!isAlive(store)) {
|
|
195
|
-
return [2 /*return*/];
|
|
196
|
-
}
|
|
197
|
-
data = cloneObject(store.data);
|
|
198
|
-
initedAt = store.initedAt;
|
|
199
|
-
store.setInited(true);
|
|
200
|
-
hooks = this.hooks['init'] || [];
|
|
201
|
-
return [4 /*yield*/, Promise.all(hooks.map(function (hook) { return hook(data); }))];
|
|
202
|
-
case 1:
|
|
203
|
-
_b.sent();
|
|
204
|
-
if (!isAlive(store)) {
|
|
205
|
-
return [2 /*return*/];
|
|
206
|
-
}
|
|
207
|
-
if (store.initedAt !== initedAt) {
|
|
208
|
-
// 说明,之前的数据已经失效了。
|
|
209
|
-
// 比如 combo 一开始设置了初始值,然后 form 的 initApi 又返回了新的值。
|
|
210
|
-
// 这个时候 store 的数据应该已经 init 了新的值。但是 data 还是老的,这个时候
|
|
211
|
-
// onInit 出去就是错误的。
|
|
212
|
-
data = __assign(__assign({}, data), store.data);
|
|
213
|
-
}
|
|
214
|
-
if (persistData) {
|
|
215
|
-
store.getLocalPersistData();
|
|
216
|
-
data = cloneObject(store.data);
|
|
217
|
-
}
|
|
218
|
-
return [4 /*yield*/, dispatchEvent('inited', createObject(this.props.data, data))];
|
|
219
|
-
case 2:
|
|
220
|
-
dispatcher = _b.sent();
|
|
221
|
-
if (!(dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.prevented)) {
|
|
222
|
-
onInit && onInit(data, this.props);
|
|
223
|
-
}
|
|
224
|
-
submitOnInit &&
|
|
225
|
-
this.handleAction(undefined, {
|
|
226
|
-
type: 'submit'
|
|
227
|
-
}, store.data);
|
|
228
|
-
return [2 /*return*/];
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
};
|
|
233
|
-
Form.prototype.reload = function (subPath, query, ctx, silent) {
|
|
234
|
-
var _a;
|
|
235
|
-
var _this = this;
|
|
236
|
-
if (query) {
|
|
237
|
-
return this.receive(query);
|
|
238
|
-
}
|
|
239
|
-
var _b = this.props, store = _b.store, initApi = _b.initApi, initAsyncApi = _b.initAsyncApi, initFinishedField = _b.initFinishedField, _c = _b.messages, fetchSuccess = _c.fetchSuccess, fetchFailed = _c.fetchFailed;
|
|
240
|
-
isEffectiveApi(initAsyncApi, store.data) &&
|
|
241
|
-
store.updateData((_a = {},
|
|
242
|
-
_a[initFinishedField || 'finished'] = false,
|
|
243
|
-
_a));
|
|
244
|
-
isEffectiveApi(initApi, store.data)
|
|
245
|
-
? store
|
|
246
|
-
.fetchInitData(initApi, store.data, {
|
|
247
|
-
successMessage: fetchSuccess,
|
|
248
|
-
errorMessage: fetchFailed,
|
|
249
|
-
silent: silent,
|
|
250
|
-
onSuccess: function () {
|
|
251
|
-
if (!isEffectiveApi(initAsyncApi, store.data) ||
|
|
252
|
-
store.data[initFinishedField || 'finished']) {
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
return until(function () { return store.checkRemote(initAsyncApi, store.data); }, function (ret) { return ret && ret[initFinishedField || 'finished']; }, function (cancel) { return (_this.asyncCancel = cancel); });
|
|
256
|
-
}
|
|
257
|
-
})
|
|
258
|
-
.then(function (result) {
|
|
259
|
-
if (result === null || result === void 0 ? void 0 : result.ok) {
|
|
260
|
-
_this.initInterval(result);
|
|
261
|
-
store.reset(undefined, false);
|
|
262
|
-
}
|
|
263
|
-
})
|
|
264
|
-
: store.reset(undefined, false);
|
|
265
|
-
};
|
|
266
|
-
Form.prototype.receive = function (values, name, replace) {
|
|
267
|
-
var store = this.props.store;
|
|
268
|
-
store.updateData(values, undefined, replace);
|
|
269
|
-
this.reload();
|
|
270
|
-
};
|
|
271
|
-
Form.prototype.silentReload = function (target, query) {
|
|
272
|
-
this.reload(target, query, undefined, true);
|
|
273
|
-
};
|
|
274
|
-
Form.prototype.initInterval = function (value) {
|
|
275
|
-
var _a = this.props, interval = _a.interval, silentPolling = _a.silentPolling, stopAutoRefreshWhen = _a.stopAutoRefreshWhen, data = _a.data;
|
|
276
|
-
clearTimeout(this.timer);
|
|
277
|
-
interval &&
|
|
278
|
-
this.mounted &&
|
|
279
|
-
(!stopAutoRefreshWhen || !evalExpression(stopAutoRefreshWhen, data)) &&
|
|
280
|
-
(this.timer = setTimeout(silentPolling ? this.silentReload : this.reload, Math.max(interval, 1000)));
|
|
281
|
-
return value;
|
|
282
|
-
};
|
|
283
|
-
Form.prototype.isValidated = function () {
|
|
284
|
-
return this.props.store.validated;
|
|
285
|
-
};
|
|
286
|
-
Form.prototype.validate = function (forceValidate) {
|
|
287
|
-
var _a = this.props, store = _a.store, dispatchEvent = _a.dispatchEvent, data = _a.data;
|
|
288
|
-
this.flush();
|
|
289
|
-
return store
|
|
290
|
-
.validate(this.hooks['validate'] || [], forceValidate)
|
|
291
|
-
.then(function (result) {
|
|
292
|
-
if (result) {
|
|
293
|
-
dispatchEvent('validateSucc', data);
|
|
294
|
-
}
|
|
295
|
-
else {
|
|
296
|
-
dispatchEvent('validateError', data);
|
|
297
|
-
}
|
|
298
|
-
return result;
|
|
299
|
-
});
|
|
300
|
-
};
|
|
301
|
-
Form.prototype.setErrors = function (errors, tag) {
|
|
302
|
-
if (tag === void 0) { tag = 'remote'; }
|
|
303
|
-
var store = this.props.store;
|
|
304
|
-
store.setFormItemErrors(errors, tag);
|
|
305
|
-
};
|
|
306
|
-
Form.prototype.clearErrors = function () {
|
|
307
|
-
var store = this.props.store;
|
|
308
|
-
return store.clearErrors();
|
|
309
|
-
};
|
|
310
|
-
Form.prototype.getValues = function () {
|
|
311
|
-
var store = this.props.store;
|
|
312
|
-
this.flush();
|
|
313
|
-
return store.data;
|
|
314
|
-
};
|
|
315
|
-
Form.prototype.setValues = function (value, replace) {
|
|
316
|
-
var store = this.props.store;
|
|
317
|
-
this.flush();
|
|
318
|
-
store.setValues(value, undefined, replace);
|
|
319
|
-
};
|
|
320
|
-
Form.prototype.submit = function (fn) {
|
|
321
|
-
var _a = this.props, store = _a.store, messages = _a.messages, __ = _a.translate, dispatchEvent = _a.dispatchEvent, data = _a.data;
|
|
322
|
-
this.flush();
|
|
323
|
-
var validateErrCb = function () { return dispatchEvent('validateError', data); };
|
|
324
|
-
return store.submit(fn, this.hooks['validate'] || [], __(messages && messages.validateFailed), validateErrCb);
|
|
325
|
-
};
|
|
326
|
-
// 如果开启了 lazyChange,需要一个 flush 方法把队列中值应用上。
|
|
327
|
-
Form.prototype.flush = function () {
|
|
328
|
-
var hooks = this.hooks['flush'] || [];
|
|
329
|
-
hooks.forEach(function (fn) { return fn(); });
|
|
330
|
-
this.lazyEmitChange.flush();
|
|
331
|
-
};
|
|
332
|
-
Form.prototype.reset = function () {
|
|
333
|
-
var _a = this.props, store = _a.store, onReset = _a.onReset;
|
|
334
|
-
store.reset(onReset);
|
|
335
|
-
};
|
|
336
|
-
Form.prototype.addHook = function (fn, type) {
|
|
337
|
-
var _this = this;
|
|
338
|
-
if (type === void 0) { type = 'validate'; }
|
|
339
|
-
this.hooks[type] = this.hooks[type] || [];
|
|
340
|
-
this.hooks[type].push(type === 'flush' ? fn : promisify(fn));
|
|
341
|
-
return function () {
|
|
342
|
-
_this.removeHook(fn, type);
|
|
343
|
-
fn = noop;
|
|
344
|
-
};
|
|
345
|
-
};
|
|
346
|
-
Form.prototype.removeHook = function (fn, type) {
|
|
347
|
-
if (type === void 0) { type = 'validate'; }
|
|
348
|
-
var hooks = this.hooks[type];
|
|
349
|
-
if (!hooks) {
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
for (var i = 0, len = hooks.length; i < len; i++) {
|
|
353
|
-
var hook = hooks[i];
|
|
354
|
-
if (hook === fn || hook.raw === fn) {
|
|
355
|
-
hooks.splice(i, 1);
|
|
356
|
-
len--;
|
|
357
|
-
i--;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
};
|
|
361
|
-
Form.prototype.handleChange = function (value, name, submit, changePristine) {
|
|
362
|
-
if (changePristine === void 0) { changePristine = false; }
|
|
363
|
-
var _a = this.props, store = _a.store, formLazyChange = _a.formLazyChange, persistDataKeys = _a.persistDataKeys;
|
|
364
|
-
if (typeof name !== 'string') {
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
store.changeValue(name, value, changePristine);
|
|
368
|
-
if (!changePristine) {
|
|
369
|
-
(formLazyChange === false ? this.emitChange : this.lazyEmitChange)(submit);
|
|
370
|
-
}
|
|
371
|
-
if (store.persistData && store.inited) {
|
|
372
|
-
store.setLocalPersistData(persistDataKeys);
|
|
373
|
-
}
|
|
374
|
-
};
|
|
375
|
-
Form.prototype.formItemDispatchEvent = function (dispatchEvent) {
|
|
376
|
-
return function (type, data) {
|
|
377
|
-
dispatchEvent(type, data);
|
|
378
|
-
};
|
|
379
|
-
};
|
|
380
|
-
Form.prototype.emitChange = function (submit) {
|
|
381
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
382
|
-
var _a, onChange, store, submitOnChange, dispatchEvent, data, dispatcher;
|
|
383
|
-
return __generator(this, function (_b) {
|
|
384
|
-
switch (_b.label) {
|
|
385
|
-
case 0:
|
|
386
|
-
_a = this.props, onChange = _a.onChange, store = _a.store, submitOnChange = _a.submitOnChange, dispatchEvent = _a.dispatchEvent, data = _a.data;
|
|
387
|
-
if (!isAlive(store)) {
|
|
388
|
-
return [2 /*return*/];
|
|
389
|
-
}
|
|
390
|
-
return [4 /*yield*/, dispatchEvent('change', createObject(data, store.data))];
|
|
391
|
-
case 1:
|
|
392
|
-
dispatcher = _b.sent();
|
|
393
|
-
if (!(dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.prevented)) {
|
|
394
|
-
onChange &&
|
|
395
|
-
onChange(store.data, difference(store.data, store.pristine), this.props);
|
|
396
|
-
}
|
|
397
|
-
store.clearRestError();
|
|
398
|
-
(submit || (submitOnChange && store.inited)) &&
|
|
399
|
-
this.handleAction(undefined, {
|
|
400
|
-
type: 'submit'
|
|
401
|
-
}, store.data);
|
|
402
|
-
return [2 /*return*/];
|
|
403
|
-
}
|
|
404
|
-
});
|
|
405
|
-
});
|
|
406
|
-
};
|
|
407
|
-
Form.prototype.handleBulkChange = function (values, submit) {
|
|
408
|
-
var _a = this.props; _a.onChange; var store = _a.store, formLazyChange = _a.formLazyChange;
|
|
409
|
-
store.updateData(values);
|
|
410
|
-
store.items.forEach(function (formItem) {
|
|
411
|
-
var updatedValue = getVariable(values, formItem.name, false);
|
|
412
|
-
if (updatedValue !== undefined) {
|
|
413
|
-
// 更新验证状态但保留错误信息
|
|
414
|
-
formItem.reset(true);
|
|
415
|
-
// 这里需要更新value,否则提交时不会使用新的字段值校验
|
|
416
|
-
formItem.changeTmpValue(updatedValue);
|
|
417
|
-
formItem.validateOnChange && formItem.validate(values);
|
|
418
|
-
}
|
|
419
|
-
});
|
|
420
|
-
(formLazyChange === false ? this.emitChange : this.lazyEmitChange)(submit);
|
|
421
|
-
};
|
|
422
|
-
Form.prototype.handleFormSubmit = function (e) {
|
|
423
|
-
var _a = this.props, preventEnterSubmit = _a.preventEnterSubmit, onActionSensor = _a.onActionSensor;
|
|
424
|
-
e.preventDefault();
|
|
425
|
-
if (preventEnterSubmit) {
|
|
426
|
-
return false;
|
|
427
|
-
}
|
|
428
|
-
var sensor = this.handleAction(e, {
|
|
429
|
-
type: 'submit'
|
|
430
|
-
}, this.props.store.data);
|
|
431
|
-
// 让外层可以监控这个动作执行结果
|
|
432
|
-
onActionSensor === null || onActionSensor === void 0 ? void 0 : onActionSensor(sensor);
|
|
433
|
-
return sensor;
|
|
434
|
-
};
|
|
435
|
-
Form.prototype.handleReset = function (action) {
|
|
436
|
-
var onReset = this.props.onReset;
|
|
437
|
-
return function (data) {
|
|
438
|
-
onReset && onReset(data, action);
|
|
439
|
-
};
|
|
440
|
-
};
|
|
441
|
-
Form.prototype.handleAction = function (e, action, data, throwErrors, delegate) {
|
|
442
|
-
if (throwErrors === void 0) { throwErrors = false; }
|
|
443
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
444
|
-
var _a, store, onSubmit, api, asyncApi, finishedField, checkInterval, _b, saveSuccess, saveFailed, resetAfterSubmit, clearAfterSubmit, onAction, onSaved, onReset, onFinished, onFailed, redirect, reload, target, env, onChange, clearPersistDataAfterSubmit, trimValues, dispatchEvent, __, fields, validationRes, dispatcher;
|
|
445
|
-
var _this = this;
|
|
446
|
-
return __generator(this, function (_c) {
|
|
447
|
-
switch (_c.label) {
|
|
448
|
-
case 0:
|
|
449
|
-
_a = this.props, store = _a.store, onSubmit = _a.onSubmit, api = _a.api, asyncApi = _a.asyncApi, finishedField = _a.finishedField, checkInterval = _a.checkInterval, _b = _a.messages, saveSuccess = _b.saveSuccess, saveFailed = _b.saveFailed, resetAfterSubmit = _a.resetAfterSubmit, clearAfterSubmit = _a.clearAfterSubmit, onAction = _a.onAction, onSaved = _a.onSaved, onReset = _a.onReset, onFinished = _a.onFinished, onFailed = _a.onFailed, redirect = _a.redirect, reload = _a.reload, target = _a.target, env = _a.env, onChange = _a.onChange, clearPersistDataAfterSubmit = _a.clearPersistDataAfterSubmit, trimValues = _a.trimValues, dispatchEvent = _a.dispatchEvent, __ = _a.translate;
|
|
450
|
-
// 做动作之前,先把数据同步一下。
|
|
451
|
-
this.flush();
|
|
452
|
-
if (trimValues) {
|
|
453
|
-
store.trimValues();
|
|
454
|
-
}
|
|
455
|
-
// 如果 data 就是当前层,则 flush 一下。
|
|
456
|
-
if (data === this.props.data) {
|
|
457
|
-
data = store.data;
|
|
458
|
-
}
|
|
459
|
-
if (!(Array.isArray(action.required) && action.required.length)) return [3 /*break*/, 4];
|
|
460
|
-
/** 如果是按钮指定了required,则校验前先清空一下遗留的校验报错 */
|
|
461
|
-
store.clearErrors();
|
|
462
|
-
fields = action.required.map(function (item) { return ({
|
|
463
|
-
name: item,
|
|
464
|
-
rules: { isRequired: true }
|
|
465
|
-
}); });
|
|
466
|
-
return [4 /*yield*/, store.validateFields(fields)];
|
|
467
|
-
case 1:
|
|
468
|
-
validationRes = _c.sent();
|
|
469
|
-
if (!!validationRes) return [3 /*break*/, 3];
|
|
470
|
-
return [4 /*yield*/, dispatchEvent('validateError', this.props.data)];
|
|
471
|
-
case 2:
|
|
472
|
-
dispatcher = _c.sent();
|
|
473
|
-
if (!(dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.prevented)) {
|
|
474
|
-
env.notify('error', __('Form.validateFailed'));
|
|
475
|
-
}
|
|
476
|
-
/** 抛异常是为了在dialog中catch这个错误,避免弹窗直接关闭 */
|
|
477
|
-
return [2 /*return*/, Promise.reject(__('Form.validateFailed'))];
|
|
478
|
-
case 3:
|
|
479
|
-
/** 重置validated状态,保证submit时触发表单中的校验项 */
|
|
480
|
-
store.clearErrors();
|
|
481
|
-
_c.label = 4;
|
|
482
|
-
case 4:
|
|
483
|
-
if (action.type === 'submit' ||
|
|
484
|
-
action.actionType === 'submit' ||
|
|
485
|
-
action.actionType === 'confirm' ||
|
|
486
|
-
action.actionType === 'reset-and-submit' ||
|
|
487
|
-
action.actionType === 'clear-and-submit') {
|
|
488
|
-
store.setCurrentAction(action);
|
|
489
|
-
if (action.actionType === 'reset-and-submit') {
|
|
490
|
-
store.reset(this.handleReset(action));
|
|
491
|
-
}
|
|
492
|
-
else if (action.actionType === 'clear-and-submit') {
|
|
493
|
-
store.clear(this.handleReset(action));
|
|
494
|
-
}
|
|
495
|
-
return [2 /*return*/, this.submit(function (values) {
|
|
496
|
-
var _a;
|
|
497
|
-
if (onSubmit && onSubmit(values, action) === false) {
|
|
498
|
-
return Promise.resolve(false);
|
|
499
|
-
}
|
|
500
|
-
// 走到这里代表校验成功了
|
|
501
|
-
dispatchEvent('validateSucc', _this.props.data);
|
|
502
|
-
if (target) {
|
|
503
|
-
_this.submitToTarget(target, values);
|
|
504
|
-
dispatchEvent('submitSucc', createObject(_this.props.data, values));
|
|
505
|
-
}
|
|
506
|
-
else if (action.actionType === 'reload') {
|
|
507
|
-
action.target && _this.reloadTarget(action.target, values);
|
|
508
|
-
}
|
|
509
|
-
else if (action.actionType === 'dialog') {
|
|
510
|
-
store.openDialog(data);
|
|
511
|
-
}
|
|
512
|
-
else if (action.actionType === 'drawer') {
|
|
513
|
-
store.openDrawer(data);
|
|
514
|
-
}
|
|
515
|
-
else if (isEffectiveApi(action.api || api, values)) {
|
|
516
|
-
var finnalAsyncApi_1 = action.asyncApi || asyncApi;
|
|
517
|
-
isEffectiveApi(finnalAsyncApi_1, store.data) &&
|
|
518
|
-
store.updateData((_a = {},
|
|
519
|
-
_a[finishedField || 'finished'] = false,
|
|
520
|
-
_a));
|
|
521
|
-
return store
|
|
522
|
-
.saveRemote(action.api || api, values, {
|
|
523
|
-
successMessage: saveSuccess,
|
|
524
|
-
errorMessage: saveFailed,
|
|
525
|
-
onSuccess: function (result) { return __awaiter(_this, void 0, void 0, function () {
|
|
526
|
-
var dispatcher, cbResult;
|
|
527
|
-
var _this = this;
|
|
528
|
-
return __generator(this, function (_a) {
|
|
529
|
-
switch (_a.label) {
|
|
530
|
-
case 0: return [4 /*yield*/, dispatchEvent('submitSucc', createObject(this.props.data, { result: result }))];
|
|
531
|
-
case 1:
|
|
532
|
-
dispatcher = _a.sent();
|
|
533
|
-
if (!isEffectiveApi(finnalAsyncApi_1, store.data) ||
|
|
534
|
-
store.data[finishedField || 'finished']) {
|
|
535
|
-
return [2 /*return*/, {
|
|
536
|
-
cbResult: null,
|
|
537
|
-
dispatcher: dispatcher
|
|
538
|
-
}];
|
|
539
|
-
}
|
|
540
|
-
cbResult = until(function () { return store.checkRemote(finnalAsyncApi_1, store.data); }, function (ret) { return ret && ret[finishedField || 'finished']; }, function (cancel) { return (_this.asyncCancel = cancel); }, checkInterval);
|
|
541
|
-
return [2 /*return*/, {
|
|
542
|
-
cbResult: cbResult,
|
|
543
|
-
dispatcher: dispatcher
|
|
544
|
-
}];
|
|
545
|
-
}
|
|
546
|
-
});
|
|
547
|
-
}); },
|
|
548
|
-
onFailed: function (result) { return __awaiter(_this, void 0, void 0, function () {
|
|
549
|
-
var dispatcher;
|
|
550
|
-
return __generator(this, function (_a) {
|
|
551
|
-
switch (_a.label) {
|
|
552
|
-
case 0: return [4 /*yield*/, dispatchEvent('submitFail', createObject(this.props.data, { error: result }))];
|
|
553
|
-
case 1:
|
|
554
|
-
dispatcher = _a.sent();
|
|
555
|
-
return [2 /*return*/, {
|
|
556
|
-
dispatcher: dispatcher
|
|
557
|
-
}];
|
|
558
|
-
}
|
|
559
|
-
});
|
|
560
|
-
}); }
|
|
561
|
-
})
|
|
562
|
-
.then(function (response) { return __awaiter(_this, void 0, void 0, function () {
|
|
563
|
-
var feedback, confirmed;
|
|
564
|
-
return __generator(this, function (_a) {
|
|
565
|
-
switch (_a.label) {
|
|
566
|
-
case 0:
|
|
567
|
-
onSaved && onSaved(values, response);
|
|
568
|
-
feedback = action.feedback || this.props.feedback;
|
|
569
|
-
if (!(feedback && isVisible(feedback, store.data))) return [3 /*break*/, 2];
|
|
570
|
-
return [4 /*yield*/, this.openFeedback(feedback, store.data)];
|
|
571
|
-
case 1:
|
|
572
|
-
confirmed = _a.sent();
|
|
573
|
-
// 如果 feedback 配置了,取消就跳过原有逻辑。
|
|
574
|
-
if (feedback.skipRestOnCancel && !confirmed) {
|
|
575
|
-
throw new SkipOperation();
|
|
576
|
-
}
|
|
577
|
-
else if (feedback.skipRestOnConfirm && confirmed) {
|
|
578
|
-
throw new SkipOperation();
|
|
579
|
-
}
|
|
580
|
-
_a.label = 2;
|
|
581
|
-
case 2: return [2 /*return*/];
|
|
582
|
-
}
|
|
583
|
-
});
|
|
584
|
-
}); });
|
|
585
|
-
}
|
|
586
|
-
else {
|
|
587
|
-
// type为submit,但是没有配api以及target时,只派发事件
|
|
588
|
-
dispatchEvent('submitSucc', createObject(_this.props.data, values));
|
|
589
|
-
}
|
|
590
|
-
return Promise.resolve(null);
|
|
591
|
-
})
|
|
592
|
-
.then(function (values) {
|
|
593
|
-
// 有可能 onSubmit return false 了,那么后面的就不应该再执行了。
|
|
594
|
-
if (values === false) {
|
|
595
|
-
return store.data;
|
|
596
|
-
}
|
|
597
|
-
if (onFinished && onFinished(values, action) === false) {
|
|
598
|
-
return values;
|
|
599
|
-
}
|
|
600
|
-
resetAfterSubmit && store.reset(_this.handleReset(action));
|
|
601
|
-
clearAfterSubmit && store.clear(_this.handleReset(action));
|
|
602
|
-
clearPersistDataAfterSubmit && store.clearLocalPersistData();
|
|
603
|
-
if (action.redirect || redirect) {
|
|
604
|
-
var finalRedirect = filter(action.redirect || redirect, store.data);
|
|
605
|
-
finalRedirect && env.jumpTo(finalRedirect, action);
|
|
606
|
-
}
|
|
607
|
-
else if (action.reload || reload) {
|
|
608
|
-
_this.reloadTarget(action.reload || reload, store.data);
|
|
609
|
-
}
|
|
610
|
-
action.close && _this.closeTarget(action.close);
|
|
611
|
-
return values;
|
|
612
|
-
})
|
|
613
|
-
.catch(function (reason) {
|
|
614
|
-
if (reason instanceof SkipOperation) {
|
|
615
|
-
return;
|
|
616
|
-
}
|
|
617
|
-
onFailed && onFailed(reason, store.errors);
|
|
618
|
-
if (throwErrors) {
|
|
619
|
-
throw reason;
|
|
620
|
-
}
|
|
621
|
-
})];
|
|
622
|
-
}
|
|
623
|
-
else if (action.type === 'reset' || action.actionType === 'reset') {
|
|
624
|
-
store.setCurrentAction(action);
|
|
625
|
-
store.reset(onReset);
|
|
626
|
-
}
|
|
627
|
-
else if (action.actionType === 'clear') {
|
|
628
|
-
store.setCurrentAction(action);
|
|
629
|
-
store.clear(onReset);
|
|
630
|
-
}
|
|
631
|
-
else if (action.actionType === 'validate') {
|
|
632
|
-
store.setCurrentAction(action);
|
|
633
|
-
this.validate(true);
|
|
634
|
-
}
|
|
635
|
-
else if (action.actionType === 'dialog') {
|
|
636
|
-
store.setCurrentAction(action);
|
|
637
|
-
store.openDialog(data);
|
|
638
|
-
}
|
|
639
|
-
else if (action.actionType === 'drawer') {
|
|
640
|
-
store.setCurrentAction(action);
|
|
641
|
-
store.openDrawer(data);
|
|
642
|
-
}
|
|
643
|
-
else if (action.actionType === 'ajax') {
|
|
644
|
-
store.setCurrentAction(action);
|
|
645
|
-
if (!isEffectiveApi(action.api)) {
|
|
646
|
-
return [2 /*return*/, env.alert(__("\u5F53 actionType \u4E3A ajax \u65F6\uFF0C\u8BF7\u8BBE\u7F6E api \u5C5E\u6027"))];
|
|
647
|
-
}
|
|
648
|
-
return [2 /*return*/, store
|
|
649
|
-
.saveRemote(action.api, data, {
|
|
650
|
-
successMessage: __((action.messages && action.messages.success) || saveSuccess),
|
|
651
|
-
errorMessage: __((action.messages && action.messages.failed) || saveFailed)
|
|
652
|
-
})
|
|
653
|
-
.then(function (response) { return __awaiter(_this, void 0, void 0, function () {
|
|
654
|
-
var redirect;
|
|
655
|
-
return __generator(this, function (_a) {
|
|
656
|
-
switch (_a.label) {
|
|
657
|
-
case 0:
|
|
658
|
-
response &&
|
|
659
|
-
onChange &&
|
|
660
|
-
onChange(store.data, difference(store.data, store.pristine), this.props);
|
|
661
|
-
if (!store.validated) return [3 /*break*/, 2];
|
|
662
|
-
return [4 /*yield*/, this.validate(true)];
|
|
663
|
-
case 1:
|
|
664
|
-
_a.sent();
|
|
665
|
-
_a.label = 2;
|
|
666
|
-
case 2:
|
|
667
|
-
if (!(action.feedback && isVisible(action.feedback, store.data))) return [3 /*break*/, 4];
|
|
668
|
-
return [4 /*yield*/, this.openFeedback(action.feedback, store.data)];
|
|
669
|
-
case 3:
|
|
670
|
-
_a.sent();
|
|
671
|
-
_a.label = 4;
|
|
672
|
-
case 4:
|
|
673
|
-
redirect = action.redirect && filter(action.redirect, store.data);
|
|
674
|
-
redirect && env.jumpTo(redirect, action);
|
|
675
|
-
action.reload && this.reloadTarget(action.reload, store.data);
|
|
676
|
-
action.close && this.closeTarget(action.close);
|
|
677
|
-
return [2 /*return*/];
|
|
678
|
-
}
|
|
679
|
-
});
|
|
680
|
-
}); })
|
|
681
|
-
.catch(function (e) {
|
|
682
|
-
onFailed && onFailed(e, store.errors);
|
|
683
|
-
if (throwErrors || action.countDown) {
|
|
684
|
-
throw e;
|
|
685
|
-
}
|
|
686
|
-
})];
|
|
687
|
-
}
|
|
688
|
-
else if (action.actionType === 'reload') {
|
|
689
|
-
store.setCurrentAction(action);
|
|
690
|
-
if (action.target) {
|
|
691
|
-
this.reloadTarget(action.target, data);
|
|
692
|
-
}
|
|
693
|
-
else {
|
|
694
|
-
this.receive(data);
|
|
695
|
-
}
|
|
696
|
-
// action.target && this.reloadTarget(action.target, data);
|
|
697
|
-
}
|
|
698
|
-
else if (onAction) {
|
|
699
|
-
// 不识别的丢给上层去处理。
|
|
700
|
-
return [2 /*return*/, onAction(e, action, data, throwErrors, delegate || this.context)];
|
|
701
|
-
}
|
|
702
|
-
return [2 /*return*/];
|
|
703
|
-
}
|
|
704
|
-
});
|
|
705
|
-
});
|
|
706
|
-
};
|
|
707
|
-
Form.prototype.handleQuery = function (query) {
|
|
708
|
-
var _a, _b;
|
|
709
|
-
if (this.props.initApi) {
|
|
710
|
-
this.receive(query);
|
|
711
|
-
}
|
|
712
|
-
else {
|
|
713
|
-
(_b = (_a = this.props).onQuery) === null || _b === void 0 ? void 0 : _b.call(_a, query);
|
|
714
|
-
}
|
|
715
|
-
};
|
|
716
|
-
Form.prototype.handleDialogConfirm = function (values, action, ctx, targets) {
|
|
717
|
-
var _a = this.props, store = _a.store; _a.onChange;
|
|
718
|
-
if ((action.mergeData || store.action.mergeData) &&
|
|
719
|
-
values.length === 1 &&
|
|
720
|
-
values[0] &&
|
|
721
|
-
targets[0].props.type === 'form') {
|
|
722
|
-
this.handleBulkChange(values[0], false);
|
|
723
|
-
}
|
|
724
|
-
store.closeDialog(true);
|
|
725
|
-
};
|
|
726
|
-
Form.prototype.handleDialogClose = function (confirmed) {
|
|
727
|
-
if (confirmed === void 0) { confirmed = false; }
|
|
728
|
-
var store = this.props.store;
|
|
729
|
-
store.closeDialog(confirmed);
|
|
730
|
-
};
|
|
731
|
-
Form.prototype.handleDrawerConfirm = function (values, action, ctx, targets) {
|
|
732
|
-
var _a = this.props, store = _a.store, onChange = _a.onChange;
|
|
733
|
-
if ((action.mergeData || store.action.mergeData) &&
|
|
734
|
-
values.length === 1 &&
|
|
735
|
-
values[0] &&
|
|
736
|
-
targets[0].props.type === 'form') {
|
|
737
|
-
store.updateData(values[0]);
|
|
738
|
-
onChange &&
|
|
739
|
-
onChange(store.data, difference(store.data, store.pristine), this.props);
|
|
740
|
-
}
|
|
741
|
-
store.closeDrawer(true);
|
|
742
|
-
};
|
|
743
|
-
Form.prototype.handleDrawerClose = function () {
|
|
744
|
-
var store = this.props.store;
|
|
745
|
-
store.closeDrawer(false);
|
|
746
|
-
};
|
|
747
|
-
Form.prototype.submitToTarget = function (target, values) {
|
|
748
|
-
// 会被覆写
|
|
749
|
-
};
|
|
750
|
-
Form.prototype.reloadTarget = function (target, data) {
|
|
751
|
-
// 会被覆写
|
|
752
|
-
};
|
|
753
|
-
Form.prototype.closeTarget = function (target) {
|
|
754
|
-
// 会被覆写
|
|
755
|
-
};
|
|
756
|
-
Form.prototype.openFeedback = function (dialog, ctx) {
|
|
757
|
-
var _this = this;
|
|
758
|
-
return new Promise(function (resolve) {
|
|
759
|
-
var store = _this.props.store;
|
|
760
|
-
store.setCurrentAction({
|
|
761
|
-
type: 'button',
|
|
762
|
-
actionType: 'dialog',
|
|
763
|
-
dialog: dialog
|
|
764
|
-
});
|
|
765
|
-
store.openDialog(ctx, undefined, function (confirmed) {
|
|
766
|
-
resolve(confirmed);
|
|
767
|
-
});
|
|
768
|
-
});
|
|
769
|
-
};
|
|
770
|
-
Form.prototype.buildActions = function () {
|
|
771
|
-
var _a = this.props, actions = _a.actions, submitText = _a.submitText, body = _a.body, __ = _a.translate, loadingConfig = _a.loadingConfig;
|
|
772
|
-
if (typeof actions !== 'undefined' ||
|
|
773
|
-
!submitText ||
|
|
774
|
-
(Array.isArray(body) &&
|
|
775
|
-
body.some(function (item) {
|
|
776
|
-
var _a, _b, _c;
|
|
777
|
-
return item &&
|
|
778
|
-
!!~['submit', 'button', 'button-group', 'reset'].indexOf(((_b = (_a = item === null || item === void 0 ? void 0 : item.body) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.type) ||
|
|
779
|
-
((_c = item === null || item === void 0 ? void 0 : item.body) === null || _c === void 0 ? void 0 : _c.type) ||
|
|
780
|
-
item.type);
|
|
781
|
-
}))) {
|
|
782
|
-
return actions;
|
|
783
|
-
}
|
|
784
|
-
return [
|
|
785
|
-
{
|
|
786
|
-
type: 'submit',
|
|
787
|
-
label: __(submitText),
|
|
788
|
-
primary: true,
|
|
789
|
-
loadingConfig: loadingConfig
|
|
790
|
-
}
|
|
791
|
-
];
|
|
792
|
-
};
|
|
793
|
-
Form.prototype.renderFormItems = function (schema, region, otherProps) {
|
|
794
|
-
if (region === void 0) { region = ''; }
|
|
795
|
-
if (otherProps === void 0) { otherProps = {}; }
|
|
796
|
-
var body = Array.isArray(schema.body)
|
|
797
|
-
? schema.body
|
|
798
|
-
: schema.body
|
|
799
|
-
? [schema.body]
|
|
800
|
-
: [];
|
|
801
|
-
// 旧用法,让 wrapper 走走 compat 逻辑兼容旧用法
|
|
802
|
-
// 后续可以删除。
|
|
803
|
-
if (!body.length && schema.controls) {
|
|
804
|
-
console.warn('请用 body 代替 controls');
|
|
805
|
-
body = [
|
|
806
|
-
{
|
|
807
|
-
size: 'none',
|
|
808
|
-
type: 'wrapper',
|
|
809
|
-
wrap: false,
|
|
810
|
-
controls: schema.controls
|
|
811
|
-
}
|
|
812
|
-
];
|
|
813
|
-
}
|
|
814
|
-
return this.renderChildren(body, region, otherProps);
|
|
815
|
-
};
|
|
816
|
-
Form.prototype.renderChildren = function (children, region, otherProps) {
|
|
817
|
-
var _this = this;
|
|
818
|
-
if (otherProps === void 0) { otherProps = {}; }
|
|
819
|
-
children = children || [];
|
|
820
|
-
if (!Array.isArray(children)) {
|
|
821
|
-
children = [children];
|
|
822
|
-
}
|
|
823
|
-
if (this.props.mode === 'row') {
|
|
824
|
-
this.props.classPrefix;
|
|
825
|
-
children = flatten(children).filter(function (item) {
|
|
826
|
-
if (item.hidden || item.visible === false) {
|
|
827
|
-
return false;
|
|
828
|
-
}
|
|
829
|
-
var exprProps = getExprProperties(item, _this.props.store.data, undefined, _this.props);
|
|
830
|
-
if (exprProps.hidden || exprProps.visible === false) {
|
|
831
|
-
return false;
|
|
832
|
-
}
|
|
833
|
-
return true;
|
|
834
|
-
});
|
|
835
|
-
if (!children.length) {
|
|
836
|
-
return null;
|
|
837
|
-
}
|
|
838
|
-
var cx_1 = this.props.classnames;
|
|
839
|
-
return (React.createElement("div", { className: cx_1('Form-row') }, children.map(function (control, key) {
|
|
840
|
-
return ~['hidden', 'formula'].indexOf(control.type) ||
|
|
841
|
-
control.mode === 'inline' ? (_this.renderChild(control, key, otherProps)) : (React.createElement("div", { key: key, className: cx_1("Form-col", control.columnClassName) }, _this.renderChild(control, '', __assign(__assign({}, otherProps), { mode: 'row' }))));
|
|
842
|
-
})));
|
|
843
|
-
}
|
|
844
|
-
return children.map(function (control, key) {
|
|
845
|
-
return _this.renderChild(control, key, otherProps, region);
|
|
846
|
-
});
|
|
847
|
-
};
|
|
848
|
-
Form.prototype.renderChild = function (control, key, otherProps, region) {
|
|
849
|
-
if (key === void 0) { key = ''; }
|
|
850
|
-
if (otherProps === void 0) { otherProps = {}; }
|
|
851
|
-
if (region === void 0) { region = ''; }
|
|
852
|
-
if (!control) {
|
|
853
|
-
return null;
|
|
854
|
-
}
|
|
855
|
-
else if (typeof control === 'string') {
|
|
856
|
-
control = {
|
|
857
|
-
type: 'tpl',
|
|
858
|
-
tpl: control
|
|
859
|
-
};
|
|
860
|
-
}
|
|
861
|
-
var props = __assign(__assign({}, this.props), otherProps);
|
|
862
|
-
var form = this.props.store;
|
|
863
|
-
var render = props.render, mode = props.mode, horizontal = props.horizontal, store = props.store, disabled = props.disabled, controlWidth = props.controlWidth, resolveDefinitions = props.resolveDefinitions, lazyChange = props.lazyChange; props.formLazyChange; var dispatchEvent = props.dispatchEvent, labelAlign = props.labelAlign, labelWidth = props.labelWidth, _a = props.static, isStatic = _a === void 0 ? false : _a;
|
|
864
|
-
var subProps = {
|
|
865
|
-
formStore: form,
|
|
866
|
-
data: store.data,
|
|
867
|
-
key: "".concat(control.name || '', "-").concat(control.type, "-").concat(key),
|
|
868
|
-
formInited: form.inited,
|
|
869
|
-
formSubmited: form.submited,
|
|
870
|
-
formMode: mode,
|
|
871
|
-
formHorizontal: horizontal,
|
|
872
|
-
formLabelAlign: labelAlign !== 'left' ? 'right' : labelAlign,
|
|
873
|
-
formLabelWidth: labelWidth,
|
|
874
|
-
controlWidth: controlWidth,
|
|
875
|
-
/**
|
|
876
|
-
* form.loading有为true时才下发disabled属性,否则不显性设置disbaled为false
|
|
877
|
-
* Form中包含容器类组件时,这些组件会将此处的disbaled继续下发至子组件,导致SchemaRenderer中props.disabled覆盖schema.disabled
|
|
878
|
-
*/
|
|
879
|
-
disabled: disabled ||
|
|
880
|
-
control.disabled ||
|
|
881
|
-
(form.loading ? true : undefined),
|
|
882
|
-
/**
|
|
883
|
-
* 静态展示 优先级逻辑
|
|
884
|
-
* 1. 表单子项 static: true 始终保持静态
|
|
885
|
-
* 2. 表单子项 static: false 或 不配置,跟随父表单
|
|
886
|
-
* 3. 动作控制 表单子项 时,无视配置,优先级最高
|
|
887
|
-
*/
|
|
888
|
-
static: control.static || isStatic,
|
|
889
|
-
btnDisabled: disabled || form.loading || form.validating,
|
|
890
|
-
onAction: this.handleAction,
|
|
891
|
-
onQuery: this.handleQuery,
|
|
892
|
-
onChange: this.handleChange,
|
|
893
|
-
onBulkChange: this.handleBulkChange,
|
|
894
|
-
addHook: this.addHook,
|
|
895
|
-
removeHook: this.removeHook,
|
|
896
|
-
renderFormItems: this.renderFormItems,
|
|
897
|
-
formItemDispatchEvent: this.formItemDispatchEvent(dispatchEvent),
|
|
898
|
-
formPristine: form.pristine
|
|
899
|
-
// value: (control as any)?.name
|
|
900
|
-
// ? getVariable(form.data, (control as any)?.name, canAccessSuperData)
|
|
901
|
-
// : (control as any)?.value,
|
|
902
|
-
// defaultValue: (control as any)?.value
|
|
903
|
-
};
|
|
904
|
-
var subSchema = __assign({}, control);
|
|
905
|
-
if (subSchema.$ref) {
|
|
906
|
-
subSchema = __assign(__assign({}, resolveDefinitions(subSchema.$ref)), subSchema);
|
|
907
|
-
}
|
|
908
|
-
lazyChange === false && (subSchema.changeImmediately = true);
|
|
909
|
-
return render("".concat(region ? "".concat(region, "/") : '').concat(key), subSchema, subProps);
|
|
910
|
-
};
|
|
911
|
-
Form.prototype.renderBody = function () {
|
|
912
|
-
var _a = this.props, body = _a.body, mode = _a.mode, className = _a.className, cx = _a.classnames, debug = _a.debug, debugConfig = _a.debugConfig, $path = _a.$path, store = _a.store, columnCount = _a.columnCount, render = _a.render, staticClassName = _a.staticClassName, _b = _a.static, isStatic = _b === void 0 ? false : _b, loadingConfig = _a.loadingConfig;
|
|
913
|
-
var restError = store.restError;
|
|
914
|
-
var WrapperComponent = this.props.wrapperComponent ||
|
|
915
|
-
(/(?:\/|^)form\//.test($path) ? 'div' : 'form');
|
|
916
|
-
var padDom = repeatCount(columnCount && Array.isArray(body)
|
|
917
|
-
? columnCount - (body.length % columnCount)
|
|
918
|
-
: 0, function (index) { return (React.createElement("div", { className: cx("Form-item Form-item--".concat(mode, " is-placeholder")), key: index })); });
|
|
919
|
-
return (React.createElement(WrapperComponent, { className: cx("Form", "Form--".concat(mode || 'normal'), columnCount ? "Form--column Form--column-".concat(columnCount) : null, staticClassName && isStatic ? staticClassName : className, isStatic ? 'Form--isStatic' : null), onSubmit: this.handleFormSubmit, noValidate: true },
|
|
920
|
-
React.createElement("input", { type: "submit", style: { display: 'none' } }),
|
|
921
|
-
debug
|
|
922
|
-
? render('form-debug-json', extend({
|
|
923
|
-
type: 'json',
|
|
924
|
-
value: store.data,
|
|
925
|
-
ellipsisThreshold: 120,
|
|
926
|
-
className: cx('Form--debug')
|
|
927
|
-
},
|
|
928
|
-
/** 定制debug输出格式 */
|
|
929
|
-
isObject(debugConfig) ? debugConfig : {}))
|
|
930
|
-
: null,
|
|
931
|
-
render('spinner', { type: 'spinner' }, {
|
|
932
|
-
overlay: true,
|
|
933
|
-
show: store.loading,
|
|
934
|
-
loadingConfig: loadingConfig
|
|
935
|
-
}),
|
|
936
|
-
this.renderFormItems({
|
|
937
|
-
body: body
|
|
938
|
-
}),
|
|
939
|
-
padDom,
|
|
940
|
-
restError && restError.length ? (React.createElement("ul", { className: cx('Form-restError', 'Form-feedback') }, restError.map(function (item, idx) { return (React.createElement("li", { key: idx }, item)); }))) : null,
|
|
941
|
-
render('modal', __assign(__assign({}, (store.action &&
|
|
942
|
-
store.action.dialog)), { type: 'dialog' }), {
|
|
943
|
-
key: 'dialog',
|
|
944
|
-
data: store.dialogData,
|
|
945
|
-
onConfirm: this.handleDialogConfirm,
|
|
946
|
-
onClose: this.handleDialogClose,
|
|
947
|
-
show: store.dialogOpen
|
|
948
|
-
}),
|
|
949
|
-
render('modal', __assign(__assign({}, (store.action &&
|
|
950
|
-
store.action.drawer)), { type: 'drawer' }), {
|
|
951
|
-
key: 'drawer',
|
|
952
|
-
data: store.drawerData,
|
|
953
|
-
onConfirm: this.handleDrawerConfirm,
|
|
954
|
-
onClose: this.handleDrawerClose,
|
|
955
|
-
show: store.drawerOpen
|
|
956
|
-
})));
|
|
957
|
-
};
|
|
958
|
-
Form.prototype.render = function () {
|
|
959
|
-
var _a = this.props; _a.$path; _a.$schema; var wrapWithPanel = _a.wrapWithPanel, render = _a.render, title = _a.title, store = _a.store, panelClassName = _a.panelClassName, headerClassName = _a.headerClassName, footerClassName = _a.footerClassName, footerWrapClassName = _a.footerWrapClassName, actionsClassName = _a.actionsClassName, bodyClassName = _a.bodyClassName, cx = _a.classnames, style = _a.style, affixFooter = _a.affixFooter, lazyLoad = _a.lazyLoad, __ = _a.translate, footer = _a.footer;
|
|
960
|
-
var body = this.renderBody();
|
|
961
|
-
if (wrapWithPanel) {
|
|
962
|
-
body = render('body', {
|
|
963
|
-
type: 'panel',
|
|
964
|
-
title: __(title)
|
|
965
|
-
}, {
|
|
966
|
-
className: cx(panelClassName, 'Panel--form'),
|
|
967
|
-
style: style,
|
|
968
|
-
formStore: this.props.store,
|
|
969
|
-
children: body,
|
|
970
|
-
actions: this.buildActions(),
|
|
971
|
-
onAction: this.handleAction,
|
|
972
|
-
onQuery: this.handleQuery,
|
|
973
|
-
disabled: store.loading,
|
|
974
|
-
btnDisabled: store.loading || store.validating,
|
|
975
|
-
headerClassName: headerClassName,
|
|
976
|
-
footer: footer,
|
|
977
|
-
footerClassName: footerClassName,
|
|
978
|
-
footerWrapClassName: footerWrapClassName,
|
|
979
|
-
actionsClassName: actionsClassName,
|
|
980
|
-
bodyClassName: bodyClassName,
|
|
981
|
-
affixFooter: affixFooter
|
|
982
|
-
});
|
|
983
|
-
}
|
|
984
|
-
if (lazyLoad) {
|
|
985
|
-
body = React.createElement(LazyComponent, null, body);
|
|
986
|
-
}
|
|
987
|
-
return body;
|
|
988
|
-
};
|
|
989
|
-
Form.defaultProps = {
|
|
990
|
-
title: 'Form.title',
|
|
991
|
-
submitText: 'Form.submit',
|
|
992
|
-
initFetch: true,
|
|
993
|
-
wrapWithPanel: true,
|
|
994
|
-
mode: 'normal',
|
|
995
|
-
collapsable: false,
|
|
996
|
-
controlWidth: 'full',
|
|
997
|
-
horizontal: {
|
|
998
|
-
left: 2,
|
|
999
|
-
right: 10,
|
|
1000
|
-
offset: 2
|
|
1001
|
-
},
|
|
1002
|
-
columnCount: 0,
|
|
1003
|
-
panelClassName: 'Panel--default',
|
|
1004
|
-
messages: {
|
|
1005
|
-
fetchFailed: 'fetchFailed',
|
|
1006
|
-
saveSuccess: 'saveSuccess',
|
|
1007
|
-
saveFailed: 'saveFailed'
|
|
1008
|
-
},
|
|
1009
|
-
wrapperComponent: '',
|
|
1010
|
-
finishedField: 'finished',
|
|
1011
|
-
initFinishedField: 'finished',
|
|
1012
|
-
labelAlign: 'right'
|
|
1013
|
-
};
|
|
1014
|
-
Form.propsList = [
|
|
1015
|
-
'title',
|
|
1016
|
-
'header',
|
|
1017
|
-
'controls',
|
|
1018
|
-
'tabs',
|
|
1019
|
-
'fieldSet',
|
|
1020
|
-
'submitText',
|
|
1021
|
-
'initFetch',
|
|
1022
|
-
'wrapWithPanel',
|
|
1023
|
-
'mode',
|
|
1024
|
-
'columnCount',
|
|
1025
|
-
'collapsable',
|
|
1026
|
-
'horizontal',
|
|
1027
|
-
'panelClassName',
|
|
1028
|
-
'messages',
|
|
1029
|
-
'wrapperComponent',
|
|
1030
|
-
'resetAfterSubmit',
|
|
1031
|
-
'clearAfterSubmit',
|
|
1032
|
-
'submitOnInit',
|
|
1033
|
-
'submitOnChange',
|
|
1034
|
-
'onInit',
|
|
1035
|
-
'onReset',
|
|
1036
|
-
'onSubmit',
|
|
1037
|
-
'onChange',
|
|
1038
|
-
'onFailed',
|
|
1039
|
-
'onFinished',
|
|
1040
|
-
'onSaved',
|
|
1041
|
-
'canAccessSuperData',
|
|
1042
|
-
'lazyChange',
|
|
1043
|
-
'formLazyChange',
|
|
1044
|
-
'lazyLoad',
|
|
1045
|
-
'formInited',
|
|
1046
|
-
'simpleMode',
|
|
1047
|
-
'inputOnly',
|
|
1048
|
-
'value',
|
|
1049
|
-
'actions',
|
|
1050
|
-
'multiple'
|
|
1051
|
-
];
|
|
1052
|
-
return Form;
|
|
1053
|
-
}(React.Component));
|
|
1054
|
-
var FormRenderer = /** @class */ (function (_super) {
|
|
1055
|
-
__extends(FormRenderer, _super);
|
|
1056
|
-
function FormRenderer(props, context) {
|
|
1057
|
-
var _this = _super.call(this, props) || this;
|
|
1058
|
-
var scoped = context;
|
|
1059
|
-
scoped.registerComponent(_this);
|
|
1060
|
-
return _this;
|
|
1061
|
-
}
|
|
1062
|
-
FormRenderer.prototype.componentDidMount = function () {
|
|
1063
|
-
_super.prototype.componentDidMount.call(this);
|
|
1064
|
-
if (this.props.autoFocus) {
|
|
1065
|
-
var scoped = this.context;
|
|
1066
|
-
var inputs = scoped.getComponents();
|
|
1067
|
-
var focuableInput_1 = find(inputs, function (input) { return input.focus; });
|
|
1068
|
-
focuableInput_1 && setTimeout(function () { return focuableInput_1.focus(); }, 200);
|
|
1069
|
-
}
|
|
1070
|
-
};
|
|
1071
|
-
FormRenderer.prototype.componentWillUnmount = function () {
|
|
1072
|
-
var scoped = this.context;
|
|
1073
|
-
scoped.unRegisterComponent(this);
|
|
1074
|
-
_super.prototype.componentWillUnmount.call(this);
|
|
1075
|
-
};
|
|
1076
|
-
FormRenderer.prototype.doAction = function (action, data, throwErrors) {
|
|
1077
|
-
if (data === void 0) { data = this.props.store.data; }
|
|
1078
|
-
if (throwErrors === void 0) { throwErrors = false; }
|
|
1079
|
-
return this.handleAction(undefined, action, data, throwErrors);
|
|
1080
|
-
};
|
|
1081
|
-
FormRenderer.prototype.handleAction = function (e, action, ctx, throwErrors, delegate) {
|
|
1082
|
-
var _a, _b;
|
|
1083
|
-
if (throwErrors === void 0) { throwErrors = false; }
|
|
1084
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1085
|
-
var _c, dispatchEvent, onEvent, submitEvent, dispatcher, scoped_1;
|
|
1086
|
-
return __generator(this, function (_d) {
|
|
1087
|
-
switch (_d.label) {
|
|
1088
|
-
case 0:
|
|
1089
|
-
_c = this.props, dispatchEvent = _c.dispatchEvent, onEvent = _c.onEvent;
|
|
1090
|
-
submitEvent = (_b = (_a = onEvent === null || onEvent === void 0 ? void 0 : onEvent.submit) === null || _a === void 0 ? void 0 : _a.actions) === null || _b === void 0 ? void 0 : _b.length;
|
|
1091
|
-
return [4 /*yield*/, dispatchEvent('submit', this.props.data)];
|
|
1092
|
-
case 1:
|
|
1093
|
-
dispatcher = _d.sent();
|
|
1094
|
-
if ((dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.prevented) || submitEvent) {
|
|
1095
|
-
return [2 /*return*/];
|
|
1096
|
-
}
|
|
1097
|
-
if (action.target && action.actionType !== 'reload') {
|
|
1098
|
-
scoped_1 = this.context;
|
|
1099
|
-
return [2 /*return*/, Promise.all(action.target.split(',').map(function (name) {
|
|
1100
|
-
var target = scoped_1.getComponentByName(name);
|
|
1101
|
-
return (target &&
|
|
1102
|
-
target.doAction &&
|
|
1103
|
-
target.doAction(__assign(__assign({}, action), { target: undefined }), ctx, throwErrors));
|
|
1104
|
-
}))];
|
|
1105
|
-
}
|
|
1106
|
-
else {
|
|
1107
|
-
return [2 /*return*/, _super.prototype.handleAction.call(this, e, action, ctx, throwErrors, delegate)];
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
});
|
|
1111
|
-
});
|
|
1112
|
-
};
|
|
1113
|
-
FormRenderer.prototype.handleDialogConfirm = function (values, action, ctx, targets) {
|
|
1114
|
-
_super.prototype.handleDialogConfirm.call(this, values, action, ctx, targets);
|
|
1115
|
-
var store = this.props.store;
|
|
1116
|
-
var scoped = this.context;
|
|
1117
|
-
if (action.reload) {
|
|
1118
|
-
scoped.reload(action.reload, ctx);
|
|
1119
|
-
}
|
|
1120
|
-
else if (store.action && store.action.reload) {
|
|
1121
|
-
scoped.reload(store.action.reload, ctx);
|
|
1122
|
-
}
|
|
1123
|
-
};
|
|
1124
|
-
FormRenderer.prototype.submitToTarget = function (target, values) {
|
|
1125
|
-
var scoped = this.context;
|
|
1126
|
-
scoped.send(target, values);
|
|
1127
|
-
};
|
|
1128
|
-
FormRenderer.prototype.reloadTarget = function (target, data) {
|
|
1129
|
-
var scoped = this.context;
|
|
1130
|
-
scoped.reload(target, data);
|
|
1131
|
-
};
|
|
1132
|
-
FormRenderer.prototype.closeTarget = function (target) {
|
|
1133
|
-
var scoped = this.context;
|
|
1134
|
-
scoped.close(target);
|
|
1135
|
-
};
|
|
1136
|
-
FormRenderer.prototype.reload = function (target, query, ctx, silent, replace) {
|
|
1137
|
-
if (query) {
|
|
1138
|
-
return this.receive(query, undefined, replace);
|
|
1139
|
-
}
|
|
1140
|
-
var scoped = this.context;
|
|
1141
|
-
var subPath = '';
|
|
1142
|
-
var idx;
|
|
1143
|
-
var subQuery = null;
|
|
1144
|
-
if (target && ~(idx = target.indexOf('.'))) {
|
|
1145
|
-
subPath = target.substring(idx + 1);
|
|
1146
|
-
target = target.substring(0, idx);
|
|
1147
|
-
}
|
|
1148
|
-
var idx2 = target ? target.indexOf('?') : -1;
|
|
1149
|
-
if (~idx2) {
|
|
1150
|
-
subQuery = dataMapping(qsparse(target.substring(idx2 + 1)), ctx);
|
|
1151
|
-
target = target.substring(0, idx2);
|
|
1152
|
-
}
|
|
1153
|
-
var component;
|
|
1154
|
-
if (target &&
|
|
1155
|
-
(component = scoped.getComponentByName(target)) &&
|
|
1156
|
-
component.reload) {
|
|
1157
|
-
component.reload(subPath, subQuery, ctx);
|
|
1158
|
-
}
|
|
1159
|
-
else if (target === '*') {
|
|
1160
|
-
_super.prototype.reload.call(this, target, query, ctx, silent);
|
|
1161
|
-
var components = scoped.getComponents();
|
|
1162
|
-
components.forEach(function (component) {
|
|
1163
|
-
return component.reload && component.reload('', subQuery, ctx);
|
|
1164
|
-
});
|
|
1165
|
-
}
|
|
1166
|
-
else {
|
|
1167
|
-
_super.prototype.reload.call(this, target, query, ctx, silent);
|
|
1168
|
-
}
|
|
1169
|
-
};
|
|
1170
|
-
FormRenderer.prototype.receive = function (values, name, replace) {
|
|
1171
|
-
if (name) {
|
|
1172
|
-
var scoped = this.context;
|
|
1173
|
-
var idx = name.indexOf('.');
|
|
1174
|
-
var subPath = '';
|
|
1175
|
-
if (~idx) {
|
|
1176
|
-
subPath = name.substring(1 + idx);
|
|
1177
|
-
name = name.substring(0, idx);
|
|
1178
|
-
}
|
|
1179
|
-
var component = scoped.getComponentByName(name);
|
|
1180
|
-
component && component.receive && component.receive(values, subPath);
|
|
1181
|
-
return;
|
|
1182
|
-
}
|
|
1183
|
-
return _super.prototype.receive.call(this, values, undefined, replace);
|
|
1184
|
-
};
|
|
1185
|
-
FormRenderer.prototype.setData = function (values, replace) {
|
|
1186
|
-
var _a = this.props, onChange = _a.onChange, store = _a.store;
|
|
1187
|
-
_super.prototype.setValues.call(this, values);
|
|
1188
|
-
// 触发表单change
|
|
1189
|
-
onChange &&
|
|
1190
|
-
onChange(store.data, difference(store.data, store.pristine), this.props);
|
|
1191
|
-
};
|
|
1192
|
-
FormRenderer.prototype.getData = function () {
|
|
1193
|
-
var store = this.props.store;
|
|
1194
|
-
return store.data;
|
|
1195
|
-
};
|
|
1196
|
-
FormRenderer.contextType = ScopedContext;
|
|
1197
|
-
FormRenderer = __decorate([
|
|
1198
|
-
Renderer({
|
|
1199
|
-
type: 'form',
|
|
1200
|
-
storeType: FormStore.name,
|
|
1201
|
-
isolateScope: true,
|
|
1202
|
-
storeExtendsData: function (props) { return props.inheritData; },
|
|
1203
|
-
shouldSyncSuperStore: function (store, props, prevProps) {
|
|
1204
|
-
var _a, _b;
|
|
1205
|
-
// 如果是 QuickEdit,让 store 同步 __super 数据。
|
|
1206
|
-
if (props.quickEditFormRef &&
|
|
1207
|
-
props.onQuickChange &&
|
|
1208
|
-
(isObjectShallowModified(prevProps.data, props.data) ||
|
|
1209
|
-
isObjectShallowModified(prevProps.data.__super, props.data.__super) ||
|
|
1210
|
-
isObjectShallowModified((_a = prevProps.data.__super) === null || _a === void 0 ? void 0 : _a.__super, (_b = props.data.__super) === null || _b === void 0 ? void 0 : _b.__super))) {
|
|
1211
|
-
return true;
|
|
1212
|
-
}
|
|
1213
|
-
return undefined;
|
|
1214
|
-
}
|
|
1215
|
-
}),
|
|
1216
|
-
__metadata("design:paramtypes", [Object, Object])
|
|
1217
|
-
], FormRenderer);
|
|
1218
|
-
return FormRenderer;
|
|
1219
|
-
}(Form));
|
|
1220
|
-
|
|
1221
|
-
export { FormRenderer, Form as default };
|