@kine-design/core 0.0.1-beta.1 → 0.0.1-beta.11
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/.vlaude/last-session-id +1 -0
- package/assets/style/global.css +1 -0
- package/assets/style/var/Wuxing.css +71 -0
- package/assets/style/var.css +23 -0
- package/components/base/affix/api.ts +16 -0
- package/components/base/affix/index.ts +17 -0
- package/components/base/affix/props.d.ts +34 -0
- package/components/base/affix/useAffix.ts +124 -0
- package/components/base/alert/api.ts +18 -0
- package/components/base/alert/index.ts +15 -0
- package/components/base/alert/props.d.ts +50 -0
- package/components/base/anchor/api.ts +20 -0
- package/components/base/anchor/index.ts +18 -0
- package/components/base/anchor/props.d.ts +46 -0
- package/components/base/anchor/useAnchor.ts +84 -0
- package/components/base/autoComplete/api.ts +24 -0
- package/components/base/autoComplete/index.ts +17 -0
- package/components/base/autoComplete/props.d.ts +75 -0
- package/components/base/autoComplete/useAutoComplete.ts +157 -0
- package/components/base/avatar/api.ts +17 -0
- package/components/base/avatar/avatar.css +61 -0
- package/components/base/avatar/index.ts +15 -0
- package/components/base/avatar/props.d.ts +37 -0
- package/components/base/backTop/api.ts +17 -0
- package/components/base/backTop/index.ts +17 -0
- package/components/base/backTop/props.d.ts +38 -0
- package/components/base/backTop/useBackTop.ts +62 -0
- package/components/base/badge/api.ts +22 -0
- package/components/base/badge/index.ts +15 -0
- package/components/base/badge/props.d.ts +50 -0
- package/components/base/button/api.ts +28 -0
- package/components/base/button/button.css +34 -0
- package/components/base/button/index.ts +17 -0
- package/components/base/button/props.d.ts +66 -0
- package/components/base/button/useButton.ts +37 -0
- package/components/base/card/api.ts +17 -0
- package/components/base/card/index.ts +15 -0
- package/components/base/card/props.d.ts +37 -0
- package/components/base/carousel/api.ts +28 -0
- package/components/base/carousel/index.ts +17 -0
- package/components/base/carousel/props.d.ts +72 -0
- package/components/base/carousel/useCarousel.ts +150 -0
- package/components/base/cascader/api.ts +23 -0
- package/components/base/cascader/index.ts +18 -0
- package/components/base/cascader/props.d.ts +103 -0
- package/components/base/cascader/useCascader.ts +335 -0
- package/components/base/checkbox/api.ts +24 -0
- package/components/base/checkbox/checkbox.css +0 -0
- package/components/base/checkbox/index.ts +17 -0
- package/components/base/checkbox/props.d.ts +77 -0
- package/components/base/checkbox/useCheckbox.ts +43 -0
- package/components/base/collapse/api.ts +21 -0
- package/components/base/collapse/index.ts +18 -0
- package/components/base/collapse/props.d.ts +45 -0
- package/components/base/collapse/useCollapse.ts +81 -0
- package/components/base/datePicker/__tests__/useDatePicker.test.ts +235 -0
- package/components/base/datePicker/api.ts +22 -0
- package/components/base/datePicker/index.ts +19 -0
- package/components/base/datePicker/props.d.ts +86 -0
- package/components/base/datePicker/useDatePicker.ts +375 -0
- package/components/base/divider/api.ts +15 -0
- package/components/base/divider/divider.css +11 -0
- package/components/base/divider/index.ts +15 -0
- package/components/base/divider/props.d.ts +30 -0
- package/components/base/dropdown/api.ts +33 -0
- package/components/base/dropdown/index.ts +18 -0
- package/components/base/dropdown/props.d.ts +60 -0
- package/components/base/dropdown/useDropdown.ts +124 -0
- package/components/base/empty/api.ts +15 -0
- package/components/base/empty/index.ts +15 -0
- package/components/base/empty/props.d.ts +26 -0
- package/components/base/image/__tests__/useImage.test.ts +176 -0
- package/components/base/image/api.ts +25 -0
- package/components/base/image/index.ts +18 -0
- package/components/base/image/props.d.ts +67 -0
- package/components/base/image/useImage.ts +119 -0
- package/components/base/input/api.ts +23 -0
- package/components/base/input/index.ts +17 -0
- package/components/base/input/input.css +19 -0
- package/components/base/input/props.d.ts +85 -0
- package/components/base/input/useInput.ts +63 -0
- package/components/base/inputNumber/__tests__/useInputNumber.test.ts +189 -0
- package/components/base/inputNumber/api.ts +23 -0
- package/components/base/inputNumber/index.ts +17 -0
- package/components/base/inputNumber/props.d.ts +78 -0
- package/components/base/inputNumber/useInputNumber.ts +182 -0
- package/components/base/li/api.ts +15 -0
- package/components/base/li/index.ts +15 -0
- package/components/base/li/props.d.ts +30 -0
- package/components/base/list/api.ts +16 -0
- package/components/base/list/index.ts +17 -0
- package/components/base/list/props.d.ts +33 -0
- package/components/base/list/useList.ts +36 -0
- package/components/base/loading/api.ts +17 -0
- package/components/base/loading/index.ts +15 -0
- package/components/base/loading/props.d.ts +40 -0
- package/components/base/popover/api.ts +28 -0
- package/components/base/popover/index.ts +17 -0
- package/components/base/popover/props.d.ts +73 -0
- package/components/base/popover/usePopover.ts +193 -0
- package/components/base/progress/api.ts +20 -0
- package/components/base/progress/index.ts +17 -0
- package/components/base/progress/props.d.ts +68 -0
- package/components/base/progress/useProgress.ts +28 -0
- package/components/base/radio/api.ts +19 -0
- package/components/base/radio/index.ts +19 -0
- package/components/base/radio/props.d.ts +59 -0
- package/components/base/radio/useRadio.ts +11 -0
- package/components/base/rate/api.ts +18 -0
- package/components/base/rate/index.ts +17 -0
- package/components/base/rate/props.d.ts +49 -0
- package/components/base/rate/useRate.ts +76 -0
- package/components/base/result/api.ts +20 -0
- package/components/base/result/index.ts +15 -0
- package/components/base/result/props.d.ts +36 -0
- package/components/base/select/api.ts +34 -0
- package/components/base/select/index.ts +18 -0
- package/components/base/select/props.d.ts +152 -0
- package/components/base/select/select.css +7 -0
- package/components/base/select/useSelect.ts +281 -0
- package/components/base/select/useSelectTools.ts +60 -0
- package/components/base/skeleton/api.ts +18 -0
- package/components/base/skeleton/index.ts +15 -0
- package/components/base/skeleton/props.d.ts +41 -0
- package/components/base/slider/api.ts +22 -0
- package/components/base/slider/index.ts +17 -0
- package/components/base/slider/props.d.ts +79 -0
- package/components/base/slider/useSlider.ts +87 -0
- package/components/base/space/api.ts +17 -0
- package/components/base/space/index.ts +15 -0
- package/components/base/space/props.d.ts +39 -0
- package/components/base/steps/__tests__/useSteps.test.ts +46 -0
- package/components/base/steps/api.ts +30 -0
- package/components/base/steps/index.ts +22 -0
- package/components/base/steps/props.d.ts +88 -0
- package/components/base/steps/useSteps.ts +101 -0
- package/components/base/switch/api.ts +22 -0
- package/components/base/switch/index.ts +19 -0
- package/components/base/switch/props.d.ts +66 -0
- package/components/base/switch/useSwitch.tsx +80 -0
- package/components/base/tabs/api.ts +23 -0
- package/components/base/tabs/index.ts +18 -0
- package/components/base/tabs/props.d.ts +41 -0
- package/components/base/tabs/useTabs.ts +67 -0
- package/components/base/tag/api.ts +17 -0
- package/components/base/tag/index.ts +15 -0
- package/components/base/tag/props.d.ts +51 -0
- package/components/base/timePicker/__tests__/useTimePicker.test.ts +125 -0
- package/components/base/timePicker/api.ts +24 -0
- package/components/base/timePicker/index.ts +18 -0
- package/components/base/timePicker/props.d.ts +86 -0
- package/components/base/timePicker/useTimePicker.ts +161 -0
- package/components/base/timeline/api.ts +24 -0
- package/components/base/timeline/index.ts +16 -0
- package/components/base/timeline/props.d.ts +60 -0
- package/components/base/tooltip/api.ts +20 -0
- package/components/base/tooltip/index.ts +17 -0
- package/components/base/tooltip/props.d.ts +40 -0
- package/components/base/tooltip/useTooltip.ts +89 -0
- package/components/base/transfer/api.ts +18 -0
- package/components/base/transfer/index.ts +17 -0
- package/components/base/transfer/props.d.ts +63 -0
- package/components/base/transfer/useTransfer.ts +208 -0
- package/components/base/tree/__tests__/tree.test.ts +223 -0
- package/components/base/tree/api.ts +47 -0
- package/components/base/tree/index.ts +29 -0
- package/components/base/tree/props.d.ts +108 -0
- package/components/base/tree/tree.ts +263 -0
- package/components/base/tree/useTree.ts +114 -0
- package/components/message/confirm/api.ts +21 -0
- package/components/message/confirm/index.ts +15 -0
- package/components/message/confirm/props.d.ts +69 -0
- package/components/message/dialog/api.ts +20 -0
- package/components/message/dialog/index.ts +15 -0
- package/components/message/dialog/props.d.ts +62 -0
- package/components/message/drawer/api.ts +33 -0
- package/components/message/drawer/index.ts +15 -0
- package/components/message/drawer/props.d.ts +80 -0
- package/components/message/message/api.ts +27 -0
- package/components/message/message/index.ts +20 -0
- package/components/message/message/props.d.ts +54 -0
- package/components/message/message/useMessage.ts +61 -0
- package/components/message/notification/__tests__/useNotification.test.ts +129 -0
- package/components/message/notification/api.ts +23 -0
- package/components/message/notification/index.ts +19 -0
- package/components/message/notification/props.d.ts +64 -0
- package/components/message/notification/useNotification.ts +79 -0
- package/components/message/popover/MPopover.tsx +94 -0
- package/components/message/popover/api.ts +54 -0
- package/components/message/popover/index.ts +17 -0
- package/components/message/popover/popover.css +21 -0
- package/components/message/popover/props.d.ts +76 -0
- package/components/message/popover/usePopover.ts +234 -0
- package/components/other/darkMode/api.ts +17 -0
- package/components/other/darkMode/index.ts +17 -0
- package/components/other/darkMode/props.d.ts +37 -0
- package/components/other/darkMode/useDarkMode.ts +129 -0
- package/components/template/border/api.ts +18 -0
- package/components/template/border/index.ts +15 -0
- package/components/template/border/props.d.ts +41 -0
- package/components/template/breadcrumb/api.ts +15 -0
- package/components/template/breadcrumb/index.ts +15 -0
- package/components/template/breadcrumb/props.d.ts +45 -0
- package/components/template/descriptions/api.ts +23 -0
- package/components/template/descriptions/index.ts +16 -0
- package/components/template/descriptions/props.d.ts +54 -0
- package/components/template/form/api.ts +23 -0
- package/components/template/form/index.ts +20 -0
- package/components/template/form/props.d.ts +60 -0
- package/components/template/grid/api.ts +20 -0
- package/components/template/grid/index.ts +15 -0
- package/components/template/grid/props.d.ts +48 -0
- package/components/template/menu/__tests__/useMenu.test.ts +157 -0
- package/components/template/menu/api.ts +26 -0
- package/components/template/menu/index.ts +18 -0
- package/components/template/menu/props.d.ts +93 -0
- package/components/template/menu/useMenu.ts +155 -0
- package/components/template/pagination/__tests__/usePagination.test.ts +138 -0
- package/components/template/pagination/api.ts +22 -0
- package/components/template/pagination/index.ts +19 -0
- package/components/template/pagination/props.d.ts +65 -0
- package/components/template/pagination/usePagination.ts +186 -0
- package/components/template/table/__tests__/useTable.test.ts +138 -0
- package/components/template/table/api.ts +18 -0
- package/components/template/table/index.ts +18 -0
- package/components/template/table/props.d.ts +36 -0
- package/components/template/table/useTable.ts +136 -0
- package/components/template/tableColumn/api.ts +17 -0
- package/components/template/tableColumn/index.ts +15 -0
- package/components/template/tableColumn/props.d.ts +32 -0
- package/components/template/virtualList/api.ts +16 -0
- package/components/template/virtualList/index.ts +17 -0
- package/components/template/virtualList/props.d.ts +25 -0
- package/components/template/virtualList/useVirtualList.ts +237 -0
- package/components/types/hook.d.ts +24 -0
- package/components/types/props.d.ts +57 -0
- package/components/types/template.d.ts +59 -0
- package/compositions/common/__tests__/useDebounceFn.test.ts +62 -0
- package/compositions/common/__tests__/useEventListener.test.ts +98 -0
- package/compositions/common/__tests__/usePopover.test.ts +43 -0
- package/compositions/common/__tests__/useTeleport.test.ts +32 -0
- package/compositions/common/defineCore.ts +55 -0
- package/compositions/common/testAnchor.ts +211 -0
- package/compositions/common/useComponentSize.ts +17 -0
- package/compositions/common/useDebounceFn.ts +27 -0
- package/compositions/common/useDrag.ts +65 -0
- package/compositions/common/useElementSize.ts +37 -0
- package/compositions/common/useEventListener.ts +48 -0
- package/compositions/common/useLocale.ts +53 -0
- package/compositions/common/usePopover.ts +45 -0
- package/compositions/common/useResizeObserver.ts +47 -0
- package/compositions/common/useTeleport.ts +24 -0
- package/compositions/input/__tests__/useBooleanInput.test.ts +73 -0
- package/compositions/input/useBooleanInput.ts +52 -0
- package/compositions/modal/__tests__/useModal.test.ts +110 -0
- package/compositions/modal/useModal.ts +72 -0
- package/compositions/popper/useClickAway.ts +41 -0
- package/compositions/popper/usePopper.ts +63 -0
- package/compositions/utils/__tests__/filters.test.ts +136 -0
- package/compositions/utils/filters.ts +135 -0
- package/compositions/virtualList/__tests__/useHeightCache.test.ts +97 -0
- package/compositions/virtualList/enums.ts +52 -0
- package/compositions/virtualList/useContainerObserver.ts +89 -0
- package/compositions/virtualList/useEntries.ts +248 -0
- package/compositions/virtualList/useHeightCache.ts +83 -0
- package/compositions/virtualList/useSentinelObserver.ts +81 -0
- package/dist/components/base/affix/index.d.ts +2 -1
- package/dist/components/base/affix/useAffix.d.ts +7 -5
- package/dist/components/base/anchor/index.d.ts +2 -1
- package/dist/components/base/anchor/useAnchor.d.ts +3 -2
- package/dist/components/base/autoComplete/useAutoComplete.d.ts +14 -5
- package/dist/components/base/avatar/index.d.ts +1 -0
- package/dist/components/base/backTop/index.d.ts +2 -1
- package/dist/components/base/backTop/useBackTop.d.ts +2 -2
- package/dist/components/base/button/index.d.ts +3 -21
- package/dist/components/base/button/useButton.d.ts +5 -2
- package/dist/components/base/carousel/useCarousel.d.ts +7 -3
- package/dist/components/base/cascader/useCascader.d.ts +25 -12
- package/dist/components/base/checkbox/index.d.ts +2 -1
- package/dist/components/base/checkbox/useCheckbox.d.ts +5 -3
- package/dist/components/base/collapse/index.d.ts +2 -1
- package/dist/components/base/collapse/useCollapse.d.ts +4 -3
- package/dist/components/base/datePicker/__tests__/useDatePicker.test.d.ts +1 -0
- package/dist/components/base/datePicker/index.d.ts +1 -1
- package/dist/components/base/datePicker/useDatePicker.d.ts +140 -15
- package/dist/components/base/dropdown/index.d.ts +2 -1
- package/dist/components/base/dropdown/useDropdown.d.ts +13 -6
- package/dist/components/base/image/__tests__/useImage.test.d.ts +1 -0
- package/dist/components/base/image/useImage.d.ts +5 -5
- package/dist/components/base/input/index.d.ts +2 -1
- package/dist/components/base/input/useInput.d.ts +4 -2
- package/dist/components/base/inputNumber/__tests__/useInputNumber.test.d.ts +1 -0
- package/dist/components/base/inputNumber/index.d.ts +2 -1
- package/dist/components/base/inputNumber/useInputNumber.d.ts +4 -3
- package/dist/components/base/li/index.d.ts +1 -0
- package/dist/components/base/list/index.d.ts +2 -1
- package/dist/components/base/list/useList.d.ts +1 -1
- package/dist/components/base/popover/index.d.ts +2 -1
- package/dist/components/base/popover/usePopover.d.ts +10 -9
- package/dist/components/base/progress/index.d.ts +2 -1
- package/dist/components/base/progress/useProgress.d.ts +2 -2
- package/dist/components/base/rate/index.d.ts +2 -1
- package/dist/components/base/rate/useRate.d.ts +3 -2
- package/dist/components/base/select/useSelect.d.ts +10 -9
- package/dist/components/base/slider/index.d.ts +2 -1
- package/dist/components/base/slider/useSlider.d.ts +5 -4
- package/dist/components/base/steps/__tests__/useSteps.test.d.ts +1 -0
- package/dist/components/base/steps/index.d.ts +1 -1
- package/dist/components/base/steps/useSteps.d.ts +5 -5
- package/dist/components/base/switch/index.d.ts +2 -1
- package/dist/components/base/switch/useSwitch.d.ts +9 -3
- package/dist/components/base/tabs/index.d.ts +1 -1
- package/dist/components/base/tabs/useTabs.d.ts +4 -3
- package/dist/components/base/tag/index.d.ts +1 -0
- package/dist/components/base/timePicker/__tests__/useTimePicker.test.d.ts +1 -0
- package/dist/components/base/timePicker/useTimePicker.d.ts +14 -6
- package/dist/components/base/tooltip/index.d.ts +1 -1
- package/dist/components/base/tooltip/useTooltip.d.ts +15 -5
- package/dist/components/base/transfer/useTransfer.d.ts +17 -16
- package/dist/components/base/tree/__tests__/tree.test.d.ts +1 -0
- package/dist/components/base/tree/index.d.ts +1 -1
- package/dist/components/base/tree/useTree.d.ts +2 -1
- package/dist/components/message/drawer/index.d.ts +2 -2
- package/dist/components/message/message/useMessage.d.ts +11 -1
- package/dist/components/message/notification/__tests__/useNotification.test.d.ts +1 -0
- package/dist/components/message/notification/useNotification.d.ts +17 -1
- package/dist/components/message/popover/MPopover.d.ts +6 -1
- package/dist/components/message/popover/index.d.ts +1 -1
- package/dist/components/message/popover/usePopover.d.ts +7 -7
- package/dist/components/other/darkMode/useDarkMode.d.ts +3 -4
- package/dist/components/template/menu/__tests__/useMenu.test.d.ts +1 -0
- package/dist/components/template/menu/index.d.ts +0 -1
- package/dist/components/template/menu/useMenu.d.ts +2 -1
- package/dist/components/template/pagination/__tests__/usePagination.test.d.ts +1 -0
- package/dist/components/template/pagination/index.d.ts +2 -1
- package/dist/components/template/table/__tests__/useTable.test.d.ts +1 -0
- package/dist/components/template/virtualList/index.d.ts +0 -1
- package/dist/components/template/virtualList/useVirtualList.d.ts +10 -7
- package/dist/compositions/common/__tests__/useDebounceFn.test.d.ts +1 -0
- package/dist/compositions/common/__tests__/useEventListener.test.d.ts +1 -0
- package/dist/compositions/common/__tests__/usePopover.test.d.ts +1 -0
- package/dist/compositions/common/__tests__/useTeleport.test.d.ts +1 -0
- package/dist/compositions/common/testAnchor.d.ts +40 -0
- package/dist/compositions/common/useComponentSize.d.ts +6 -0
- package/dist/compositions/common/useDrag.d.ts +1 -1
- package/dist/compositions/common/useElementSize.d.ts +2 -2
- package/dist/compositions/common/useEventListener.d.ts +2 -2
- package/dist/compositions/common/useLocale.d.ts +14 -0
- package/dist/compositions/common/useTeleport.d.ts +4 -2
- package/dist/compositions/input/__tests__/useBooleanInput.test.d.ts +1 -0
- package/dist/compositions/modal/__tests__/useModal.test.d.ts +1 -0
- package/dist/compositions/modal/useModal.d.ts +3 -2
- package/dist/compositions/popper/useClickAway.d.ts +3 -3
- package/dist/compositions/utils/__tests__/filters.test.d.ts +1 -0
- package/dist/compositions/virtualList/__tests__/useHeightCache.test.d.ts +1 -0
- package/dist/core.js +6697 -4188
- package/dist/index.d.ts +2 -0
- package/dist/locale/en.d.ts +3 -0
- package/dist/locale/index.d.ts +9 -0
- package/dist/locale/types.d.ts +222 -0
- package/dist/locale/zh.d.ts +3 -0
- package/dist/runtime/defineHook.d.ts +1 -1
- package/dist/tools/__tests__/empty.test.d.ts +1 -0
- package/dist/tools/empty.d.ts +2 -2
- package/dist/tools/types.d.ts +1 -1
- package/dist/vitest.config.d.ts +10 -0
- package/index.css +1 -0
- package/index.ts +81 -0
- package/locale/.vlaude/last-session-id +1 -0
- package/locale/en.ts +187 -0
- package/locale/index.ts +29 -0
- package/locale/types.ts +214 -0
- package/locale/zh.ts +190 -0
- package/package.json +23 -17
- package/runtime/defineHook.ts +21 -0
- package/tools/__tests__/empty.test.ts +91 -0
- package/tools/empty.ts +81 -0
- package/tools/index.ts +15 -0
- package/tools/types.ts +11 -0
- package/tsconfig.json +8 -0
- package/types/common/common.d.ts +25 -0
- package/types/common/model.d.ts +25 -0
- package/types/index.d.ts +11 -0
- package/types/props.d.ts +13 -0
- package/vite.config.build.ts +41 -0
- package/vitest.config.ts +17 -0
- package/dist/vite.config.build.d.ts +0 -2
package/locale/types.ts
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description kine-design locale message contract.
|
|
3
|
+
* The single source of truth for every user-facing string in the component
|
|
4
|
+
* library. Each language pack (zh / en) must implement this interface in
|
|
5
|
+
* full — a missing key is a compile error, which is exactly the guarantee we
|
|
6
|
+
* want so translations never silently drift out of sync.
|
|
7
|
+
* @author kine-design
|
|
8
|
+
* @version v1.0.0
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Built-in language pack identifiers. The library ships only the two general
|
|
13
|
+
* languages (zh / en). App-specific languages — e.g. Bengali in the factory —
|
|
14
|
+
* are supplied by the consumer as a full `KineLocaleMessages` object passed to
|
|
15
|
+
* `<KConfigProvider :locale="...">`, not bundled here.
|
|
16
|
+
*/
|
|
17
|
+
export type KineLocaleName = 'zh' | 'en';
|
|
18
|
+
|
|
19
|
+
/** Full message dictionary consumed by components via `useLocale()`. */
|
|
20
|
+
export interface KineLocaleMessages {
|
|
21
|
+
/** Shared atoms reused across many components. */
|
|
22
|
+
common: {
|
|
23
|
+
confirm: string;
|
|
24
|
+
cancel: string;
|
|
25
|
+
close: string;
|
|
26
|
+
search: string;
|
|
27
|
+
reset: string;
|
|
28
|
+
all: string;
|
|
29
|
+
noData: string;
|
|
30
|
+
loading: string;
|
|
31
|
+
save: string;
|
|
32
|
+
};
|
|
33
|
+
pagination: {
|
|
34
|
+
/** Text before the count, e.g. "共 " (en: ""). The count renders in its
|
|
35
|
+
* own <span> between prefix and suffix so per-language word order works. */
|
|
36
|
+
totalPrefix: string;
|
|
37
|
+
/** Text after the count, e.g. " 条" (en: " items"). */
|
|
38
|
+
totalSuffix: string;
|
|
39
|
+
};
|
|
40
|
+
datePicker: {
|
|
41
|
+
placeholder: string;
|
|
42
|
+
/** e.g. "2026年" / "2026" */
|
|
43
|
+
year: (year: number | string) => string;
|
|
44
|
+
/** e.g. "6月" / "Jun" */
|
|
45
|
+
month: (month: number | string) => string;
|
|
46
|
+
hour: string;
|
|
47
|
+
minute: string;
|
|
48
|
+
second: string;
|
|
49
|
+
confirm: string;
|
|
50
|
+
/** 7 entries, Sun→Sat ordering as rendered in the calendar header. */
|
|
51
|
+
weekNames: readonly [string, string, string, string, string, string, string];
|
|
52
|
+
/** 12 entries, Jan→Dec. */
|
|
53
|
+
monthNames: readonly [
|
|
54
|
+
string, string, string, string, string, string,
|
|
55
|
+
string, string, string, string, string, string,
|
|
56
|
+
];
|
|
57
|
+
};
|
|
58
|
+
timePicker: {
|
|
59
|
+
placeholder: string;
|
|
60
|
+
hour: string;
|
|
61
|
+
minute: string;
|
|
62
|
+
second: string;
|
|
63
|
+
};
|
|
64
|
+
select: {
|
|
65
|
+
placeholder: string;
|
|
66
|
+
clear: string;
|
|
67
|
+
noData: string;
|
|
68
|
+
loading: string;
|
|
69
|
+
};
|
|
70
|
+
autoComplete: {
|
|
71
|
+
placeholder: string;
|
|
72
|
+
loading: string;
|
|
73
|
+
clear: string;
|
|
74
|
+
noData: string;
|
|
75
|
+
};
|
|
76
|
+
cascader: {
|
|
77
|
+
placeholder: string;
|
|
78
|
+
noMatch: string;
|
|
79
|
+
};
|
|
80
|
+
image: {
|
|
81
|
+
loadError: string;
|
|
82
|
+
zoomOut: string;
|
|
83
|
+
zoomIn: string;
|
|
84
|
+
rotate: string;
|
|
85
|
+
close: string;
|
|
86
|
+
};
|
|
87
|
+
transfer: {
|
|
88
|
+
sourceTitle: string;
|
|
89
|
+
targetTitle: string;
|
|
90
|
+
noData: string;
|
|
91
|
+
filterPlaceholder: string;
|
|
92
|
+
};
|
|
93
|
+
empty: {
|
|
94
|
+
description: string;
|
|
95
|
+
};
|
|
96
|
+
/** Accessibility labels (screen-reader / title text). */
|
|
97
|
+
a11y: {
|
|
98
|
+
rate: string;
|
|
99
|
+
tagClose: string;
|
|
100
|
+
anchorNav: string;
|
|
101
|
+
backTop: string;
|
|
102
|
+
carouselPrev: string;
|
|
103
|
+
carouselNext: string;
|
|
104
|
+
toLightMode: string;
|
|
105
|
+
toDarkMode: string;
|
|
106
|
+
expandSider: string;
|
|
107
|
+
collapseSider: string;
|
|
108
|
+
};
|
|
109
|
+
upload: {
|
|
110
|
+
trigger: string;
|
|
111
|
+
triggerSimple: string;
|
|
112
|
+
/** e.g. 文件 "a.png" 超过大小限制(最大 2MB) */
|
|
113
|
+
oversize: (name: string, max?: string) => string;
|
|
114
|
+
uploadFailed: string;
|
|
115
|
+
statusWaiting: string;
|
|
116
|
+
statusUploading: string;
|
|
117
|
+
statusDone: string;
|
|
118
|
+
statusFailed: string;
|
|
119
|
+
};
|
|
120
|
+
searchTable: {
|
|
121
|
+
search: string;
|
|
122
|
+
reset: string;
|
|
123
|
+
};
|
|
124
|
+
editableTable: {
|
|
125
|
+
summary: string;
|
|
126
|
+
addRow: string;
|
|
127
|
+
addFirstRow: string;
|
|
128
|
+
confirmDelete: string;
|
|
129
|
+
delete: string;
|
|
130
|
+
cancel: string;
|
|
131
|
+
noData: string;
|
|
132
|
+
};
|
|
133
|
+
formPage: {
|
|
134
|
+
loading: string;
|
|
135
|
+
cancel: string;
|
|
136
|
+
saveDraft: string;
|
|
137
|
+
save: string;
|
|
138
|
+
saving: string;
|
|
139
|
+
submit: string;
|
|
140
|
+
submitting: string;
|
|
141
|
+
basicInfo: string;
|
|
142
|
+
/** e.g. "编辑订单" / "Edit Order" */
|
|
143
|
+
editTitle: (title: string) => string;
|
|
144
|
+
/** e.g. "新建订单" / "New Order" */
|
|
145
|
+
createTitle: (title: string) => string;
|
|
146
|
+
};
|
|
147
|
+
approvalDialog: {
|
|
148
|
+
submitTitle: string;
|
|
149
|
+
submitConfirm: string;
|
|
150
|
+
approveTitle: string;
|
|
151
|
+
approveConfirm: string;
|
|
152
|
+
rejectTitle: string;
|
|
153
|
+
rejectConfirm: string;
|
|
154
|
+
rejectPlaceholder: string;
|
|
155
|
+
remarkPlaceholder: string;
|
|
156
|
+
required: string;
|
|
157
|
+
cancel: string;
|
|
158
|
+
processing: string;
|
|
159
|
+
};
|
|
160
|
+
crudPage: {
|
|
161
|
+
all: string;
|
|
162
|
+
/** e.g. "请输入名称" / "Enter Name" */
|
|
163
|
+
fieldPlaceholder: (label: string) => string;
|
|
164
|
+
};
|
|
165
|
+
login: {
|
|
166
|
+
username: string;
|
|
167
|
+
usernamePlaceholder: string;
|
|
168
|
+
password: string;
|
|
169
|
+
passwordPlaceholder: string;
|
|
170
|
+
remember: string;
|
|
171
|
+
login: string;
|
|
172
|
+
loggingIn: string;
|
|
173
|
+
};
|
|
174
|
+
form: {
|
|
175
|
+
inputPlaceholder: (label: string) => string;
|
|
176
|
+
selectPlaceholder: (label: string) => string;
|
|
177
|
+
};
|
|
178
|
+
routes: {
|
|
179
|
+
createSuffix: string;
|
|
180
|
+
editSuffix: string;
|
|
181
|
+
detailSuffix: string;
|
|
182
|
+
};
|
|
183
|
+
/** User-facing request / error feedback (dev-only throws stay hardcoded). */
|
|
184
|
+
request: {
|
|
185
|
+
success: string;
|
|
186
|
+
opFailed: string;
|
|
187
|
+
failed: string;
|
|
188
|
+
failedWithStatus: (status: number | string) => string;
|
|
189
|
+
failedWithMsg: (msg: string) => string;
|
|
190
|
+
timeout: string;
|
|
191
|
+
timeoutRetry: string;
|
|
192
|
+
canceled: string;
|
|
193
|
+
permissionDenied: string;
|
|
194
|
+
invalidUrl: (url: string) => string;
|
|
195
|
+
decodeFailed: (reason: string) => string;
|
|
196
|
+
parseFailed: string;
|
|
197
|
+
networkError: string;
|
|
198
|
+
networkException: string;
|
|
199
|
+
unknownError: (error: string) => string;
|
|
200
|
+
unknown: string;
|
|
201
|
+
uploadFailed: string;
|
|
202
|
+
uploadCanceled: string;
|
|
203
|
+
};
|
|
204
|
+
aiChat: {
|
|
205
|
+
inputPlaceholder: string;
|
|
206
|
+
send: string;
|
|
207
|
+
/** e.g. "对话 3" / "Chat 3" */
|
|
208
|
+
defaultTitle: (n: number) => string;
|
|
209
|
+
phaseTyping: string;
|
|
210
|
+
phaseThinking: string;
|
|
211
|
+
phaseReplying: string;
|
|
212
|
+
phaseSending: string;
|
|
213
|
+
};
|
|
214
|
+
}
|
package/locale/zh.ts
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Chinese (zh) language pack — the historical default. Strings are
|
|
3
|
+
* lifted verbatim from the components they replace, so existing zh behaviour
|
|
4
|
+
* is preserved exactly. One deliberate fix: `weekNames` previously rendered
|
|
5
|
+
* financial numerals (壹/贰/叁…) which was placeholder data leaked into prod.
|
|
6
|
+
* @author kine-design
|
|
7
|
+
* @version v1.0.0
|
|
8
|
+
*/
|
|
9
|
+
import type { KineLocaleMessages } from './types';
|
|
10
|
+
|
|
11
|
+
const zh: KineLocaleMessages = {
|
|
12
|
+
common: {
|
|
13
|
+
confirm: '确定',
|
|
14
|
+
cancel: '取消',
|
|
15
|
+
close: '关闭',
|
|
16
|
+
search: '搜索',
|
|
17
|
+
reset: '重置',
|
|
18
|
+
all: '全部',
|
|
19
|
+
noData: '暂无数据',
|
|
20
|
+
loading: '加载中...',
|
|
21
|
+
save: '保存',
|
|
22
|
+
},
|
|
23
|
+
pagination: {
|
|
24
|
+
totalPrefix: '共 ',
|
|
25
|
+
totalSuffix: ' 条',
|
|
26
|
+
},
|
|
27
|
+
datePicker: {
|
|
28
|
+
placeholder: '请选择日期...',
|
|
29
|
+
year: (year) => `${year}年`,
|
|
30
|
+
month: (month) => `${month}月`,
|
|
31
|
+
hour: '时',
|
|
32
|
+
minute: '分',
|
|
33
|
+
second: '秒',
|
|
34
|
+
confirm: '确定',
|
|
35
|
+
weekNames: ['日', '一', '二', '三', '四', '五', '六'],
|
|
36
|
+
monthNames: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
|
|
37
|
+
},
|
|
38
|
+
timePicker: {
|
|
39
|
+
placeholder: '请选择时间...',
|
|
40
|
+
hour: '时',
|
|
41
|
+
minute: '分',
|
|
42
|
+
second: '秒',
|
|
43
|
+
},
|
|
44
|
+
select: {
|
|
45
|
+
placeholder: '请选择...',
|
|
46
|
+
clear: '清空',
|
|
47
|
+
noData: '暂无数据',
|
|
48
|
+
loading: '加载中...',
|
|
49
|
+
},
|
|
50
|
+
autoComplete: {
|
|
51
|
+
placeholder: '请输入...',
|
|
52
|
+
loading: '加载中',
|
|
53
|
+
clear: '清空',
|
|
54
|
+
noData: '暂无建议',
|
|
55
|
+
},
|
|
56
|
+
cascader: {
|
|
57
|
+
placeholder: '请选择',
|
|
58
|
+
noMatch: '暂无匹配数据',
|
|
59
|
+
},
|
|
60
|
+
image: {
|
|
61
|
+
loadError: '加载失败',
|
|
62
|
+
zoomOut: '缩小',
|
|
63
|
+
zoomIn: '放大',
|
|
64
|
+
rotate: '旋转',
|
|
65
|
+
close: '关闭',
|
|
66
|
+
},
|
|
67
|
+
transfer: {
|
|
68
|
+
sourceTitle: '源列表',
|
|
69
|
+
targetTitle: '目标列表',
|
|
70
|
+
noData: '暂无数据',
|
|
71
|
+
filterPlaceholder: '请输入搜索内容',
|
|
72
|
+
},
|
|
73
|
+
empty: {
|
|
74
|
+
description: '暂无数据',
|
|
75
|
+
},
|
|
76
|
+
a11y: {
|
|
77
|
+
rate: '评分',
|
|
78
|
+
tagClose: '关闭',
|
|
79
|
+
anchorNav: '锚点导航',
|
|
80
|
+
backTop: '回到顶部',
|
|
81
|
+
carouselPrev: '上一张',
|
|
82
|
+
carouselNext: '下一张',
|
|
83
|
+
toLightMode: '切换到亮色模式',
|
|
84
|
+
toDarkMode: '切换到暗色模式',
|
|
85
|
+
expandSider: '展开侧边栏',
|
|
86
|
+
collapseSider: '折叠侧边栏',
|
|
87
|
+
},
|
|
88
|
+
upload: {
|
|
89
|
+
trigger: '点击或拖拽文件到此处上传',
|
|
90
|
+
triggerSimple: '点击上传文件',
|
|
91
|
+
oversize: (name, max) =>
|
|
92
|
+
max ? `文件 "${name}" 超过大小限制(最大 ${max})` : `文件 "${name}" 超过大小限制`,
|
|
93
|
+
uploadFailed: '上传失败',
|
|
94
|
+
statusWaiting: '等待中',
|
|
95
|
+
statusUploading: '上传中',
|
|
96
|
+
statusDone: '已完成',
|
|
97
|
+
statusFailed: '上传失败',
|
|
98
|
+
},
|
|
99
|
+
searchTable: {
|
|
100
|
+
search: '搜索',
|
|
101
|
+
reset: '重置',
|
|
102
|
+
},
|
|
103
|
+
editableTable: {
|
|
104
|
+
summary: '合计',
|
|
105
|
+
addRow: '+ 添加行',
|
|
106
|
+
addFirstRow: '添加第一行',
|
|
107
|
+
confirmDelete: '确定删除这一行?',
|
|
108
|
+
delete: '删除',
|
|
109
|
+
cancel: '取消',
|
|
110
|
+
noData: '暂无数据',
|
|
111
|
+
},
|
|
112
|
+
formPage: {
|
|
113
|
+
loading: '加载中...',
|
|
114
|
+
cancel: '取消',
|
|
115
|
+
saveDraft: '保存草稿',
|
|
116
|
+
save: '保存',
|
|
117
|
+
saving: '保存中...',
|
|
118
|
+
submit: '提交',
|
|
119
|
+
submitting: '提交中...',
|
|
120
|
+
basicInfo: '基本信息',
|
|
121
|
+
editTitle: (title) => `编辑${title}`,
|
|
122
|
+
createTitle: (title) => `新建${title}`,
|
|
123
|
+
},
|
|
124
|
+
approvalDialog: {
|
|
125
|
+
submitTitle: '提交审批',
|
|
126
|
+
submitConfirm: '确认提交',
|
|
127
|
+
approveTitle: '审批通过',
|
|
128
|
+
approveConfirm: '确认通过',
|
|
129
|
+
rejectTitle: '驳回申请',
|
|
130
|
+
rejectConfirm: '确认驳回',
|
|
131
|
+
rejectPlaceholder: '请输入驳回原因...',
|
|
132
|
+
remarkPlaceholder: '添加备注(可选)...',
|
|
133
|
+
required: '* 必填',
|
|
134
|
+
cancel: '取消',
|
|
135
|
+
processing: '处理中...',
|
|
136
|
+
},
|
|
137
|
+
crudPage: {
|
|
138
|
+
all: '全部',
|
|
139
|
+
fieldPlaceholder: (label) => `请输入${label}`,
|
|
140
|
+
},
|
|
141
|
+
login: {
|
|
142
|
+
username: '用户名',
|
|
143
|
+
usernamePlaceholder: '请输入用户名',
|
|
144
|
+
password: '密码',
|
|
145
|
+
passwordPlaceholder: '请输入密码',
|
|
146
|
+
remember: '记住我',
|
|
147
|
+
login: '登 录',
|
|
148
|
+
loggingIn: '登录中...',
|
|
149
|
+
},
|
|
150
|
+
form: {
|
|
151
|
+
inputPlaceholder: (label) => `请输入${label}`,
|
|
152
|
+
selectPlaceholder: (label) => `请选择${label}`,
|
|
153
|
+
},
|
|
154
|
+
routes: {
|
|
155
|
+
createSuffix: ' - 新建',
|
|
156
|
+
editSuffix: ' - 编辑',
|
|
157
|
+
detailSuffix: ' - 详情',
|
|
158
|
+
},
|
|
159
|
+
request: {
|
|
160
|
+
success: '操作成功',
|
|
161
|
+
opFailed: '操作失败',
|
|
162
|
+
failed: '请求失败',
|
|
163
|
+
failedWithStatus: (status) => `请求失败(${status})`,
|
|
164
|
+
failedWithMsg: (msg) => `请求失败: ${msg}`,
|
|
165
|
+
timeout: '请求超时',
|
|
166
|
+
timeoutRetry: '请求超时,请稍后重试',
|
|
167
|
+
canceled: '请求已取消',
|
|
168
|
+
permissionDenied: '权限不足,无法执行此操作',
|
|
169
|
+
invalidUrl: (url) => `无效的请求地址: ${url}`,
|
|
170
|
+
decodeFailed: (reason) => `解码失败: ${reason}`,
|
|
171
|
+
parseFailed: '数据解析失败',
|
|
172
|
+
networkError: '网络错误',
|
|
173
|
+
networkException: '网络异常,请检查网络连接',
|
|
174
|
+
unknownError: (error) => `未知错误: ${error}`,
|
|
175
|
+
unknown: '发生了未知错误',
|
|
176
|
+
uploadFailed: '上传失败',
|
|
177
|
+
uploadCanceled: '上传已取消',
|
|
178
|
+
},
|
|
179
|
+
aiChat: {
|
|
180
|
+
inputPlaceholder: '输入消息…',
|
|
181
|
+
send: '发送',
|
|
182
|
+
defaultTitle: (n) => `对话 ${n}`,
|
|
183
|
+
phaseTyping: '正在输入…',
|
|
184
|
+
phaseThinking: '思考中…',
|
|
185
|
+
phaseReplying: '回复中…',
|
|
186
|
+
phaseSending: '发送中…',
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
export default zh;
|
package/package.json
CHANGED
|
@@ -1,32 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kine-design/core",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.11",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/core.js",
|
|
7
|
-
"module": "./dist/core.js",
|
|
8
7
|
"types": "./dist/index.d.ts",
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"import": {
|
|
12
|
-
"types": "./dist/index.d.ts",
|
|
13
|
-
"default": "./dist/core.js"
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
"./*": "./*"
|
|
8
|
+
"peerDependencies": {
|
|
9
|
+
"vue": "^3.5.30"
|
|
17
10
|
},
|
|
18
|
-
"files": [
|
|
19
|
-
"dist"
|
|
20
|
-
],
|
|
21
11
|
"dependencies": {
|
|
22
|
-
"@floating-ui/dom": "^1.
|
|
23
|
-
"dayjs": "^1.11.
|
|
12
|
+
"@floating-ui/dom": "^1.7.6",
|
|
13
|
+
"dayjs": "^1.11.20",
|
|
24
14
|
"interactjs": "^1.10.26"
|
|
25
15
|
},
|
|
26
16
|
"publishConfig": {
|
|
27
|
-
"access": "public"
|
|
17
|
+
"access": "public",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"vitest": "^4.1.0"
|
|
28
24
|
},
|
|
29
25
|
"scripts": {
|
|
30
|
-
"build": "vite build --config vite.config.build.ts"
|
|
26
|
+
"build": "vite build --config vite.config.build.ts",
|
|
27
|
+
"test": "vitest --config vitest.config.ts --run"
|
|
28
|
+
},
|
|
29
|
+
"module": "./dist/core.js",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"default": "./dist/core.js"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
31
37
|
}
|
|
32
38
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description used to create powerful typescript support hook define
|
|
3
|
+
* @author 阿怪
|
|
4
|
+
* @date 2024/12/16 11:10
|
|
5
|
+
* @version v1.0.0
|
|
6
|
+
*
|
|
7
|
+
* 江湖的业务千篇一律,复杂的代码好几百行。
|
|
8
|
+
*/
|
|
9
|
+
import { EmitsOptions, SetupContext, SlotsType } from 'vue';
|
|
10
|
+
import { UseHookResult } from '../components/types/hook';
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
export const defineHook = <
|
|
14
|
+
Props extends Record<string, any>,
|
|
15
|
+
E extends EmitsOptions = {},
|
|
16
|
+
S extends SlotsType = {},
|
|
17
|
+
Return = any
|
|
18
|
+
>(hook: (props: Props, ctx: SetupContext<E, S>) => Return):
|
|
19
|
+
(props: Props, ctx: SetupContext<E, S>) => UseHookResult<Props, S, Return> => {
|
|
20
|
+
return hook;
|
|
21
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description notEmpty / isEmpty 工具函数测试
|
|
3
|
+
* @author 阿怪
|
|
4
|
+
* @date 2026/3/23
|
|
5
|
+
* @version v1.0.0
|
|
6
|
+
*
|
|
7
|
+
* 江湖的业务千篇一律,复杂的代码好几百行。
|
|
8
|
+
*/
|
|
9
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
10
|
+
import { notEmpty, isEmpty } from '../empty';
|
|
11
|
+
|
|
12
|
+
describe('notEmpty', () => {
|
|
13
|
+
// 基本空值
|
|
14
|
+
it('null 为空', () => expect(notEmpty(null)).toBe(false));
|
|
15
|
+
it('undefined 为空', () => expect(notEmpty(undefined)).toBe(false));
|
|
16
|
+
|
|
17
|
+
// 字符串
|
|
18
|
+
it('空字符串为空', () => expect(notEmpty('')).toBe(false));
|
|
19
|
+
it('非空字符串非空', () => expect(notEmpty('hello')).toBe(true));
|
|
20
|
+
|
|
21
|
+
// 数字
|
|
22
|
+
it('0 非空', () => expect(notEmpty(0)).toBe(true));
|
|
23
|
+
it('正数非空', () => expect(notEmpty(42)).toBe(true));
|
|
24
|
+
it('NaN 非空(数字类型)', () => expect(notEmpty(NaN)).toBe(true));
|
|
25
|
+
|
|
26
|
+
// 布尔
|
|
27
|
+
it('false 非空', () => expect(notEmpty(false)).toBe(true));
|
|
28
|
+
it('true 非空', () => expect(notEmpty(true)).toBe(true));
|
|
29
|
+
|
|
30
|
+
// 函数
|
|
31
|
+
it('函数非空', () => expect(notEmpty(() => {})).toBe(true));
|
|
32
|
+
|
|
33
|
+
// Symbol
|
|
34
|
+
it('空 Symbol 为空', () => expect(notEmpty(Symbol())).toBe(false));
|
|
35
|
+
it('有描述的 Symbol 非空', () => expect(notEmpty(Symbol('desc'))).toBe(true));
|
|
36
|
+
|
|
37
|
+
// 数组
|
|
38
|
+
it('空数组为空', () => expect(notEmpty([])).toBe(false));
|
|
39
|
+
it('非空数组非空', () => expect(notEmpty([1])).toBe(true));
|
|
40
|
+
|
|
41
|
+
// 对象
|
|
42
|
+
it('空对象为空', () => expect(notEmpty({})).toBe(false));
|
|
43
|
+
it('非空对象非空', () => expect(notEmpty({ a: 1 })).toBe(true));
|
|
44
|
+
|
|
45
|
+
// Map / Set
|
|
46
|
+
it('空 Map 为空', () => expect(notEmpty(new Map())).toBe(false));
|
|
47
|
+
it('非空 Map 非空', () => expect(notEmpty(new Map([['a', 1]]))).toBe(true));
|
|
48
|
+
it('空 Set 为空', () => expect(notEmpty(new Set())).toBe(false));
|
|
49
|
+
it('非空 Set 非空', () => expect(notEmpty(new Set([1]))).toBe(true));
|
|
50
|
+
|
|
51
|
+
// Date
|
|
52
|
+
it('有效 Date 非空', () => expect(notEmpty(new Date())).toBe(true));
|
|
53
|
+
it('Invalid Date 为空', () => expect(notEmpty(new Date('invalid'))).toBe(false));
|
|
54
|
+
|
|
55
|
+
// RegExp
|
|
56
|
+
it('空正则为空', () => expect(notEmpty(new RegExp(''))).toBe(false));
|
|
57
|
+
it('非空正则非空', () => expect(notEmpty(/abc/)).toBe(true));
|
|
58
|
+
|
|
59
|
+
// TypedArray
|
|
60
|
+
// notEmpty 对 TypedArray 返回 value.length(number),0 为 falsy,>0 为 truthy
|
|
61
|
+
it('空 Uint8Array 为空', () => expect(notEmpty(new Uint8Array(0))).toBe(0));
|
|
62
|
+
it('非空 Float64Array 非空', () => expect(notEmpty(new Float64Array([1.5]))).toBe(1));
|
|
63
|
+
|
|
64
|
+
// WeakMap / WeakSet — 无法判断是否为空,始终返回 false 并 console.error
|
|
65
|
+
it('WeakMap 无法判断,返回 false', () => {
|
|
66
|
+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
67
|
+
expect(notEmpty(new WeakMap())).toBe(false);
|
|
68
|
+
expect(spy).toHaveBeenCalledWith('WeakMap和WeakSet无法以通用的方式判断是否为空。');
|
|
69
|
+
spy.mockRestore();
|
|
70
|
+
});
|
|
71
|
+
it('WeakSet 无法判断,返回 false', () => {
|
|
72
|
+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
73
|
+
expect(notEmpty(new WeakSet())).toBe(false);
|
|
74
|
+
expect(spy).toHaveBeenCalledWith('WeakMap和WeakSet无法以通用的方式判断是否为空。');
|
|
75
|
+
spy.mockRestore();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// BigInt — typeof bigint 分支,始终返回 true
|
|
79
|
+
it('BigInt(0) 非空', () => expect(notEmpty(BigInt(0))).toBe(true));
|
|
80
|
+
it('BigInt(42) 非空', () => expect(notEmpty(BigInt(42))).toBe(true));
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('isEmpty', () => {
|
|
84
|
+
it('是 notEmpty 的取反', () => {
|
|
85
|
+
expect(isEmpty(null)).toBe(true);
|
|
86
|
+
expect(isEmpty('hello')).toBe(false);
|
|
87
|
+
expect(isEmpty(0)).toBe(false);
|
|
88
|
+
expect(isEmpty([])).toBe(true);
|
|
89
|
+
expect(isEmpty({})).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
});
|
package/tools/empty.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description common tools
|
|
3
|
+
* @author 阿怪
|
|
4
|
+
* @date 2023/4/20 22:31
|
|
5
|
+
* @version v1.0.0
|
|
6
|
+
*
|
|
7
|
+
* 江湖的业务千篇一律,复杂的代码好几百行。
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 支持稍多类型的判断非空的方法
|
|
12
|
+
* @param value
|
|
13
|
+
*/
|
|
14
|
+
export const notEmpty = (value: unknown) => {
|
|
15
|
+
// 先处理基本类型
|
|
16
|
+
// null
|
|
17
|
+
// undefined
|
|
18
|
+
if (value === undefined || value === null) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
const valueType = typeof value;
|
|
22
|
+
// string
|
|
23
|
+
if (valueType === 'string') {
|
|
24
|
+
return value !== '';
|
|
25
|
+
}
|
|
26
|
+
// number bigint boolean
|
|
27
|
+
if (valueType === 'number' || valueType === 'bigint' || valueType === 'boolean' || valueType === 'function') {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
// symbol
|
|
31
|
+
if (valueType === 'symbol') {
|
|
32
|
+
return value.toString() !== 'Symbol()';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (valueType === 'object') {
|
|
36
|
+
// Bigint/Symbol no new
|
|
37
|
+
|
|
38
|
+
if (value instanceof String || value instanceof Array) {
|
|
39
|
+
return value.length !== 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (value instanceof Number || value instanceof Boolean) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (value instanceof Map || value instanceof Set) {
|
|
47
|
+
return value.size > 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (value instanceof WeakMap || value instanceof WeakSet) {
|
|
51
|
+
console.error('WeakMap和WeakSet无法以通用的方式判断是否为空。');
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (value instanceof RegExp) {
|
|
56
|
+
return value.toString() !== '/(?:)/';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (value instanceof Date) {
|
|
60
|
+
return value.toString() !== 'Invalid Date';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const typedArrayTypes = [Int8Array, Uint8Array, Uint8ClampedArray,
|
|
64
|
+
Int16Array, Uint16Array,
|
|
65
|
+
Int32Array, Uint32Array, Float32Array,
|
|
66
|
+
Float64Array];
|
|
67
|
+
for (const arrayType of typedArrayTypes) {
|
|
68
|
+
if (value instanceof arrayType) {
|
|
69
|
+
return value.length;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return Object.keys(value).length > 0;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 判断为空的方法,即notEmpty的取反
|
|
79
|
+
* @param value
|
|
80
|
+
*/
|
|
81
|
+
export const isEmpty = (value: unknown) => !notEmpty(value);
|
package/tools/index.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description tools index
|
|
3
|
+
* @author 阿怪
|
|
4
|
+
* @date 2023/4/20 22:38
|
|
5
|
+
* @version v1.0.0
|
|
6
|
+
*
|
|
7
|
+
* 江湖的业务千篇一律,复杂的代码好几百行。
|
|
8
|
+
*/
|
|
9
|
+
// import clsx from 'clsx';
|
|
10
|
+
//
|
|
11
|
+
// export {
|
|
12
|
+
// clsx
|
|
13
|
+
// };
|
|
14
|
+
export * from './empty.ts';
|
|
15
|
+
export * from './types.ts';
|
package/tools/types.ts
ADDED