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/store/form.js
DELETED
|
@@ -1,650 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* amis-core v2.6.0
|
|
3
|
-
* Copyright 2018-2022 fex
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { __generator, __assign } from 'tslib';
|
|
7
|
-
import { types, flow, isAlive, getEnv } from 'mobx-state-tree';
|
|
8
|
-
import debounce from 'lodash/debounce';
|
|
9
|
-
import throttle from 'lodash/throttle';
|
|
10
|
-
import toPairs from 'lodash/toPairs';
|
|
11
|
-
import pick from 'lodash/pick';
|
|
12
|
-
import { ServiceStore } from './service.js';
|
|
13
|
-
import { ServerError } from '../utils/errors.js';
|
|
14
|
-
import { isEmpty, difference, mapObject } from '../utils/helper.js';
|
|
15
|
-
import isEqual from 'lodash/isEqual';
|
|
16
|
-
import flatten from 'lodash/flatten';
|
|
17
|
-
import find from 'lodash/find';
|
|
18
|
-
import { filter } from '../utils/tpl.js';
|
|
19
|
-
import 'amis-formula';
|
|
20
|
-
import 'moment';
|
|
21
|
-
import { createObject, isObject, cloneObject, setVariable, deleteVariable } from '../utils/object.js';
|
|
22
|
-
import { isPureVariable } from '../utils/isPureVariable.js';
|
|
23
|
-
import { getVariable } from '../utils/getVariable.js';
|
|
24
|
-
import 'lodash/isPlainObject';
|
|
25
|
-
import '../utils/filter.js';
|
|
26
|
-
import { normalizeApiResponseData } from '../utils/api.js';
|
|
27
|
-
import { keyToPath } from '../utils/keyToPath.js';
|
|
28
|
-
|
|
29
|
-
var FormStore = ServiceStore.named('FormStore')
|
|
30
|
-
.props({
|
|
31
|
-
inited: false,
|
|
32
|
-
validated: false,
|
|
33
|
-
submited: false,
|
|
34
|
-
submiting: false,
|
|
35
|
-
savedData: types.frozen(),
|
|
36
|
-
// items: types.optional(types.array(types.late(() => FormItemStore)), []),
|
|
37
|
-
canAccessSuperData: true,
|
|
38
|
-
persistData: types.optional(types.union(types.string, types.boolean), ''),
|
|
39
|
-
restError: types.optional(types.array(types.string), []) // 没有映射到表达项上的 errors
|
|
40
|
-
})
|
|
41
|
-
.views(function (self) {
|
|
42
|
-
function getItems() {
|
|
43
|
-
var formItems = [];
|
|
44
|
-
// 查找孩子节点中是 formItem 的表单项
|
|
45
|
-
var pool = self.children.concat();
|
|
46
|
-
while (pool.length) {
|
|
47
|
-
var current = pool.shift();
|
|
48
|
-
if (current.storeType === 'FormItemStore') {
|
|
49
|
-
formItems.push(current);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
pool.push.apply(pool, current.children);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return formItems;
|
|
56
|
-
}
|
|
57
|
-
return {
|
|
58
|
-
get loading() {
|
|
59
|
-
return self.saving || self.fetching;
|
|
60
|
-
},
|
|
61
|
-
get items() {
|
|
62
|
-
return getItems();
|
|
63
|
-
},
|
|
64
|
-
/**
|
|
65
|
-
* 相对于 items(), 只收集直接子formItem
|
|
66
|
-
* 避免 子form 表单项的重复验证
|
|
67
|
-
*/
|
|
68
|
-
get directItems() {
|
|
69
|
-
var formItems = [];
|
|
70
|
-
// 查找孩子节点中是 formItem 的表单项
|
|
71
|
-
var pool = self.children.concat();
|
|
72
|
-
while (pool.length) {
|
|
73
|
-
var current = pool.shift();
|
|
74
|
-
if (current.storeType === 'FormItemStore') {
|
|
75
|
-
formItems.push(current);
|
|
76
|
-
}
|
|
77
|
-
else if (!['ComboStore', 'TableStore'].includes(current.storeType)) {
|
|
78
|
-
pool.push.apply(pool, current.children);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return formItems;
|
|
82
|
-
},
|
|
83
|
-
get errors() {
|
|
84
|
-
var errors = {};
|
|
85
|
-
getItems().forEach(function (item) {
|
|
86
|
-
if (!item.valid) {
|
|
87
|
-
errors[item.name] = Array.isArray(errors[item.name])
|
|
88
|
-
? errors[item.name].concat(item.errors)
|
|
89
|
-
: item.errors.concat();
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
return errors;
|
|
93
|
-
},
|
|
94
|
-
getValueByName: function (name, canAccessSuperData) {
|
|
95
|
-
if (canAccessSuperData === void 0) { canAccessSuperData = self.canAccessSuperData; }
|
|
96
|
-
return getVariable(self.data, name, canAccessSuperData);
|
|
97
|
-
},
|
|
98
|
-
getPristineValueByName: function (name) {
|
|
99
|
-
return getVariable(self.pristine, name);
|
|
100
|
-
},
|
|
101
|
-
getItemById: function (id) {
|
|
102
|
-
return getItems().find(function (item) { return item.itemId === id; });
|
|
103
|
-
},
|
|
104
|
-
getItemByName: function (name) {
|
|
105
|
-
return getItems().find(function (item) { return item.name === name; });
|
|
106
|
-
},
|
|
107
|
-
getItemsByName: function (name) {
|
|
108
|
-
return getItems().filter(function (item) { return item.name === name; });
|
|
109
|
-
},
|
|
110
|
-
get valid() {
|
|
111
|
-
return (getItems().every(function (item) { return item.valid; }) &&
|
|
112
|
-
(!self.restError || !self.restError.length));
|
|
113
|
-
},
|
|
114
|
-
get validating() {
|
|
115
|
-
return getItems().some(function (item) { return item.validating; });
|
|
116
|
-
},
|
|
117
|
-
get isPristine() {
|
|
118
|
-
return isEqual(self.pristine, self.data);
|
|
119
|
-
},
|
|
120
|
-
get modified() {
|
|
121
|
-
if (self.savedData) {
|
|
122
|
-
return self.savedData !== self.data;
|
|
123
|
-
}
|
|
124
|
-
return !this.isPristine;
|
|
125
|
-
},
|
|
126
|
-
get persistKey() {
|
|
127
|
-
return "".concat(location.pathname, "/").concat(self.path, "/").concat(typeof self.persistData === 'string'
|
|
128
|
-
? filter(self.persistData, self.data)
|
|
129
|
-
: self.persistData);
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
})
|
|
133
|
-
.actions(function (self) {
|
|
134
|
-
function setValues(values, tag, replace) {
|
|
135
|
-
self.updateData(values, tag, replace);
|
|
136
|
-
// 如果数据域中有数据变化,就都reset一下,去掉之前残留的验证消息
|
|
137
|
-
self.items.forEach(function (item) { return item.reset(); });
|
|
138
|
-
// 同步 options
|
|
139
|
-
syncOptions();
|
|
140
|
-
}
|
|
141
|
-
function setValueByName(name, value, isPristine, force) {
|
|
142
|
-
if (isPristine === void 0) { isPristine = false; }
|
|
143
|
-
if (force === void 0) { force = false; }
|
|
144
|
-
// 没有变化就不跑了。
|
|
145
|
-
var origin = getVariable(self.data, name, false);
|
|
146
|
-
var prev = self.data;
|
|
147
|
-
var data = cloneObject(self.data);
|
|
148
|
-
if (value !== origin) {
|
|
149
|
-
if (prev.__prev) {
|
|
150
|
-
// 基于之前的 __prev 改
|
|
151
|
-
var prevData = cloneObject(prev.__prev);
|
|
152
|
-
setVariable(prevData, name, origin);
|
|
153
|
-
Object.defineProperty(data, '__prev', {
|
|
154
|
-
value: prevData,
|
|
155
|
-
enumerable: false,
|
|
156
|
-
configurable: false,
|
|
157
|
-
writable: false
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
Object.defineProperty(data, '__prev', {
|
|
162
|
-
value: __assign({}, prev),
|
|
163
|
-
enumerable: false,
|
|
164
|
-
configurable: false,
|
|
165
|
-
writable: false
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
else if (!force) {
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
setVariable(data, name, value);
|
|
173
|
-
if (isPristine) {
|
|
174
|
-
var pristine = cloneObject(self.pristine);
|
|
175
|
-
setVariable(pristine, name, value);
|
|
176
|
-
self.pristine = pristine;
|
|
177
|
-
}
|
|
178
|
-
if (!data.__pristine) {
|
|
179
|
-
Object.defineProperty(data, '__pristine', {
|
|
180
|
-
value: self.pristine,
|
|
181
|
-
enumerable: false,
|
|
182
|
-
configurable: false,
|
|
183
|
-
writable: false
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
self.data = data;
|
|
187
|
-
// 同步 options
|
|
188
|
-
syncOptions();
|
|
189
|
-
}
|
|
190
|
-
function deleteValueByName(name) {
|
|
191
|
-
var prev = self.data;
|
|
192
|
-
var data = cloneObject(self.data);
|
|
193
|
-
if (prev.__prev) {
|
|
194
|
-
// 基于之前的 __prev 改
|
|
195
|
-
var prevData = cloneObject(prev.__prev);
|
|
196
|
-
setVariable(prevData, name, getVariable(prev, name));
|
|
197
|
-
Object.defineProperty(data, '__prev', {
|
|
198
|
-
value: prevData,
|
|
199
|
-
enumerable: false,
|
|
200
|
-
configurable: false,
|
|
201
|
-
writable: false
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
Object.defineProperty(data, '__prev', {
|
|
206
|
-
value: __assign({}, prev),
|
|
207
|
-
enumerable: false,
|
|
208
|
-
configurable: false,
|
|
209
|
-
writable: false
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
deleteVariable(data, name);
|
|
213
|
-
self.data = data;
|
|
214
|
-
}
|
|
215
|
-
function trimValues() {
|
|
216
|
-
var data = mapObject(self.data, function (item) {
|
|
217
|
-
return typeof item === 'string' ? item.trim() : item;
|
|
218
|
-
});
|
|
219
|
-
self.updateData(data);
|
|
220
|
-
}
|
|
221
|
-
var syncOptions = debounce(function () { return self.items.forEach(function (item) { return item.syncOptions(undefined, self.data); }); }, 250, {
|
|
222
|
-
trailing: true,
|
|
223
|
-
leading: false
|
|
224
|
-
});
|
|
225
|
-
function setRestError(errors) {
|
|
226
|
-
self.restError.replace(errors);
|
|
227
|
-
}
|
|
228
|
-
function addRestError(msg, name) {
|
|
229
|
-
var names = name
|
|
230
|
-
? Array.isArray(name)
|
|
231
|
-
? name.concat()
|
|
232
|
-
: [name]
|
|
233
|
-
: null;
|
|
234
|
-
if (Array.isArray(names)) {
|
|
235
|
-
var errors_1 = {};
|
|
236
|
-
names.forEach(function (name) { return (errors_1[name] = msg); });
|
|
237
|
-
setFormItemErrors(errors_1, 'rules');
|
|
238
|
-
}
|
|
239
|
-
else {
|
|
240
|
-
self.restError.push(msg);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
function clearRestError() {
|
|
244
|
-
setRestError([]);
|
|
245
|
-
}
|
|
246
|
-
var saveRemote = flow(function saveRemote(api, data, options) {
|
|
247
|
-
var ret, json, ret, e_1, ret, result;
|
|
248
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
249
|
-
if (options === void 0) { options = {}; }
|
|
250
|
-
return __generator(this, function (_q) {
|
|
251
|
-
switch (_q.label) {
|
|
252
|
-
case 0:
|
|
253
|
-
clearRestError();
|
|
254
|
-
_q.label = 1;
|
|
255
|
-
case 1:
|
|
256
|
-
_q.trys.push([1, 12, , 15]);
|
|
257
|
-
options = __assign({ method: 'post' }, options);
|
|
258
|
-
if (!(options && options.beforeSend)) return [3 /*break*/, 4];
|
|
259
|
-
ret = options.beforeSend(data);
|
|
260
|
-
if (!(ret && ret.then)) return [3 /*break*/, 3];
|
|
261
|
-
return [4 /*yield*/, ret];
|
|
262
|
-
case 2:
|
|
263
|
-
ret = _q.sent();
|
|
264
|
-
_q.label = 3;
|
|
265
|
-
case 3:
|
|
266
|
-
if (ret === false) {
|
|
267
|
-
return [2 /*return*/];
|
|
268
|
-
}
|
|
269
|
-
_q.label = 4;
|
|
270
|
-
case 4:
|
|
271
|
-
self.markSaving(true);
|
|
272
|
-
return [4 /*yield*/, getEnv(self).fetcher(api, data, options)];
|
|
273
|
-
case 5:
|
|
274
|
-
json = _q.sent();
|
|
275
|
-
// 失败也同样修改数据,如果有数据的话。
|
|
276
|
-
if (!isEmpty(json.data) || json.ok) {
|
|
277
|
-
self.updatedAt = Date.now();
|
|
278
|
-
setValues(normalizeApiResponseData(json.data), json.ok
|
|
279
|
-
? {
|
|
280
|
-
__saved: Date.now()
|
|
281
|
-
}
|
|
282
|
-
: undefined, !!api.replaceData);
|
|
283
|
-
}
|
|
284
|
-
if (!!json.ok) return [3 /*break*/, 6];
|
|
285
|
-
if (json.status === 422 && json.errors) {
|
|
286
|
-
setFormItemErrors(json.errors);
|
|
287
|
-
self.updateMessage((_d = (_c = (_b = (_a = api === null || api === void 0 ? void 0 : api.messages) === null || _a === void 0 ? void 0 : _a.failed) !== null && _b !== void 0 ? _b : json.msg) !== null && _c !== void 0 ? _c : self.__(options && options.errorMessage)) !== null && _d !== void 0 ? _d : self.__('Form.validateFailed'), true);
|
|
288
|
-
}
|
|
289
|
-
else {
|
|
290
|
-
self.updateMessage((_g = (_f = (_e = api === null || api === void 0 ? void 0 : api.messages) === null || _e === void 0 ? void 0 : _e.failed) !== null && _f !== void 0 ? _f : json.msg) !== null && _g !== void 0 ? _g : self.__(options && options.errorMessage), true);
|
|
291
|
-
}
|
|
292
|
-
throw new ServerError(self.msg, json);
|
|
293
|
-
case 6:
|
|
294
|
-
updateSavedData();
|
|
295
|
-
ret = options && options.onSuccess && options.onSuccess(json);
|
|
296
|
-
if (!(ret === null || ret === void 0 ? void 0 : ret.then)) return [3 /*break*/, 8];
|
|
297
|
-
return [4 /*yield*/, ret];
|
|
298
|
-
case 7:
|
|
299
|
-
ret = _q.sent();
|
|
300
|
-
_q.label = 8;
|
|
301
|
-
case 8:
|
|
302
|
-
if (!((_h = ret === null || ret === void 0 ? void 0 : ret.cbResult) === null || _h === void 0 ? void 0 : _h.then)) return [3 /*break*/, 10];
|
|
303
|
-
return [4 /*yield*/, ret.cbResult];
|
|
304
|
-
case 9:
|
|
305
|
-
_q.sent();
|
|
306
|
-
_q.label = 10;
|
|
307
|
-
case 10:
|
|
308
|
-
self.markSaving(false);
|
|
309
|
-
self.updateMessage((_m = (_l = (_k = (_j = api === null || api === void 0 ? void 0 : api.messages) === null || _j === void 0 ? void 0 : _j.success) !== null && _k !== void 0 ? _k : json.msg) !== null && _l !== void 0 ? _l : (options.successMessage === 'saveSuccess'
|
|
310
|
-
? json.defaultMsg
|
|
311
|
-
: self.__(options && options.successMessage))) !== null && _m !== void 0 ? _m : json.defaultMsg);
|
|
312
|
-
if (!((_o = ret === null || ret === void 0 ? void 0 : ret.dispatcher) === null || _o === void 0 ? void 0 : _o.prevented)) {
|
|
313
|
-
self.msg &&
|
|
314
|
-
getEnv(self).notify('success', self.msg, json.msgTimeout !== undefined
|
|
315
|
-
? {
|
|
316
|
-
closeButton: true,
|
|
317
|
-
timeout: json.msgTimeout
|
|
318
|
-
}
|
|
319
|
-
: undefined);
|
|
320
|
-
}
|
|
321
|
-
return [2 /*return*/, json.data];
|
|
322
|
-
case 11: return [3 /*break*/, 15];
|
|
323
|
-
case 12:
|
|
324
|
-
e_1 = _q.sent();
|
|
325
|
-
self.markSaving(false);
|
|
326
|
-
ret = options && options.onFailed && options.onFailed(e_1.response || {});
|
|
327
|
-
if (!(ret === null || ret === void 0 ? void 0 : ret.then)) return [3 /*break*/, 14];
|
|
328
|
-
return [4 /*yield*/, ret];
|
|
329
|
-
case 13:
|
|
330
|
-
ret = _q.sent();
|
|
331
|
-
_q.label = 14;
|
|
332
|
-
case 14:
|
|
333
|
-
if (!isAlive(self) || self.disposed) {
|
|
334
|
-
return [2 /*return*/];
|
|
335
|
-
}
|
|
336
|
-
if ((_p = ret === null || ret === void 0 ? void 0 : ret.dispatcher) === null || _p === void 0 ? void 0 : _p.prevented) {
|
|
337
|
-
return [2 /*return*/];
|
|
338
|
-
}
|
|
339
|
-
if (e_1.type === 'ServerError') {
|
|
340
|
-
result = e_1.response;
|
|
341
|
-
getEnv(self).notify('error', e_1.message, result.msgTimeout !== undefined
|
|
342
|
-
? {
|
|
343
|
-
closeButton: true,
|
|
344
|
-
timeout: result.msgTimeout
|
|
345
|
-
}
|
|
346
|
-
: undefined);
|
|
347
|
-
}
|
|
348
|
-
else {
|
|
349
|
-
getEnv(self).notify('error', e_1.message);
|
|
350
|
-
}
|
|
351
|
-
throw e_1;
|
|
352
|
-
case 15: return [2 /*return*/];
|
|
353
|
-
}
|
|
354
|
-
});
|
|
355
|
-
});
|
|
356
|
-
function setFormItemErrors(errors, tag) {
|
|
357
|
-
if (tag === void 0) { tag = 'remote'; }
|
|
358
|
-
Object.keys(errors).forEach(function (key) {
|
|
359
|
-
var item = self.getItemById(key);
|
|
360
|
-
var items = self.getItemsByName(key);
|
|
361
|
-
if (item) {
|
|
362
|
-
item.setError(errors[key], tag);
|
|
363
|
-
delete errors[key];
|
|
364
|
-
}
|
|
365
|
-
else if (items.length) {
|
|
366
|
-
// 通过 name 直接找到的
|
|
367
|
-
items.forEach(function (item) { return item.setError(errors[key], tag); });
|
|
368
|
-
delete errors[key];
|
|
369
|
-
}
|
|
370
|
-
else {
|
|
371
|
-
// 尝试通过path寻找
|
|
372
|
-
var items_1 = getItemsByPath(key);
|
|
373
|
-
if (Array.isArray(items_1) && items_1.length) {
|
|
374
|
-
items_1.forEach(function (item) { return item.setError("".concat(errors[key]), tag); });
|
|
375
|
-
delete errors[key];
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
});
|
|
379
|
-
// 没有映射上的error信息加在msg后显示出来
|
|
380
|
-
!isEmpty(errors) &&
|
|
381
|
-
setRestError(Object.keys(errors).map(function (key) { return String(errors[key]); }));
|
|
382
|
-
}
|
|
383
|
-
var getItemsByPath = function (key) {
|
|
384
|
-
var paths = keyToPath(key);
|
|
385
|
-
var len = paths.length;
|
|
386
|
-
return paths.reduce(function (stores, path, idx) {
|
|
387
|
-
if (Array.isArray(stores) && stores.every(function (s) { return s.getItemsByName; })) {
|
|
388
|
-
var items = flatten(stores.map(function (s) { return s.getItemsByName(path); })).filter(function (i) { return i; });
|
|
389
|
-
var subStores = items
|
|
390
|
-
.map(function (item) { var _a; return (_a = item === null || item === void 0 ? void 0 : item.getSubStore) === null || _a === void 0 ? void 0 : _a.call(item); })
|
|
391
|
-
.filter(function (i) { return i; });
|
|
392
|
-
return subStores.length && idx < len - 1 ? subStores : items;
|
|
393
|
-
}
|
|
394
|
-
return null;
|
|
395
|
-
}, [self]);
|
|
396
|
-
};
|
|
397
|
-
// 10s 内不要重复弹同一个错误
|
|
398
|
-
var toastValidateError = throttle(function (msg) {
|
|
399
|
-
var env = getEnv(self);
|
|
400
|
-
env.notify('error', msg);
|
|
401
|
-
}, 10000, {
|
|
402
|
-
trailing: false,
|
|
403
|
-
leading: true
|
|
404
|
-
});
|
|
405
|
-
var submit = flow(function submit(fn, hooks, failedMessage, validateErrCb) {
|
|
406
|
-
var valid, msg, dispatcher, diff, result;
|
|
407
|
-
return __generator(this, function (_a) {
|
|
408
|
-
switch (_a.label) {
|
|
409
|
-
case 0:
|
|
410
|
-
self.submited = true;
|
|
411
|
-
self.submiting = true;
|
|
412
|
-
_a.label = 1;
|
|
413
|
-
case 1:
|
|
414
|
-
_a.trys.push([1, , 8, 9]);
|
|
415
|
-
return [4 /*yield*/, validate(hooks)];
|
|
416
|
-
case 2:
|
|
417
|
-
valid = _a.sent();
|
|
418
|
-
if (!((!valid &&
|
|
419
|
-
self.items.some(function (item) {
|
|
420
|
-
return item.errorData.some(function (e) { return e.tag !== 'remote'; });
|
|
421
|
-
})) ||
|
|
422
|
-
self.restError.length)) return [3 /*break*/, 5];
|
|
423
|
-
msg = failedMessage !== null && failedMessage !== void 0 ? failedMessage : self.__('Form.validateFailed');
|
|
424
|
-
dispatcher = validateErrCb && validateErrCb();
|
|
425
|
-
if (!(dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.then)) return [3 /*break*/, 4];
|
|
426
|
-
return [4 /*yield*/, dispatcher];
|
|
427
|
-
case 3:
|
|
428
|
-
dispatcher = _a.sent();
|
|
429
|
-
_a.label = 4;
|
|
430
|
-
case 4:
|
|
431
|
-
if (!(dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.prevented)) {
|
|
432
|
-
msg && toastValidateError(msg);
|
|
433
|
-
}
|
|
434
|
-
throw new Error(msg);
|
|
435
|
-
case 5:
|
|
436
|
-
if (!fn) return [3 /*break*/, 7];
|
|
437
|
-
diff = difference(self.data, self.pristine);
|
|
438
|
-
return [4 /*yield*/, fn(createObject(createObject(self.data.__super, {
|
|
439
|
-
diff: diff,
|
|
440
|
-
__diff: diff,
|
|
441
|
-
pristine: self.pristine
|
|
442
|
-
}), self.data))];
|
|
443
|
-
case 6:
|
|
444
|
-
result = _a.sent();
|
|
445
|
-
return [2 /*return*/, result !== null && result !== void 0 ? result : self.data];
|
|
446
|
-
case 7: return [2 /*return*/, self.data];
|
|
447
|
-
case 8:
|
|
448
|
-
self.submiting = false;
|
|
449
|
-
return [7 /*endfinally*/];
|
|
450
|
-
case 9: return [2 /*return*/];
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
|
-
});
|
|
454
|
-
var validate = flow(function validate(hooks, forceValidate) {
|
|
455
|
-
var items, i, len, item, i, len;
|
|
456
|
-
return __generator(this, function (_a) {
|
|
457
|
-
switch (_a.label) {
|
|
458
|
-
case 0:
|
|
459
|
-
self.validated = true;
|
|
460
|
-
items = self.directItems.concat();
|
|
461
|
-
i = 0, len = items.length;
|
|
462
|
-
_a.label = 1;
|
|
463
|
-
case 1:
|
|
464
|
-
if (!(i < len)) return [3 /*break*/, 4];
|
|
465
|
-
item = items[i];
|
|
466
|
-
// 先清除组合校验的错误
|
|
467
|
-
item.clearError('rules');
|
|
468
|
-
/* 日期类校验存在表单项联动的情况,需要在提交前重置校验状态,避免变量更新后联动校验结果未更新 */
|
|
469
|
-
if (item.validated &&
|
|
470
|
-
isObject(item.rules) &&
|
|
471
|
-
toPairs(item.rules)
|
|
472
|
-
.filter(function (_a) {
|
|
473
|
-
var key = _a[0]; _a[1];
|
|
474
|
-
return /^is(Date)?Time/.test(key);
|
|
475
|
-
})
|
|
476
|
-
.some(function (_a) {
|
|
477
|
-
_a[0]; var value = _a[1];
|
|
478
|
-
return Array.isArray(value)
|
|
479
|
-
? value.some(function (item) { return isPureVariable(item); })
|
|
480
|
-
: isPureVariable(value);
|
|
481
|
-
})) {
|
|
482
|
-
item.resetValidationStatus();
|
|
483
|
-
}
|
|
484
|
-
if (!(!item.validated ||
|
|
485
|
-
item.rules.equals ||
|
|
486
|
-
item.rules.equalsField ||
|
|
487
|
-
item.unique ||
|
|
488
|
-
forceValidate ||
|
|
489
|
-
!!item.validateApi)) return [3 /*break*/, 3];
|
|
490
|
-
return [4 /*yield*/, item.validate(self.data)];
|
|
491
|
-
case 2:
|
|
492
|
-
_a.sent();
|
|
493
|
-
_a.label = 3;
|
|
494
|
-
case 3:
|
|
495
|
-
i++;
|
|
496
|
-
return [3 /*break*/, 1];
|
|
497
|
-
case 4:
|
|
498
|
-
if (!(hooks && hooks.length)) return [3 /*break*/, 8];
|
|
499
|
-
i = 0, len = hooks.length;
|
|
500
|
-
_a.label = 5;
|
|
501
|
-
case 5:
|
|
502
|
-
if (!(i < len)) return [3 /*break*/, 8];
|
|
503
|
-
return [4 /*yield*/, hooks[i]()];
|
|
504
|
-
case 6:
|
|
505
|
-
_a.sent();
|
|
506
|
-
_a.label = 7;
|
|
507
|
-
case 7:
|
|
508
|
-
i++;
|
|
509
|
-
return [3 /*break*/, 5];
|
|
510
|
-
case 8: return [2 /*return*/, self.valid];
|
|
511
|
-
}
|
|
512
|
-
});
|
|
513
|
-
});
|
|
514
|
-
var validateFields = flow(function validateFields(fields) {
|
|
515
|
-
var items, normalizedfields, result, _loop_1, i, len;
|
|
516
|
-
return __generator(this, function (_a) {
|
|
517
|
-
switch (_a.label) {
|
|
518
|
-
case 0:
|
|
519
|
-
items = self.items.concat();
|
|
520
|
-
normalizedfields = fields.map(function (field) {
|
|
521
|
-
return typeof field === 'string' ? { name: field, rules: {} } : field;
|
|
522
|
-
});
|
|
523
|
-
result = [];
|
|
524
|
-
_loop_1 = function (i, len) {
|
|
525
|
-
var item, field, _b, _c;
|
|
526
|
-
return __generator(this, function (_d) {
|
|
527
|
-
switch (_d.label) {
|
|
528
|
-
case 0:
|
|
529
|
-
item = items[i];
|
|
530
|
-
field = find(normalizedfields, function (field) { return field.name === item.name; });
|
|
531
|
-
if (!field) return [3 /*break*/, 2];
|
|
532
|
-
_c = (_b = result).push;
|
|
533
|
-
return [4 /*yield*/, item.validate(self.data, undefined, field.rules)];
|
|
534
|
-
case 1:
|
|
535
|
-
_c.apply(_b, [_d.sent()]);
|
|
536
|
-
_d.label = 2;
|
|
537
|
-
case 2: return [2 /*return*/];
|
|
538
|
-
}
|
|
539
|
-
});
|
|
540
|
-
};
|
|
541
|
-
i = 0, len = items.length;
|
|
542
|
-
_a.label = 1;
|
|
543
|
-
case 1:
|
|
544
|
-
if (!(i < len)) return [3 /*break*/, 4];
|
|
545
|
-
return [5 /*yield**/, _loop_1(i, len)];
|
|
546
|
-
case 2:
|
|
547
|
-
_a.sent();
|
|
548
|
-
_a.label = 3;
|
|
549
|
-
case 3:
|
|
550
|
-
i++;
|
|
551
|
-
return [3 /*break*/, 1];
|
|
552
|
-
case 4: return [2 /*return*/, result.every(function (item) { return item; })];
|
|
553
|
-
}
|
|
554
|
-
});
|
|
555
|
-
});
|
|
556
|
-
function clearErrors() {
|
|
557
|
-
var items = self.items.concat();
|
|
558
|
-
items.forEach(function (item) { return item.reset(); });
|
|
559
|
-
}
|
|
560
|
-
function reset(cb, resetData) {
|
|
561
|
-
if (resetData === void 0) { resetData = true; }
|
|
562
|
-
if (resetData) {
|
|
563
|
-
self.data = self.pristine;
|
|
564
|
-
}
|
|
565
|
-
// 值可能变了,重新验证一次。
|
|
566
|
-
self.validated = false;
|
|
567
|
-
self.submited = false;
|
|
568
|
-
self.items.forEach(function (item) { return item.reset(); });
|
|
569
|
-
cb && cb(self.data);
|
|
570
|
-
}
|
|
571
|
-
function clear(cb) {
|
|
572
|
-
var toClear = {};
|
|
573
|
-
self.items.forEach(function (item) {
|
|
574
|
-
if (item.name && item.type !== 'hidden') {
|
|
575
|
-
setVariable(toClear, item.name, item.resetValue);
|
|
576
|
-
}
|
|
577
|
-
});
|
|
578
|
-
setValues(toClear);
|
|
579
|
-
self.validated = false;
|
|
580
|
-
self.submited = false;
|
|
581
|
-
self.items.forEach(function (item) { return item.reset(); });
|
|
582
|
-
cb && cb(self.data);
|
|
583
|
-
}
|
|
584
|
-
function setCanAccessSuperData(value) {
|
|
585
|
-
if (value === void 0) { value = true; }
|
|
586
|
-
self.canAccessSuperData = value;
|
|
587
|
-
}
|
|
588
|
-
function setInited(value) {
|
|
589
|
-
self.inited = value;
|
|
590
|
-
}
|
|
591
|
-
function setPersistData(value) {
|
|
592
|
-
if (value === void 0) { value = ''; }
|
|
593
|
-
self.persistData = value;
|
|
594
|
-
}
|
|
595
|
-
/**
|
|
596
|
-
* 将表单数据存入本地
|
|
597
|
-
* @param keys 指定只存储某些 key
|
|
598
|
-
*/
|
|
599
|
-
var setLocalPersistData = function (keys) {
|
|
600
|
-
var data = self.data;
|
|
601
|
-
if (keys && keys.length) {
|
|
602
|
-
data = pick(data, keys);
|
|
603
|
-
}
|
|
604
|
-
localStorage.setItem(self.persistKey, JSON.stringify(data));
|
|
605
|
-
};
|
|
606
|
-
function getLocalPersistData() {
|
|
607
|
-
var data = localStorage.getItem(self.persistKey);
|
|
608
|
-
if (data) {
|
|
609
|
-
self.updateData(JSON.parse(data));
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
function clearLocalPersistData() {
|
|
613
|
-
localStorage.removeItem(self.persistKey);
|
|
614
|
-
}
|
|
615
|
-
function updateSavedData() {
|
|
616
|
-
self.savedData = self.data;
|
|
617
|
-
}
|
|
618
|
-
return {
|
|
619
|
-
setInited: setInited,
|
|
620
|
-
setValues: setValues,
|
|
621
|
-
setValueByName: setValueByName,
|
|
622
|
-
trimValues: trimValues,
|
|
623
|
-
submit: submit,
|
|
624
|
-
validate: validate,
|
|
625
|
-
validateFields: validateFields,
|
|
626
|
-
clearErrors: clearErrors,
|
|
627
|
-
saveRemote: saveRemote,
|
|
628
|
-
reset: reset,
|
|
629
|
-
syncOptions: syncOptions,
|
|
630
|
-
setCanAccessSuperData: setCanAccessSuperData,
|
|
631
|
-
deleteValueByName: deleteValueByName,
|
|
632
|
-
getLocalPersistData: getLocalPersistData,
|
|
633
|
-
setLocalPersistData: setLocalPersistData,
|
|
634
|
-
clearLocalPersistData: clearLocalPersistData,
|
|
635
|
-
setPersistData: setPersistData,
|
|
636
|
-
clear: clear,
|
|
637
|
-
updateSavedData: updateSavedData,
|
|
638
|
-
setFormItemErrors: setFormItemErrors,
|
|
639
|
-
getItemsByPath: getItemsByPath,
|
|
640
|
-
setRestError: setRestError,
|
|
641
|
-
addRestError: addRestError,
|
|
642
|
-
clearRestError: clearRestError,
|
|
643
|
-
beforeDestroy: function () {
|
|
644
|
-
syncOptions.cancel();
|
|
645
|
-
toastValidateError.cancel();
|
|
646
|
-
}
|
|
647
|
-
};
|
|
648
|
-
});
|
|
649
|
-
|
|
650
|
-
export { FormStore };
|