amis 1.4.2-beta.6 → 1.5.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/lib/Schema.d.ts +11 -3
- package/lib/Schema.js.map +1 -1
- package/lib/components/Alert2.d.ts +26 -21
- package/lib/components/Alert2.js +11 -4
- package/lib/components/Alert2.js.map +2 -2
- package/lib/components/AnchorNav.d.ts +22 -21
- package/lib/components/AnchorNav.js +7 -3
- package/lib/components/AnchorNav.js.map +2 -2
- package/lib/components/ArrayInput.d.ts +84 -84
- package/lib/components/AssociatedSelection.d.ts +930 -0
- package/lib/components/AssociatedSelection.js +89 -0
- package/lib/components/AssociatedSelection.js.map +13 -0
- package/lib/components/Badge.js +2 -2
- package/lib/components/Badge.js.map +2 -2
- package/lib/components/Button.js +1 -1
- package/lib/components/Button.js.map +2 -2
- package/lib/components/{ChainedCheckboxes.d.ts → ChainedSelection.d.ts} +267 -98
- package/lib/components/{ChainedCheckboxes.js → ChainedSelection.js} +30 -24
- package/lib/components/ChainedSelection.js.map +13 -0
- package/lib/components/Checkbox.d.ts +20 -20
- package/lib/components/Collapse.d.ts +51 -23
- package/lib/components/Collapse.js +70 -11
- package/lib/components/Collapse.js.map +2 -2
- package/lib/components/CollapseGroup.d.ts +88 -0
- package/lib/components/CollapseGroup.js +81 -0
- package/lib/components/CollapseGroup.js.map +13 -0
- package/lib/components/ColorPicker.d.ts +89 -85
- package/lib/components/ColorPicker.js +17 -4
- package/lib/components/ColorPicker.js.map +2 -2
- package/lib/components/DatePicker.d.ts +84 -84
- package/lib/components/DateRangePicker.d.ts +84 -84
- package/lib/components/Drawer.js +2 -2
- package/lib/components/Drawer.js.map +2 -2
- package/lib/components/Editor.d.ts +84 -84
- package/lib/components/GridNav.d.ts +52 -0
- package/lib/components/GridNav.js +123 -0
- package/lib/components/GridNav.js.map +13 -0
- package/lib/components/GroupedSelection.d.ts +907 -0
- package/lib/components/GroupedSelection.js +48 -0
- package/lib/components/GroupedSelection.js.map +13 -0
- package/lib/components/InputBox.d.ts +22 -21
- package/lib/components/InputBox.js +10 -2
- package/lib/components/InputBox.js.map +2 -2
- package/lib/components/Link.d.ts +29 -36
- package/lib/components/Link.js +14 -15
- package/lib/components/Link.js.map +2 -2
- package/lib/components/ListGroup.d.ts +21 -21
- package/lib/components/ModalManager.js +1 -1
- package/lib/components/ModalManager.js.map +2 -2
- package/lib/components/MonthRangePicker.d.ts +84 -84
- package/lib/components/NumberInput.d.ts +20 -20
- package/lib/components/Overlay.js +5 -0
- package/lib/components/Overlay.js.map +2 -2
- package/lib/components/PickerColumn.d.ts +514 -0
- package/lib/components/PickerColumn.js +279 -0
- package/lib/components/PickerColumn.js.map +13 -0
- package/lib/components/PickerContainer.d.ts +513 -0
- package/lib/components/PickerContainer.js +96 -0
- package/lib/components/PickerContainer.js.map +13 -0
- package/lib/components/PopOver.d.ts +1 -0
- package/lib/components/PopOver.js +12 -1
- package/lib/components/PopOver.js.map +2 -2
- package/lib/components/Progress.d.ts +85 -0
- package/lib/components/Progress.js +81 -0
- package/lib/components/Progress.js.map +13 -0
- package/lib/components/Radios.d.ts +22 -21
- package/lib/components/Radios.js +1 -0
- package/lib/components/Radios.js.map +2 -2
- package/lib/components/Rating.d.ts +21 -21
- package/lib/components/ResultBox.d.ts +84 -84
- package/lib/components/ResultBox.js +10 -2
- package/lib/components/ResultBox.js.map +2 -2
- package/lib/components/SearchBox.d.ts +84 -84
- package/lib/components/Select.d.ts +245 -237
- package/lib/components/Select.js +25 -4
- package/lib/components/Select.js.map +2 -2
- package/lib/components/{Checkboxes.d.ts → Selection.d.ts} +273 -98
- package/lib/components/Selection.js +134 -0
- package/lib/components/Selection.js.map +13 -0
- package/lib/components/{TableCheckboxes.d.ts → TableSelection.d.ts} +266 -96
- package/lib/components/{TableCheckboxes.js → TableSelection.js} +30 -30
- package/lib/components/TableSelection.js.map +13 -0
- package/lib/components/Tabs.d.ts +20 -20
- package/lib/components/TabsTransfer.d.ts +84 -84
- package/lib/components/TabsTransfer.js +9 -9
- package/lib/components/TabsTransfer.js.map +2 -2
- package/lib/components/TabsTransferPicker.d.ts +489 -0
- package/lib/components/TabsTransferPicker.js +60 -0
- package/lib/components/TabsTransferPicker.js.map +13 -0
- package/lib/components/Toast.d.ts +90 -87
- package/lib/components/Toast.js +15 -5
- package/lib/components/Toast.js.map +2 -2
- package/lib/components/Transfer.d.ts +908 -274
- package/lib/components/Transfer.js +31 -24
- package/lib/components/Transfer.js.map +2 -2
- package/lib/components/TransferDropDown.d.ts +488 -0
- package/lib/components/TransferDropDown.js +59 -0
- package/lib/components/TransferDropDown.js.map +13 -0
- package/lib/components/TransferPicker.d.ts +493 -0
- package/lib/components/TransferPicker.js +60 -0
- package/lib/components/TransferPicker.js.map +13 -0
- package/lib/components/Tree.d.ts +115 -84
- package/lib/components/Tree.js +183 -30
- package/lib/components/Tree.js.map +2 -2
- package/lib/components/{TreeCheckboxes.d.ts → TreeSelection.d.ts} +269 -99
- package/lib/components/{TreeCheckboxes.js → TreeSelection.js} +36 -32
- package/lib/components/TreeSelection.js.map +13 -0
- package/lib/components/condition-builder/Field.js +4 -2
- package/lib/components/condition-builder/Field.js.map +2 -2
- package/lib/components/condition-builder/Func.js +2 -2
- package/lib/components/condition-builder/Func.js.map +2 -2
- package/lib/components/condition-builder/InputSwitch.js +2 -2
- package/lib/components/condition-builder/InputSwitch.js.map +2 -2
- package/lib/components/condition-builder/Item.js +3 -3
- package/lib/components/condition-builder/Item.js.map +2 -2
- package/lib/components/icons.js +10 -0
- package/lib/components/icons.js.map +2 -2
- package/lib/components/index.d.ts +8 -8
- package/lib/components/index.js +16 -16
- package/lib/components/index.js.map +2 -2
- package/lib/envOverwrite.d.ts +1 -1
- package/lib/envOverwrite.js +24 -9
- package/lib/envOverwrite.js.map +2 -2
- package/lib/factory.d.ts +15 -1
- package/lib/factory.js +35 -6
- package/lib/factory.js.map +2 -2
- package/lib/helper.css.map +1 -1
- package/lib/hooks/index.d.ts +5 -0
- package/lib/hooks/index.js +14 -0
- package/lib/hooks/index.js.map +13 -0
- package/lib/hooks/use-set-state.d.ts +2 -0
- package/lib/hooks/use-set-state.js +15 -0
- package/lib/hooks/use-set-state.js.map +13 -0
- package/lib/hooks/use-touch.d.ts +16 -0
- package/lib/hooks/use-touch.js +73 -0
- package/lib/hooks/use-touch.js.map +13 -0
- package/lib/hooks/use-update-effect.d.ts +3 -0
- package/lib/hooks/use-update-effect.js +17 -0
- package/lib/hooks/use-update-effect.js.map +13 -0
- package/lib/icons/alert-danger.js +7 -0
- package/lib/icons/alert-info.js +7 -0
- package/lib/icons/alert-success.js +7 -0
- package/lib/icons/alert-warning.js +7 -0
- package/lib/icons/download.js +7 -0
- package/lib/icons/drag-bar.js +10 -3
- package/lib/index.d.ts +5 -0
- package/lib/index.js +6 -1
- package/lib/index.js.map +2 -2
- package/lib/locale/de-DE.js +2 -0
- package/lib/locale/de-DE.js.map +2 -2
- package/lib/locale/en-US.js +3 -0
- package/lib/locale/en-US.js.map +2 -2
- package/lib/locale/zh-CN.js +5 -2
- package/lib/locale/zh-CN.js.map +2 -2
- package/lib/renderers/Action.d.ts +10 -5
- package/lib/renderers/Action.js +23 -5
- package/lib/renderers/Action.js.map +2 -2
- package/lib/renderers/Alert.d.ts +21 -1
- package/lib/renderers/Alert.js.map +2 -2
- package/lib/renderers/AnchorNav.d.ts +1 -0
- package/lib/renderers/AnchorNav.js +2 -2
- package/lib/renderers/AnchorNav.js.map +2 -2
- package/lib/renderers/Avatar.js +3 -3
- package/lib/renderers/Avatar.js.map +2 -2
- package/lib/renderers/Breadcrumb.js +1 -1
- package/lib/renderers/Breadcrumb.js.map +2 -2
- package/lib/renderers/CRUD.d.ts +5 -0
- package/lib/renderers/CRUD.js +25 -4
- package/lib/renderers/CRUD.js.map +2 -2
- package/lib/renderers/Card.d.ts +5 -0
- package/lib/renderers/Card.js +34 -23
- package/lib/renderers/Card.js.map +2 -2
- package/lib/renderers/Collapse.d.ts +25 -20
- package/lib/renderers/Collapse.js +10 -72
- package/lib/renderers/Collapse.js.map +2 -2
- package/lib/renderers/CollapseGroup.d.ts +42 -0
- package/lib/renderers/CollapseGroup.js +33 -0
- package/lib/renderers/CollapseGroup.js.map +13 -0
- package/lib/renderers/Form/ConditionBuilder.js +2 -2
- package/lib/renderers/Form/ConditionBuilder.js.map +2 -2
- package/lib/renderers/Form/DiffEditor.d.ts +4 -3
- package/lib/renderers/Form/Editor.d.ts +3 -2
- package/lib/renderers/Form/InputCity.d.ts +84 -84
- package/lib/renderers/Form/InputCity.js +7 -6
- package/lib/renderers/Form/InputCity.js.map +2 -2
- package/lib/renderers/Form/InputColor.d.ts +86 -85
- package/lib/renderers/Form/InputColor.js +1 -1
- package/lib/renderers/Form/InputColor.js.map +2 -2
- package/lib/renderers/Form/InputFile.d.ts +6 -0
- package/lib/renderers/Form/InputFile.js +28 -8
- package/lib/renderers/Form/InputFile.js.map +2 -2
- package/lib/renderers/Form/InputImage.js +11 -4
- package/lib/renderers/Form/InputImage.js.map +2 -2
- package/lib/renderers/Form/Item.d.ts +1 -1
- package/lib/renderers/Form/Item.js +2 -1
- package/lib/renderers/Form/Item.js.map +2 -2
- package/lib/renderers/Form/Options.js +25 -4
- package/lib/renderers/Form/Options.js.map +2 -2
- package/lib/renderers/Form/Select.d.ts +42 -4
- package/lib/renderers/Form/Select.js +37 -3
- package/lib/renderers/Form/Select.js.map +2 -2
- package/lib/renderers/Form/TabsTransferPicker.d.ts +48 -0
- package/lib/renderers/Form/TabsTransferPicker.js +29 -0
- package/lib/renderers/Form/TabsTransferPicker.js.map +13 -0
- package/lib/renderers/Form/Transfer.js +18 -3
- package/lib/renderers/Form/Transfer.js.map +2 -2
- package/lib/renderers/Form/TransferPicker.d.ts +52 -0
- package/lib/renderers/Form/TransferPicker.js +43 -0
- package/lib/renderers/Form/TransferPicker.js.map +13 -0
- package/lib/renderers/Form/TreeSelect.js +2 -2
- package/lib/renderers/Form/TreeSelect.js.map +2 -2
- package/lib/renderers/Form/index.d.ts +5 -0
- package/lib/renderers/Form/index.js +5 -3
- package/lib/renderers/Form/index.js.map +2 -2
- package/lib/renderers/Form/wrapControl.js +13 -1
- package/lib/renderers/Form/wrapControl.js.map +2 -2
- package/lib/renderers/GridNav.d.ts +99 -0
- package/lib/renderers/GridNav.js +82 -0
- package/lib/renderers/GridNav.js.map +13 -0
- package/lib/renderers/IFrame.js +1 -3
- package/lib/renderers/IFrame.js.map +2 -2
- package/lib/renderers/Image.js +7 -5
- package/lib/renderers/Image.js.map +2 -2
- package/lib/renderers/Json.d.ts +4 -0
- package/lib/renderers/Json.js +4 -13
- package/lib/renderers/Json.js.map +2 -2
- package/lib/renderers/Link.d.ts +4 -2
- package/lib/renderers/Link.js +15 -8
- package/lib/renderers/Link.js.map +2 -2
- package/lib/renderers/List.js +1 -1
- package/lib/renderers/List.js.map +2 -2
- package/lib/renderers/Nav.d.ts +21 -21
- package/lib/renderers/Nav.js +37 -19
- package/lib/renderers/Nav.js.map +2 -2
- package/lib/renderers/Page.d.ts +18 -0
- package/lib/renderers/Page.js +53 -9
- package/lib/renderers/Page.js.map +2 -2
- package/lib/renderers/Portlet.d.ts +125 -0
- package/lib/renderers/Portlet.js +156 -0
- package/lib/renderers/Portlet.js.map +13 -0
- package/lib/renderers/Progress.d.ts +23 -3
- package/lib/renderers/Progress.js +15 -19
- package/lib/renderers/Progress.js.map +2 -2
- package/lib/renderers/Property.js +1 -1
- package/lib/renderers/Property.js.map +2 -2
- package/lib/renderers/Table/ColumnToggler.js +1 -1
- package/lib/renderers/Table/ColumnToggler.js.map +2 -2
- package/lib/renderers/Table/TableContent.d.ts +4 -1
- package/lib/renderers/Table/TableContent.js +21 -1
- package/lib/renderers/Table/TableContent.js.map +2 -2
- package/lib/renderers/Table/index.d.ts +5 -1
- package/lib/renderers/Table/index.js +65 -30
- package/lib/renderers/Table/index.js.map +2 -2
- package/lib/renderers/Tabs.js +9 -1
- package/lib/renderers/Tabs.js.map +2 -2
- package/lib/renderers/WebComponent.js +1 -1
- package/lib/renderers/WebComponent.js.map +2 -2
- package/lib/store/combo.d.ts +2 -2
- package/lib/store/form.d.ts +1 -1
- package/lib/store/form.js +3 -5
- package/lib/store/form.js.map +2 -2
- package/lib/store/formItem.js +44 -4
- package/lib/store/formItem.js.map +2 -2
- package/lib/store/table.d.ts +3 -2
- package/lib/store/table.js +35 -12
- package/lib/store/table.js.map +2 -2
- package/lib/themes/ang-ie11.css +934 -222
- package/lib/themes/ang.css +934 -222
- package/lib/themes/ang.css.map +1 -1
- package/lib/themes/antd-ie11.css +934 -222
- package/lib/themes/antd.css +934 -222
- package/lib/themes/antd.css.map +1 -1
- package/lib/themes/cxd-ie11.css +970 -260
- package/lib/themes/cxd.css +970 -260
- package/lib/themes/cxd.css.map +1 -1
- package/lib/themes/dark-ie11.css +934 -222
- package/lib/themes/dark.css +934 -222
- package/lib/themes/dark.css.map +1 -1
- package/lib/themes/default.css +970 -260
- package/lib/themes/default.css.map +1 -1
- package/lib/types.d.ts +38 -1
- package/lib/types.js +0 -5
- package/lib/types.js.map +2 -2
- package/lib/utils/api.d.ts +3 -2
- package/lib/utils/api.js +90 -17
- package/lib/utils/api.js.map +2 -2
- package/lib/utils/dom.d.ts +4 -0
- package/lib/utils/dom.js +11 -1
- package/lib/utils/dom.js.map +2 -2
- package/lib/utils/helper.d.ts +12 -23
- package/lib/utils/helper.js +62 -166
- package/lib/utils/helper.js.map +2 -2
- package/lib/utils/tpl-builtin.d.ts +2 -20
- package/lib/utils/tpl-builtin.js +25 -743
- package/lib/utils/tpl-builtin.js.map +2 -2
- package/lib/utils/tpl.js +24 -0
- package/lib/utils/tpl.js.map +2 -2
- package/package.json +5 -2
- package/schema.json +3966 -1263
- package/scss/_mixins.scss +1 -3
- package/scss/_properties.scss +42 -13
- package/scss/base/_common.scss +3 -0
- package/scss/base/_normalize.scss +2 -0
- package/scss/components/_alert.scss +28 -5
- package/scss/components/_anchor-nav.scss +89 -29
- package/scss/components/_button.scss +12 -0
- package/scss/components/_card.scss +9 -15
- package/scss/components/_collapse-group.scss +15 -0
- package/scss/components/_collapse.scss +48 -23
- package/scss/components/_grid-nav.scss +128 -0
- package/scss/components/_images.scss +1 -0
- package/scss/components/_input-box.scss +1 -0
- package/scss/components/_nav.scss +2 -7
- package/scss/components/_page.scss +35 -2
- package/scss/components/_picker-columns.scss +124 -0
- package/scss/components/_popover.scss +13 -0
- package/scss/components/_portlet.scss +51 -0
- package/scss/components/_progress.scss +141 -33
- package/scss/components/_result-box.scss +1 -0
- package/scss/components/_spinner.scss +5 -4
- package/scss/components/_status.scss +1 -1
- package/scss/components/_table.scss +32 -0
- package/scss/components/_toast.scss +41 -11
- package/scss/components/form/_checks.scss +0 -351
- package/scss/components/form/_color.scss +32 -3
- package/scss/components/form/_combo.scss +4 -0
- package/scss/components/form/_fieldset.scss +6 -1
- package/scss/components/form/_file.scss +11 -0
- package/scss/components/form/_form.scss +48 -0
- package/scss/components/form/_selection.scss +354 -0
- package/scss/components/form/_transfer.scss +76 -18
- package/scss/components/form/_tree.scss +42 -0
- package/scss/themes/_common.scss +6 -0
- package/scss/themes/_cxd-variables.scss +13 -6
- package/scss/themes/cxd.scss +19 -20
- package/sdk/ang-ie11.css +1065 -246
- package/sdk/ang.css +1069 -230
- package/sdk/antd-ie11.css +1068 -249
- package/sdk/antd.css +1069 -230
- package/sdk/charts.js +17 -17
- package/sdk/color-picker.js +65 -69
- package/sdk/cropperjs.js +3 -3
- package/sdk/cxd-ie11.css +1081 -268
- package/sdk/cxd.css +1116 -279
- package/sdk/dark-ie11.css +1069 -250
- package/sdk/dark.css +1069 -230
- package/sdk/exceljs.js +1 -1
- package/sdk/helper.css.map +1 -1
- package/sdk/iconfont.svg +2513 -0
- package/sdk/iconfont.ttf +0 -0
- package/sdk/iconfont.woff +0 -0
- package/sdk/locale/de-DE.js +2 -0
- package/sdk/markdown.js +69 -69
- package/sdk/papaparse.js +1 -1
- package/sdk/renderers/Form/CityDB.js +1 -1
- package/sdk/rest.js +20 -28
- package/sdk/rich-text.js +62 -62
- package/sdk/sdk-ie11.css +1081 -268
- package/sdk/sdk.css +1116 -279
- package/sdk/sdk.js +1371 -1189
- package/sdk/thirds/hls.js/hls.js +18 -18
- package/sdk/thirds/mpegts.js/mpegts.js +2 -2
- package/sdk/tinymce.js +57 -57
- package/src/Schema.ts +19 -1
- package/src/components/Alert2.tsx +32 -4
- package/src/components/AnchorNav.tsx +15 -4
- package/src/components/{AssociatedCheckboxes.tsx → AssociatedSelection.tsx} +43 -37
- package/src/components/Badge.tsx +3 -3
- package/src/components/Button.tsx +1 -0
- package/src/components/{ChainedCheckboxes.tsx → ChainedSelection.tsx} +57 -40
- package/src/components/Collapse.tsx +139 -20
- package/src/components/CollapseGroup.tsx +130 -0
- package/src/components/ColorPicker.tsx +32 -10
- package/src/components/Drawer.tsx +8 -6
- package/src/components/GridNav.tsx +233 -0
- package/src/components/{ListCheckboxes.tsx → GroupedSelection.tsx} +26 -21
- package/src/components/InputBox.tsx +10 -9
- package/src/components/Link.tsx +28 -37
- package/src/components/ModalManager.ts +1 -1
- package/src/components/Overlay.tsx +6 -0
- package/src/components/PickerColumn.tsx +429 -0
- package/src/components/PickerContainer.tsx +128 -0
- package/src/components/PopOver.tsx +15 -1
- package/src/components/Progress.tsx +140 -0
- package/src/components/Radios.tsx +3 -8
- package/src/components/ResultBox.tsx +9 -9
- package/src/components/Select.tsx +57 -5
- package/src/components/{Checkboxes.tsx → Selection.tsx} +75 -21
- package/src/components/{TableCheckboxes.tsx → TableSelection.tsx} +46 -25
- package/src/components/TabsTransfer.tsx +13 -7
- package/src/components/TabsTransferPicker.tsx +85 -0
- package/src/components/Toast.tsx +48 -21
- package/src/components/Transfer.tsx +71 -50
- package/src/components/TransferDropDown.tsx +120 -0
- package/src/components/TransferPicker.tsx +91 -0
- package/src/components/Tree.tsx +194 -8
- package/src/components/{TreeCheckboxes.tsx → TreeSelection.tsx} +33 -26
- package/src/components/condition-builder/Field.tsx +7 -5
- package/src/components/condition-builder/Func.tsx +3 -3
- package/src/components/condition-builder/InputSwitch.tsx +3 -3
- package/src/components/condition-builder/Item.tsx +5 -12
- package/src/components/icons.tsx +10 -0
- package/src/components/index.tsx +13 -13
- package/src/envOverwrite.ts +20 -8
- package/src/factory.tsx +70 -9
- package/src/hooks/index.ts +5 -0
- package/src/hooks/use-set-state.ts +19 -0
- package/src/hooks/use-touch.ts +100 -0
- package/src/hooks/use-update-effect.ts +16 -0
- package/src/icons/alert-danger.svg +1 -0
- package/src/icons/alert-info.svg +1 -0
- package/src/icons/alert-success.svg +1 -0
- package/src/icons/alert-warning.svg +1 -0
- package/src/icons/download.svg +4 -0
- package/src/icons/drag-bar.svg +12 -6
- package/src/index.tsx +5 -0
- package/src/locale/de-DE.ts +2 -0
- package/src/locale/en-US.ts +3 -0
- package/src/locale/zh-CN.ts +5 -2
- package/src/renderers/Action.tsx +58 -3
- package/src/renderers/Alert.tsx +31 -1
- package/src/renderers/AnchorNav.tsx +4 -0
- package/src/renderers/Avatar.tsx +8 -4
- package/src/renderers/Breadcrumb.tsx +5 -1
- package/src/renderers/CRUD.tsx +29 -3
- package/src/renderers/Card.tsx +76 -36
- package/src/renderers/Collapse.tsx +70 -115
- package/src/renderers/CollapseGroup.tsx +80 -0
- package/src/renderers/Form/ConditionBuilder.tsx +2 -2
- package/src/renderers/Form/InputCity.tsx +4 -8
- package/src/renderers/Form/InputColor.tsx +4 -2
- package/src/renderers/Form/InputFile.tsx +65 -24
- package/src/renderers/Form/InputImage.tsx +11 -3
- package/src/renderers/Form/Item.tsx +3 -2
- package/src/renderers/Form/Options.tsx +29 -3
- package/src/renderers/Form/Select.tsx +162 -21
- package/src/renderers/Form/TabsTransferPicker.tsx +123 -0
- package/src/renderers/Form/Transfer.tsx +19 -4
- package/src/renderers/Form/TransferPicker.tsx +145 -0
- package/src/renderers/Form/TreeSelect.tsx +25 -0
- package/src/renderers/Form/index.tsx +15 -2
- package/src/renderers/Form/wrapControl.tsx +26 -1
- package/src/renderers/GridNav.tsx +204 -0
- package/src/renderers/IFrame.tsx +2 -4
- package/src/renderers/Image.tsx +19 -15
- package/src/renderers/Json.tsx +9 -9
- package/src/renderers/Link.tsx +29 -16
- package/src/renderers/List.tsx +1 -1
- package/src/renderers/Nav.tsx +105 -56
- package/src/renderers/Page.tsx +62 -1
- package/src/renderers/Portlet.tsx +423 -0
- package/src/renderers/Progress.tsx +56 -38
- package/src/renderers/Property.tsx +6 -4
- package/src/renderers/Table/ColumnToggler.tsx +1 -1
- package/src/renderers/Table/TableContent.tsx +40 -2
- package/src/renderers/Table/index.tsx +88 -43
- package/src/renderers/Tabs.tsx +9 -1
- package/src/renderers/WebComponent.tsx +2 -2
- package/src/store/form.ts +3 -9
- package/src/store/formItem.ts +94 -2
- package/src/store/table.ts +55 -14
- package/src/types.ts +58 -1
- package/src/utils/api.ts +120 -26
- package/src/utils/dom.tsx +12 -0
- package/src/utils/helper.ts +55 -185
- package/src/utils/tpl-builtin.ts +40 -866
- package/src/utils/tpl.ts +33 -0
- package/tsconfig-for-declaration.json +1 -1
- package/dump.rdb +0 -0
- package/lib/components/AssociatedCheckboxes.d.ts +0 -762
- package/lib/components/AssociatedCheckboxes.js +0 -90
- package/lib/components/AssociatedCheckboxes.js.map +0 -13
- package/lib/components/ChainedCheckboxes.js.map +0 -13
- package/lib/components/Checkboxes.js +0 -101
- package/lib/components/Checkboxes.js.map +0 -13
- package/lib/components/ListCheckboxes.d.ts +0 -739
- package/lib/components/ListCheckboxes.js +0 -48
- package/lib/components/ListCheckboxes.js.map +0 -13
- package/lib/components/ListRadios.d.ts +0 -763
- package/lib/components/ListRadios.js +0 -86
- package/lib/components/ListRadios.js.map +0 -13
- package/lib/components/TableCheckboxes.js.map +0 -13
- package/lib/components/TreeCheckboxes.js.map +0 -13
- package/lib/components/TreeRadios.d.ts +0 -838
- package/lib/components/TreeRadios.js +0 -116
- package/lib/components/TreeRadios.js.map +0 -13
- package/src/components/ListRadios.tsx +0 -159
- package/src/components/TreeRadios.tsx +0 -202
package/src/utils/tpl-builtin.ts
CHANGED
@@ -1,870 +1,39 @@
|
|
1
|
-
import moment from 'moment';
|
2
1
|
import {PlainObject} from '../types';
|
3
2
|
import isPlainObject from 'lodash/isPlainObject';
|
4
|
-
import
|
5
|
-
import {
|
6
|
-
createObject,
|
7
|
-
isObject,
|
8
|
-
setVariable,
|
9
|
-
qsstringify,
|
10
|
-
keyToPath,
|
11
|
-
string2regExp,
|
12
|
-
deleteVariable
|
13
|
-
} from './helper';
|
3
|
+
import {createObject, setVariable, deleteVariable} from './helper';
|
14
4
|
import {Enginer} from './tpl';
|
15
|
-
import
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
[propName: string]: string;
|
48
|
-
} = {
|
49
|
-
'&': '&',
|
50
|
-
'<': '<',
|
51
|
-
'>': '>',
|
52
|
-
'"': '"',
|
53
|
-
"'": ''',
|
54
|
-
'/': '/'
|
55
|
-
};
|
56
|
-
export const escapeHtml = (str: string) =>
|
57
|
-
String(str).replace(/[&<>"'\/]/g, function (s) {
|
58
|
-
return entityMap[s];
|
59
|
-
});
|
60
|
-
|
61
|
-
export function formatDuration(value: number): string {
|
62
|
-
const unit = ['秒', '分', '时', '天', '月', '季', '年'];
|
63
|
-
const steps = [1, 60, 3600, 86400, 2592000, 7776000, 31104000];
|
64
|
-
let len = steps.length;
|
65
|
-
const parts = [];
|
66
|
-
|
67
|
-
while (len--) {
|
68
|
-
if (steps[len] && value >= steps[len]) {
|
69
|
-
parts.push(Math.floor(value / steps[len]) + unit[len]);
|
70
|
-
value %= steps[len];
|
71
|
-
} else if (len === 0 && value) {
|
72
|
-
parts.push((value.toFixed ? value.toFixed(2) : '0') + unit[0]);
|
73
|
-
}
|
74
|
-
}
|
75
|
-
|
76
|
-
return parts.join('');
|
77
|
-
}
|
78
|
-
|
79
|
-
function makeSorter(
|
80
|
-
key: string,
|
81
|
-
method?: 'alpha' | 'numerical',
|
82
|
-
order?: 'desc' | 'asc'
|
83
|
-
) {
|
84
|
-
return function (a: any, b: any) {
|
85
|
-
if (!a || !b) {
|
86
|
-
return 0;
|
87
|
-
}
|
88
|
-
|
89
|
-
const va = resolveVariable(key, a);
|
90
|
-
const vb = resolveVariable(key, b);
|
91
|
-
let result = 0;
|
92
|
-
|
93
|
-
if (method === 'numerical') {
|
94
|
-
result = (parseFloat(va) || 0) - (parseFloat(vb) || 0);
|
95
|
-
} else {
|
96
|
-
result = String(va).localeCompare(String(vb));
|
97
|
-
}
|
98
|
-
|
99
|
-
return result * (order === 'desc' ? -1 : 1);
|
100
|
-
};
|
101
|
-
}
|
102
|
-
|
103
|
-
const timeUnitMap: {
|
104
|
-
[propName: string]: string;
|
105
|
-
} = {
|
106
|
-
year: 'Y',
|
107
|
-
month: 'M',
|
108
|
-
week: 'w',
|
109
|
-
weekday: 'W',
|
110
|
-
day: 'd',
|
111
|
-
hour: 'h',
|
112
|
-
minute: 'm',
|
113
|
-
min: 'm',
|
114
|
-
second: 's',
|
115
|
-
millisecond: 'ms'
|
116
|
-
};
|
117
|
-
|
118
|
-
export const relativeValueRe =
|
119
|
-
/^(.+)?(\+|-)(\d+)(minute|min|hour|day|week|month|year|weekday|second|millisecond)s?$/i;
|
120
|
-
export const filterDate = (
|
121
|
-
value: string,
|
122
|
-
data: object = {},
|
123
|
-
format = 'X',
|
124
|
-
utc: boolean = false
|
125
|
-
): moment.Moment => {
|
126
|
-
let m,
|
127
|
-
mm = utc ? moment.utc : moment;
|
128
|
-
|
129
|
-
if (typeof value === 'string') {
|
130
|
-
value = value.trim();
|
131
|
-
}
|
132
|
-
|
133
|
-
value = tokenize(value, data);
|
134
|
-
|
135
|
-
if (value && typeof value === 'string' && (m = relativeValueRe.exec(value))) {
|
136
|
-
const date = new Date();
|
137
|
-
const step = parseInt(m[3], 10);
|
138
|
-
const from = m[1]
|
139
|
-
? filterDate(m[1], data, format, utc)
|
140
|
-
: mm(
|
141
|
-
/(minute|min|hour|second)s?/.test(m[4])
|
142
|
-
? [
|
143
|
-
date.getFullYear(),
|
144
|
-
date.getMonth(),
|
145
|
-
date.getDate(),
|
146
|
-
date.getHours(),
|
147
|
-
date.getMinutes(),
|
148
|
-
date.getSeconds()
|
149
|
-
]
|
150
|
-
: [date.getFullYear(), date.getMonth(), date.getDate()]
|
151
|
-
);
|
152
|
-
|
153
|
-
return m[2] === '-'
|
154
|
-
? from.subtract(step, timeUnitMap[m[4]] as moment.DurationInputArg2)
|
155
|
-
: from.add(step, timeUnitMap[m[4]] as moment.DurationInputArg2);
|
156
|
-
// return from[m[2] === '-' ? 'subtract' : 'add'](step, mapping[m[4]] || m[4]);
|
157
|
-
} else if (value === 'now') {
|
158
|
-
return mm();
|
159
|
-
} else if (value === 'today') {
|
160
|
-
const date = new Date();
|
161
|
-
return mm([date.getFullYear(), date.getMonth(), date.getDate()]);
|
162
|
-
} else {
|
163
|
-
return mm(value, format);
|
164
|
-
}
|
165
|
-
};
|
166
|
-
|
167
|
-
export function parseDuration(str: string): moment.Duration | undefined {
|
168
|
-
const matches =
|
169
|
-
/^((?:\-|\+)?(?:\d*\.)?\d+)(minute|min|hour|day|week|month|quarter|year|weekday|second|millisecond)s?$/.exec(
|
170
|
-
str
|
171
|
-
);
|
172
|
-
|
173
|
-
if (matches) {
|
174
|
-
const duration = moment.duration(parseFloat(matches[1]), matches[2] as any);
|
175
|
-
|
176
|
-
if (moment.isDuration(duration)) {
|
177
|
-
return duration;
|
178
|
-
}
|
179
|
-
}
|
180
|
-
|
181
|
-
return;
|
182
|
-
}
|
183
|
-
|
184
|
-
// 主要用于解决 0.1+0.2 结果的精度问题导致太长
|
185
|
-
export function stripNumber(number: number) {
|
186
|
-
if (typeof number === 'number') {
|
187
|
-
return parseFloat(number.toPrecision(12));
|
188
|
-
} else {
|
189
|
-
return number;
|
190
|
-
}
|
191
|
-
}
|
192
|
-
|
193
|
-
export const filters: {
|
194
|
-
[propName: string]: (input: any, ...args: any[]) => any;
|
195
|
-
} = {
|
196
|
-
map: (input: Array<unknown>, fn: string, ...arg: any) =>
|
197
|
-
Array.isArray(input) && filters[fn]
|
198
|
-
? input.map(item => filters[fn](item, ...arg))
|
199
|
-
: input,
|
200
|
-
html: (input: string) => escapeHtml(input),
|
201
|
-
json: (input, tabSize: number | string = 2) =>
|
202
|
-
tabSize
|
203
|
-
? JSON.stringify(input, null, parseInt(tabSize as string, 10))
|
204
|
-
: JSON.stringify(input),
|
205
|
-
toJson: input => {
|
206
|
-
let ret;
|
207
|
-
try {
|
208
|
-
ret = JSON.parse(input);
|
209
|
-
} catch (e) {
|
210
|
-
ret = null;
|
211
|
-
}
|
212
|
-
return ret;
|
213
|
-
},
|
214
|
-
toInt: input => (typeof input === 'string' ? parseInt(input, 10) : input),
|
215
|
-
toFloat: input => (typeof input === 'string' ? parseFloat(input) : input),
|
216
|
-
raw: input => input,
|
217
|
-
now: () => new Date(),
|
218
|
-
toDate: (input: any, inputFormat = '') => {
|
219
|
-
const data = moment(input, inputFormat);
|
220
|
-
data.add();
|
221
|
-
return data.isValid() ? data.toDate() : undefined;
|
222
|
-
},
|
223
|
-
fromNow: (input: any, inputFormat = '') =>
|
224
|
-
moment(input, inputFormat).fromNow(),
|
225
|
-
dateModify: (
|
226
|
-
input: any,
|
227
|
-
modifier: 'add' | 'subtract' | 'endOf' | 'startOf' = 'add',
|
228
|
-
amount = 0,
|
229
|
-
unit = 'days'
|
230
|
-
) => {
|
231
|
-
if (!(input instanceof Date)) {
|
232
|
-
input = new Date();
|
233
|
-
}
|
234
|
-
|
235
|
-
if (modifier === 'endOf' || modifier === 'startOf') {
|
236
|
-
return moment(input)
|
237
|
-
[modifier === 'endOf' ? 'endOf' : 'startOf'](amount || 'day')
|
238
|
-
.toDate();
|
239
|
-
}
|
240
|
-
|
241
|
-
return moment(input)
|
242
|
-
[modifier === 'add' ? 'add' : 'subtract'](parseInt(amount, 10) || 0, unit)
|
243
|
-
.toDate();
|
244
|
-
},
|
245
|
-
date: (input, format = 'LLL', inputFormat = 'X') =>
|
246
|
-
moment(input, inputFormat).format(format),
|
247
|
-
number: input => {
|
248
|
-
let parts = String(input).split('.');
|
249
|
-
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
250
|
-
return parts.join('.');
|
251
|
-
},
|
252
|
-
trim: input => (typeof input === 'string' ? input.trim() : input),
|
253
|
-
percent: (input, decimals = 0) => {
|
254
|
-
input = parseFloat(input) || 0;
|
255
|
-
decimals = parseInt(decimals, 10) || 0;
|
256
|
-
|
257
|
-
let whole = input * 100;
|
258
|
-
let multiplier = Math.pow(10, decimals);
|
259
|
-
|
260
|
-
return (
|
261
|
-
(Math.round(whole * multiplier) / multiplier).toFixed(decimals) + '%'
|
262
|
-
);
|
263
|
-
},
|
264
|
-
duration: input => (input ? formatDuration(input) : input),
|
265
|
-
bytes: input => (input ? prettyBytes(parseFloat(input)) : input),
|
266
|
-
round: (input, decimals = 2) => {
|
267
|
-
if (isNaN(input)) {
|
268
|
-
return 0;
|
269
|
-
}
|
270
|
-
|
271
|
-
decimals = parseInt(decimals, 10) ?? 2;
|
272
|
-
|
273
|
-
let multiplier = Math.pow(10, decimals);
|
274
|
-
return (Math.round(input * multiplier) / multiplier).toFixed(decimals);
|
275
|
-
},
|
276
|
-
truncate: (input, length, end) => {
|
277
|
-
if (typeof input !== 'string') {
|
278
|
-
return input;
|
279
|
-
}
|
280
|
-
|
281
|
-
end = end || '...';
|
282
|
-
|
283
|
-
if (length == null) {
|
284
|
-
return input;
|
285
|
-
}
|
286
|
-
|
287
|
-
length = parseInt(length, 10) || 200;
|
288
|
-
|
289
|
-
return input.substring(0, length) + (input.length > length ? end : '');
|
290
|
-
},
|
291
|
-
url_encode: input => encodeURIComponent(input),
|
292
|
-
url_decode: input => decodeURIComponent(input),
|
293
|
-
default: (input, defaultValue, strict = false) =>
|
294
|
-
(strict ? input : input ? input : undefined) ??
|
295
|
-
(() => {
|
296
|
-
try {
|
297
|
-
if (defaultValue === 'undefined') {
|
298
|
-
return undefined;
|
299
|
-
}
|
300
|
-
|
301
|
-
return JSON.parse(defaultValue);
|
302
|
-
} catch (e) {
|
303
|
-
return defaultValue;
|
304
|
-
}
|
305
|
-
})(),
|
306
|
-
join: (input, glue) => (input && input.join ? input.join(glue) : input),
|
307
|
-
split: (input, delimiter = ',') =>
|
308
|
-
typeof input === 'string' ? input.split(delimiter) : input,
|
309
|
-
sortBy: (
|
310
|
-
input: any,
|
311
|
-
key: string,
|
312
|
-
method: 'alpha' | 'numerical' = 'alpha',
|
313
|
-
order?: 'asc' | 'desc'
|
314
|
-
) =>
|
315
|
-
Array.isArray(input) ? input.sort(makeSorter(key, method, order)) : input,
|
316
|
-
objectToArray: (
|
317
|
-
input: any,
|
318
|
-
label: string = 'label',
|
319
|
-
value: string = 'value'
|
320
|
-
) =>
|
321
|
-
transform(
|
322
|
-
input,
|
323
|
-
(result: any, v, k) => {
|
324
|
-
(result || (result = [])).push({
|
325
|
-
[label]: v,
|
326
|
-
[value]: k
|
327
|
-
});
|
328
|
-
},
|
329
|
-
[]
|
330
|
-
),
|
331
|
-
unique: (input: any, key?: string) =>
|
332
|
-
Array.isArray(input) ? (key ? uniqBy(input, key) : uniq(input)) : input,
|
333
|
-
topAndOther: (
|
334
|
-
input: any,
|
335
|
-
len: number = 10,
|
336
|
-
labelField: string = 'name',
|
337
|
-
restLabel = '其他'
|
338
|
-
) => {
|
339
|
-
if (Array.isArray(input) && len) {
|
340
|
-
const grouped = groupBy(input, (item: any) => {
|
341
|
-
const index = input.indexOf(item) + 1;
|
342
|
-
return index >= len ? len : index;
|
343
|
-
});
|
344
|
-
|
345
|
-
return Object.keys(grouped).map((key, index) => {
|
346
|
-
const group = grouped[key];
|
347
|
-
const obj = group.reduce((obj, item) => {
|
348
|
-
Object.keys(item).forEach(key => {
|
349
|
-
if (!obj.hasOwnProperty(key) || key === 'labelField') {
|
350
|
-
obj[key] = item[key];
|
351
|
-
} else if (
|
352
|
-
typeof item[key] === 'number' &&
|
353
|
-
typeof obj[key] === 'number'
|
354
|
-
) {
|
355
|
-
obj[key] += item[key];
|
356
|
-
} else if (
|
357
|
-
typeof item[key] === 'string' &&
|
358
|
-
/^(?:\-|\.)\d/.test(item[key]) &&
|
359
|
-
typeof obj[key] === 'number'
|
360
|
-
) {
|
361
|
-
obj[key] += parseFloat(item[key]) || 0;
|
362
|
-
} else if (
|
363
|
-
typeof item[key] === 'string' &&
|
364
|
-
typeof obj[key] === 'string'
|
365
|
-
) {
|
366
|
-
obj[key] += `, ${item[key]}`;
|
367
|
-
} else {
|
368
|
-
obj[key] = item[key];
|
369
|
-
}
|
370
|
-
});
|
371
|
-
|
372
|
-
return obj;
|
373
|
-
}, {});
|
374
|
-
|
375
|
-
if (index === len - 1) {
|
376
|
-
obj[labelField] = restLabel || '其他';
|
377
|
-
}
|
378
|
-
return obj;
|
379
|
-
});
|
380
|
-
}
|
381
|
-
return input;
|
382
|
-
},
|
383
|
-
first: input => input && input[0],
|
384
|
-
nth: (input, nth = 0) => input && input[nth],
|
385
|
-
last: input => input && (input.length ? input[input.length - 1] : null),
|
386
|
-
minus(input, step = 1) {
|
387
|
-
return stripNumber(
|
388
|
-
(Number(input) || 0) - Number(getStrOrVariable(step, this))
|
389
|
-
);
|
390
|
-
},
|
391
|
-
plus(input, step = 1) {
|
392
|
-
return stripNumber(
|
393
|
-
(Number(input) || 0) + Number(getStrOrVariable(step, this))
|
394
|
-
);
|
395
|
-
},
|
396
|
-
times(input, step = 1) {
|
397
|
-
return stripNumber(
|
398
|
-
(Number(input) || 0) * Number(getStrOrVariable(step, this))
|
399
|
-
);
|
400
|
-
},
|
401
|
-
division(input, step = 1) {
|
402
|
-
return stripNumber(
|
403
|
-
(Number(input) || 0) / Number(getStrOrVariable(step, this))
|
404
|
-
);
|
405
|
-
},
|
406
|
-
count: (input: any) =>
|
407
|
-
Array.isArray(input) || typeof input === 'string' ? input.length : 0,
|
408
|
-
sum: (input, field) => {
|
409
|
-
if (!Array.isArray(input)) {
|
410
|
-
return input;
|
411
|
-
}
|
412
|
-
const restult = input.reduce(
|
413
|
-
(sum, item) =>
|
414
|
-
sum + (parseFloat(field ? pickValues(field, item) : item) || 0),
|
415
|
-
0
|
416
|
-
);
|
417
|
-
return stripNumber(restult);
|
418
|
-
},
|
419
|
-
abs: (input: any) => (typeof input === 'number' ? Math.abs(input) : input),
|
420
|
-
pick: (input, path = '&') =>
|
421
|
-
Array.isArray(input) && !/^\d+$/.test(path)
|
422
|
-
? input.map((item, index) =>
|
423
|
-
pickValues(path, createObject({index}, item))
|
424
|
-
)
|
425
|
-
: pickValues(path, input),
|
426
|
-
pick_if_exist: (input, path = '&') =>
|
427
|
-
Array.isArray(input)
|
428
|
-
? input.map(item => resolveVariable(path, item) || item)
|
429
|
-
: resolveVariable(path, input) || input,
|
430
|
-
str2date: function (input, inputFormat = 'X', outputFormat = 'X') {
|
431
|
-
return input
|
432
|
-
? filterDate(input, this, inputFormat).format(outputFormat)
|
433
|
-
: '';
|
434
|
-
},
|
435
|
-
asArray: input => (Array.isArray(input) ? input : input ? [input] : input),
|
436
|
-
concat(input, ...args: any[]) {
|
437
|
-
return Array.isArray(input)
|
438
|
-
? input.concat(...args.map(arg => getStrOrVariable(arg, this)))
|
439
|
-
: input;
|
440
|
-
},
|
441
|
-
filter: function (input, keys, expOrDirective, arg1) {
|
442
|
-
if (!Array.isArray(input) || !keys || !expOrDirective) {
|
443
|
-
return input;
|
444
|
-
}
|
445
|
-
|
446
|
-
let directive = expOrDirective;
|
447
|
-
let fn: (value: any, key: string, item: any) => boolean = () => true;
|
448
|
-
|
449
|
-
if (directive === 'isTrue') {
|
450
|
-
fn = value => !!value;
|
451
|
-
} else if (directive === 'isFalse') {
|
452
|
-
fn = value => !value;
|
453
|
-
} else if (directive === 'isExists') {
|
454
|
-
fn = value => typeof value !== 'undefined';
|
455
|
-
} else if (directive === 'equals' || directive === 'equal') {
|
456
|
-
arg1 = arg1 ? getStrOrVariable(arg1, this) : '';
|
457
|
-
fn = value => arg1 == value;
|
458
|
-
} else if (directive === 'isIn') {
|
459
|
-
let list: any = arg1 ? getStrOrVariable(arg1, this) : [];
|
460
|
-
|
461
|
-
list = str2array(list);
|
462
|
-
list = Array.isArray(list) ? list : list ? [list] : [];
|
463
|
-
fn = value => (list.length ? !!~list.indexOf(value) : true);
|
464
|
-
} else if (directive === 'notIn') {
|
465
|
-
let list: Array<any> = arg1 ? getStrOrVariable(arg1, this) : [];
|
466
|
-
list = str2array(list);
|
467
|
-
list = Array.isArray(list) ? list : list ? [list] : [];
|
468
|
-
fn = value => !~list.indexOf(value);
|
469
|
-
} else {
|
470
|
-
if (directive !== 'match') {
|
471
|
-
directive = 'match';
|
472
|
-
arg1 = expOrDirective;
|
473
|
-
}
|
474
|
-
arg1 = arg1 ? getStrOrVariable(arg1, this) : '';
|
475
|
-
|
476
|
-
// 比对的值是空时直接返回。
|
477
|
-
if (!arg1) {
|
478
|
-
return input;
|
479
|
-
}
|
480
|
-
|
481
|
-
let reg = string2regExp(`${arg1}`, false);
|
482
|
-
fn = value => reg.test(String(value));
|
483
|
-
}
|
484
|
-
|
485
|
-
// 判断keys是否为*
|
486
|
-
const isAsterisk = /\s*\*\s*/.test(keys);
|
487
|
-
keys = keys.split(/\s*,\s*/);
|
488
|
-
return input.filter((item: any) =>
|
489
|
-
// 当keys为*时从item中获取key
|
490
|
-
(isAsterisk ? Object.keys(item) : keys).some((key: string) =>
|
491
|
-
fn(resolveVariable(key, item), key, item)
|
492
|
-
)
|
493
|
-
);
|
494
|
-
},
|
495
|
-
base64Encode(str) {
|
496
|
-
return btoa(
|
497
|
-
encodeURIComponent(str).replace(
|
498
|
-
/%([0-9A-F]{2})/g,
|
499
|
-
function toSolidBytes(match, p1) {
|
500
|
-
return String.fromCharCode(('0x' + p1) as any);
|
501
|
-
}
|
502
|
-
)
|
503
|
-
);
|
504
|
-
},
|
505
|
-
|
506
|
-
base64Decode(str) {
|
507
|
-
return decodeURIComponent(
|
508
|
-
atob(str)
|
509
|
-
.split('')
|
510
|
-
.map(function (c) {
|
511
|
-
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
512
|
-
})
|
513
|
-
.join('')
|
514
|
-
);
|
515
|
-
},
|
516
|
-
|
517
|
-
lowerCase: input =>
|
518
|
-
input && typeof input === 'string' ? input.toLowerCase() : input,
|
519
|
-
upperCase: input =>
|
520
|
-
input && typeof input === 'string' ? input.toUpperCase() : input,
|
521
|
-
|
522
|
-
isTrue(input, trueValue, falseValue) {
|
523
|
-
return getConditionValue(input, !!input, trueValue, falseValue, this);
|
524
|
-
},
|
525
|
-
isFalse(input, trueValue, falseValue) {
|
526
|
-
return getConditionValue(input, !input, trueValue, falseValue, this);
|
527
|
-
},
|
528
|
-
isMatch(input, matchArg, trueValue, falseValue) {
|
529
|
-
matchArg = getStrOrVariable(matchArg, this as any);
|
530
|
-
return getConditionValue(
|
531
|
-
input,
|
532
|
-
matchArg && string2regExp(`${matchArg}`, false).test(String(input)),
|
533
|
-
trueValue,
|
534
|
-
falseValue,
|
535
|
-
this
|
536
|
-
);
|
537
|
-
},
|
538
|
-
notMatch(input, matchArg, trueValue, falseValue) {
|
539
|
-
matchArg = getStrOrVariable(matchArg, this as any);
|
540
|
-
return getConditionValue(
|
541
|
-
input,
|
542
|
-
matchArg && !string2regExp(`${matchArg}`, false).test(String(input)),
|
543
|
-
trueValue,
|
544
|
-
falseValue,
|
545
|
-
this
|
546
|
-
);
|
547
|
-
},
|
548
|
-
isEquals(input, equalsValue, trueValue, falseValue) {
|
549
|
-
equalsValue = /^\d+$/.test(equalsValue)
|
550
|
-
? parseInt(equalsValue, 10)
|
551
|
-
: getStrOrVariable(equalsValue, this as any);
|
552
|
-
return getConditionValue(
|
553
|
-
input,
|
554
|
-
input === equalsValue,
|
555
|
-
trueValue,
|
556
|
-
falseValue,
|
557
|
-
this
|
558
|
-
);
|
559
|
-
},
|
560
|
-
notEquals(input, equalsValue, trueValue, falseValue) {
|
561
|
-
equalsValue = /^\d+$/.test(equalsValue)
|
562
|
-
? parseInt(equalsValue, 10)
|
563
|
-
: getStrOrVariable(equalsValue, this as any);
|
564
|
-
return getConditionValue(
|
565
|
-
input,
|
566
|
-
input !== equalsValue,
|
567
|
-
trueValue,
|
568
|
-
falseValue,
|
569
|
-
this
|
570
|
-
);
|
571
|
-
}
|
572
|
-
};
|
573
|
-
|
574
|
-
/**
|
575
|
-
* 如果当前传入字符为:'xxx'或者"xxx",则返回字符xxx
|
576
|
-
* 否则去数据域中,获取变量xxx
|
577
|
-
*
|
578
|
-
* @param value 传入字符
|
579
|
-
* @param data 数据域
|
580
|
-
*/
|
581
|
-
function getStrOrVariable(value: string, data: any) {
|
582
|
-
return /^('|")(.*)\1$/.test(value)
|
583
|
-
? RegExp.$2
|
584
|
-
: /^-?\d+$/.test(value)
|
585
|
-
? parseInt(value, 10)
|
586
|
-
: /^(-?\d+)\.\d+?$/.test(value)
|
587
|
-
? parseFloat(value)
|
588
|
-
: /^\[.*\]$/.test(value)
|
589
|
-
? value
|
590
|
-
.substring(1, value.length - 1)
|
591
|
-
.split(/\s*,\s*/)
|
592
|
-
.filter(item => item)
|
593
|
-
: /,/.test(value)
|
594
|
-
? value.split(/\s*,\s*/).filter(item => item)
|
595
|
-
: resolveVariable(value, data);
|
596
|
-
}
|
597
|
-
|
598
|
-
function str2array(list: any) {
|
599
|
-
if (list && typeof list === 'string') {
|
600
|
-
if (/^\[.*\]$/.test(list)) {
|
601
|
-
return list
|
602
|
-
.substring(1, list.length - 1)
|
603
|
-
.split(/\s*,\s*/)
|
604
|
-
.filter(item => item);
|
605
|
-
} else {
|
606
|
-
return list.split(/\s*,\s*/).filter(item => item);
|
607
|
-
}
|
608
|
-
}
|
609
|
-
return list;
|
610
|
-
}
|
611
|
-
|
612
|
-
function getConditionValue(
|
613
|
-
input: string,
|
614
|
-
isTrue: boolean,
|
615
|
-
trueValue: string,
|
616
|
-
falseValue: string,
|
617
|
-
data: any
|
618
|
-
) {
|
619
|
-
return isTrue || (!isTrue && falseValue)
|
620
|
-
? getStrOrVariable(isTrue ? trueValue : falseValue, data)
|
621
|
-
: input;
|
622
|
-
}
|
623
|
-
|
624
|
-
export function registerFilter(
|
625
|
-
name: string,
|
626
|
-
fn: (input: any, ...args: any[]) => any
|
627
|
-
): void {
|
628
|
-
filters[name] = fn;
|
629
|
-
}
|
630
|
-
|
631
|
-
export function getFilters() {
|
632
|
-
return filters;
|
633
|
-
}
|
634
|
-
|
635
|
-
export function pickValues(names: string, data: object) {
|
636
|
-
let arr: Array<string>;
|
637
|
-
if (!names || ((arr = names.split(',')) && arr.length < 2)) {
|
638
|
-
let idx = names.indexOf('~');
|
639
|
-
if (~idx) {
|
640
|
-
let key = names.substring(0, idx);
|
641
|
-
let target = names.substring(idx + 1);
|
642
|
-
return {
|
643
|
-
[key]: resolveVariable(target, data)
|
644
|
-
};
|
645
|
-
}
|
646
|
-
return resolveVariable(names, data);
|
647
|
-
}
|
648
|
-
|
649
|
-
let ret: any = {};
|
650
|
-
arr.forEach(name => {
|
651
|
-
let idx = name.indexOf('~');
|
652
|
-
let target = name;
|
653
|
-
|
654
|
-
if (~idx) {
|
655
|
-
target = name.substring(idx + 1);
|
656
|
-
name = name.substring(0, idx);
|
657
|
-
}
|
658
|
-
|
659
|
-
setVariable(ret, name, resolveVariable(target, data));
|
660
|
-
});
|
661
|
-
return ret;
|
662
|
-
}
|
663
|
-
|
664
|
-
function objectGet(data: any, path: string) {
|
665
|
-
if (typeof data[path] !== 'undefined') {
|
666
|
-
return data[path];
|
667
|
-
}
|
668
|
-
|
669
|
-
let parts = keyToPath(path.replace(/^{|}$/g, ''));
|
670
|
-
return parts.reduce((data, path) => {
|
671
|
-
if ((isObject(data) || Array.isArray(data)) && path in data) {
|
672
|
-
return (data as {[propName: string]: any})[path];
|
673
|
-
}
|
674
|
-
|
675
|
-
return undefined;
|
676
|
-
}, data);
|
677
|
-
}
|
678
|
-
|
679
|
-
function parseJson(str: string, defaultValue?: any) {
|
680
|
-
try {
|
681
|
-
return JSON.parse(str);
|
682
|
-
} catch (e) {
|
683
|
-
return defaultValue;
|
684
|
-
}
|
685
|
-
}
|
686
|
-
|
687
|
-
function getCookie(name: string) {
|
688
|
-
const value = `; ${document.cookie}`;
|
689
|
-
const parts = value.split(`; ${name}=`);
|
690
|
-
if (parts.length === 2) {
|
691
|
-
return parts.pop()!.split(';').shift();
|
692
|
-
}
|
693
|
-
return undefined;
|
694
|
-
}
|
695
|
-
|
696
|
-
export const resolveVariable = (path?: string, data: any = {}): any => {
|
697
|
-
if (!path || !data || typeof path !== 'string') {
|
698
|
-
return undefined;
|
699
|
-
}
|
700
|
-
|
701
|
-
let [ns, varname] = path.split(':');
|
702
|
-
|
703
|
-
if (!varname && ns) {
|
704
|
-
varname = ns;
|
705
|
-
ns = '';
|
706
|
-
}
|
707
|
-
|
708
|
-
if (ns === 'window') {
|
709
|
-
data = window;
|
710
|
-
} else if (ns === 'ls' || ns === 'ss') {
|
711
|
-
let parts = keyToPath(varname.replace(/^{|}$/g, ''));
|
712
|
-
const key = parts.shift()!;
|
713
|
-
const raw =
|
714
|
-
ns === 'ss' ? sessionStorage.getItem(key) : localStorage.getItem(key);
|
715
|
-
|
716
|
-
if (typeof raw === 'string') {
|
717
|
-
const data = parseJson(raw, raw);
|
718
|
-
|
719
|
-
if (isObject(data) && parts.length) {
|
720
|
-
return objectGet(data, parts.join('.'));
|
721
|
-
}
|
722
|
-
|
723
|
-
return data;
|
724
|
-
}
|
725
|
-
|
726
|
-
return undefined;
|
727
|
-
} else if (ns === 'cookie') {
|
728
|
-
const key = varname.replace(/^{|}$/g, '').trim();
|
729
|
-
return getCookie(key);
|
730
|
-
}
|
731
|
-
|
732
|
-
if (varname === '$$') {
|
733
|
-
return data;
|
734
|
-
} else if (varname[0] === '$') {
|
735
|
-
varname = path.substring(1);
|
736
|
-
} else if (varname === '&') {
|
737
|
-
return data;
|
738
|
-
}
|
739
|
-
|
740
|
-
return objectGet(data, varname);
|
741
|
-
};
|
742
|
-
|
743
|
-
export function isPureVariable(path?: any): path is string {
|
744
|
-
return typeof path === 'string'
|
745
|
-
? /^\$(?:((?:\w+\:)?[a-z0-9_.][a-z0-9_.\[\]]*)|{[^}{]+})$/i.test(path)
|
746
|
-
: false;
|
747
|
-
}
|
748
|
-
export const resolveVariableAndFilter = (
|
749
|
-
path?: string,
|
750
|
-
data: object = {},
|
751
|
-
defaultFilter: string = '| html',
|
752
|
-
fallbackValue = (value: any) => value
|
753
|
-
): any => {
|
754
|
-
if (!path) {
|
755
|
-
return undefined;
|
756
|
-
}
|
757
|
-
|
758
|
-
const m =
|
759
|
-
/^(\\)?\$(?:((?:\w+\:)?[a-z0-9_.][a-z0-9_.\[\]]*)|{([\s\S]+)})$/i.exec(
|
760
|
-
path
|
761
|
-
);
|
762
|
-
|
763
|
-
if (!m) {
|
764
|
-
return undefined;
|
765
|
-
}
|
766
|
-
|
767
|
-
const [_, escape, key, key2] = m;
|
768
|
-
|
769
|
-
// 如果是转义如: `\$abc` => `$abc`
|
770
|
-
if (escape) {
|
771
|
-
return _.substring(1);
|
772
|
-
}
|
773
|
-
|
774
|
-
let finalKey: string = key || key2;
|
775
|
-
|
776
|
-
// 先只支持一层吧
|
777
|
-
finalKey = finalKey.replace(
|
778
|
-
/(\\|\\\$)?\$(?:([a-zA-Z0-9_.][a-zA-Z0-9_.\[\]]*)|{([^}{]+)})/g,
|
779
|
-
(_, escape) => {
|
780
|
-
return escape
|
781
|
-
? _.substring(1)
|
782
|
-
: resolveVariableAndFilter(_, data, defaultFilter);
|
783
|
-
}
|
784
|
-
);
|
785
|
-
|
786
|
-
// 默认 html 转义
|
787
|
-
if (!~finalKey.indexOf('|')) {
|
788
|
-
finalKey += defaultFilter;
|
789
|
-
}
|
790
|
-
|
791
|
-
let paths = finalKey.split(/\s*\|\s*/g);
|
792
|
-
let originalKey = finalKey;
|
793
|
-
finalKey = paths.shift() as string;
|
794
|
-
|
795
|
-
let ret = resolveVariable(finalKey, data);
|
796
|
-
|
797
|
-
let prevConInputChanged = false; // 前一个类三元过滤器生效,则跳过后续类三元过滤器
|
798
|
-
|
799
|
-
return ret == null &&
|
800
|
-
!~originalKey.indexOf('default') &&
|
801
|
-
!~originalKey.indexOf('now')
|
802
|
-
? fallbackValue(ret)
|
803
|
-
: paths.reduce((input, filter) => {
|
804
|
-
let params = filter
|
805
|
-
.replace(
|
806
|
-
/([^\\])\\([\:\\])/g,
|
807
|
-
(_, affix, content) =>
|
808
|
-
`${affix}__${content === ':' ? 'colon' : 'slash'}__`
|
809
|
-
)
|
810
|
-
.split(':')
|
811
|
-
.map(item =>
|
812
|
-
item.replace(/__(slash|colon)__/g, (_, type) =>
|
813
|
-
type === 'colon' ? ':' : '\\'
|
814
|
-
)
|
815
|
-
);
|
816
|
-
let key = params.shift() as string;
|
817
|
-
|
818
|
-
if (
|
819
|
-
~[
|
820
|
-
'isTrue',
|
821
|
-
'isFalse',
|
822
|
-
'isMatch',
|
823
|
-
'isEquals',
|
824
|
-
'notMatch',
|
825
|
-
'notEquals'
|
826
|
-
].indexOf(key)
|
827
|
-
) {
|
828
|
-
if (prevConInputChanged) {
|
829
|
-
return input;
|
830
|
-
} else {
|
831
|
-
const result = filters[key].call(data, input, ...params);
|
832
|
-
prevConInputChanged = result !== input;
|
833
|
-
return result;
|
834
|
-
}
|
835
|
-
} else {
|
836
|
-
// 后面再遇到非类三元filter就重置了吧,不影响再后面的其他三元filter
|
837
|
-
prevConInputChanged = false;
|
838
|
-
}
|
839
|
-
|
840
|
-
return (filters[key] || filters.raw).call(data, input, ...params);
|
841
|
-
}, ret);
|
842
|
-
};
|
843
|
-
|
844
|
-
export const tokenize = (
|
845
|
-
str: string,
|
846
|
-
data: object,
|
847
|
-
defaultFilter: string = '| html'
|
848
|
-
) => {
|
849
|
-
if (!str || typeof str !== 'string') {
|
850
|
-
return str;
|
851
|
-
}
|
852
|
-
|
853
|
-
return str.replace(
|
854
|
-
/(\\)?\$(?:((?:\w+\:)?[a-z0-9_\.][a-z0-9_\.\[\]]*|&|\$)|{([^}{]+?)})/gi,
|
855
|
-
(_, escape, key1, key2, index, source) => {
|
856
|
-
if (!escape && key1 === '$') {
|
857
|
-
const prefix = source[index - 1];
|
858
|
-
return prefix === '='
|
859
|
-
? encodeURIComponent(JSON.stringify(data))
|
860
|
-
: qsstringify(data);
|
861
|
-
}
|
862
|
-
|
863
|
-
return escape
|
864
|
-
? _.substring(1)
|
865
|
-
: resolveVariableAndFilter(_, data, defaultFilter) ?? '';
|
866
|
-
}
|
867
|
-
);
|
5
|
+
import {
|
6
|
+
prettyBytes,
|
7
|
+
escapeHtml,
|
8
|
+
formatDuration,
|
9
|
+
filterDate,
|
10
|
+
relativeValueRe,
|
11
|
+
parseDuration,
|
12
|
+
getFilters,
|
13
|
+
registerFilter,
|
14
|
+
pickValues,
|
15
|
+
resolveVariable,
|
16
|
+
isPureVariable,
|
17
|
+
resolveVariableAndFilter,
|
18
|
+
tokenize,
|
19
|
+
stripNumber
|
20
|
+
} from 'amis-formula';
|
21
|
+
|
22
|
+
export {
|
23
|
+
prettyBytes,
|
24
|
+
escapeHtml,
|
25
|
+
formatDuration,
|
26
|
+
filterDate,
|
27
|
+
relativeValueRe,
|
28
|
+
parseDuration,
|
29
|
+
getFilters,
|
30
|
+
registerFilter,
|
31
|
+
pickValues,
|
32
|
+
resolveVariable,
|
33
|
+
isPureVariable,
|
34
|
+
resolveVariableAndFilter,
|
35
|
+
tokenize,
|
36
|
+
stripNumber
|
868
37
|
};
|
869
38
|
|
870
39
|
export function resolveMapping(
|
@@ -1048,7 +217,12 @@ export function register(): Enginer & {name: string} {
|
|
1048
217
|
test: (str: string) => typeof str === 'string' && matchSynatax(str),
|
1049
218
|
removeEscapeToken: (str: string) =>
|
1050
219
|
typeof str === 'string' ? str.replace(/\\\$/g, '$') : str,
|
1051
|
-
compile: (str: string, data: object, defaultFilter = '| html') =>
|
1052
|
-
|
220
|
+
compile: (str: string, data: object, defaultFilter = '| html') => {
|
221
|
+
try {
|
222
|
+
return tokenize(str, data, defaultFilter);
|
223
|
+
} catch (e) {
|
224
|
+
return `error: ${e.message}`;
|
225
|
+
}
|
226
|
+
}
|
1053
227
|
};
|
1054
228
|
}
|