@maple-design/cli-vue 0.0.0-stage → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +305 -2
- package/README.zh-CN.md +305 -0
- package/bin/cli.mjs +5 -0
- package/client.d.ts +1 -0
- package/client.js +1 -0
- package/lib/client/appType.d.ts +4 -0
- package/lib/client/appType.js +7 -0
- package/lib/client/index.d.ts +29 -0
- package/lib/client/index.js +170 -0
- package/lib/client/language.d.ts +11 -0
- package/lib/client/language.js +52 -0
- package/lib/client/theme-state.d.ts +3 -0
- package/lib/client/theme-state.js +6 -0
- package/lib/node/bin.d.ts +2 -0
- package/lib/node/bin.js +154 -0
- package/lib/node/commands/build.d.ts +1 -0
- package/lib/node/commands/build.js +15 -0
- package/lib/node/commands/checklist.d.ts +6 -0
- package/lib/node/commands/checklist.js +59 -0
- package/lib/node/commands/compile.d.ts +3 -0
- package/lib/node/commands/compile.js +41 -0
- package/lib/node/commands/create.d.ts +8 -0
- package/lib/node/commands/create.js +91 -0
- package/lib/node/commands/dev.d.ts +6 -0
- package/lib/node/commands/dev.js +58 -0
- package/lib/node/commands/extension.d.ts +3 -0
- package/lib/node/commands/extension.js +5 -0
- package/lib/node/commands/gen.d.ts +24 -0
- package/lib/node/commands/gen.js +91 -0
- package/lib/node/commands/icons.d.ts +4 -0
- package/lib/node/commands/icons.js +15 -0
- package/lib/node/commands/preview.d.ts +4 -0
- package/lib/node/commands/preview.js +18 -0
- package/lib/node/commands/styleVars.d.ts +1 -0
- package/lib/node/commands/styleVars.js +6 -0
- package/lib/node/commands/test.d.ts +7 -0
- package/lib/node/commands/test.js +16 -0
- package/lib/node/commands/vite.d.ts +2 -0
- package/lib/node/commands/vite.js +14 -0
- package/lib/node/compiler/compileModule.d.ts +4 -0
- package/lib/node/compiler/compileModule.js +78 -0
- package/lib/node/compiler/compileSFC.d.ts +6 -0
- package/lib/node/compiler/compileSFC.js +119 -0
- package/lib/node/compiler/compileScript.d.ts +27 -0
- package/lib/node/compiler/compileScript.js +221 -0
- package/lib/node/compiler/compileSiteEntry.d.ts +19 -0
- package/lib/node/compiler/compileSiteEntry.js +164 -0
- package/lib/node/compiler/compileStyle.d.ts +14 -0
- package/lib/node/compiler/compileStyle.js +55 -0
- package/lib/node/compiler/compileStyleVars.d.ts +3 -0
- package/lib/node/compiler/compileStyleVars.js +46 -0
- package/lib/node/compiler/compileTemplateHighlight.d.ts +18 -0
- package/lib/node/compiler/compileTemplateHighlight.js +133 -0
- package/lib/node/compiler/compileTypes.d.ts +2 -0
- package/lib/node/compiler/compileTypes.js +58 -0
- package/lib/node/compiler/generateLibraryEntry.d.ts +3 -0
- package/lib/node/compiler/generateLibraryEntry.js +152 -0
- package/lib/node/compiler/siteRoutes.d.ts +4 -0
- package/lib/node/compiler/siteRoutes.js +9 -0
- package/lib/node/config/maple.config.d.ts +215 -0
- package/lib/node/config/maple.config.js +32 -0
- package/lib/node/config/maple.default.config.d.ts +2 -0
- package/lib/node/config/maple.default.config.js +386 -0
- package/lib/node/config/site-resolver.d.ts +25 -0
- package/lib/node/config/site-resolver.js +138 -0
- package/lib/node/config/vite.config.d.ts +28 -0
- package/lib/node/config/vite.config.js +209 -0
- package/lib/node/config/vitest.config.d.ts +2 -0
- package/lib/node/config/vitest.config.js +54 -0
- package/lib/node/config/vitest.setup.d.ts +1 -0
- package/lib/node/config/vitest.setup.js +8 -0
- package/lib/node/index.d.ts +13 -0
- package/lib/node/index.js +13 -0
- package/lib/node/release/index.d.ts +20 -0
- package/lib/node/release/index.js +147 -0
- package/lib/node/shared/constant.d.ts +47 -0
- package/lib/node/shared/constant.js +53 -0
- package/lib/node/shared/fsUtils.d.ts +18 -0
- package/lib/node/shared/fsUtils.js +57 -0
- package/lib/node/shared/logger.d.ts +8 -0
- package/lib/node/shared/logger.js +18 -0
- package/lib/node/shared/serial-task.d.ts +2 -0
- package/lib/node/shared/serial-task.js +9 -0
- package/package.json +111 -3
- package/site/documentation-sections.spec.ts +45 -0
- package/site/documentation-sections.ts +48 -0
- package/site/index.html +89 -0
- package/site/mobile/App.vue +437 -0
- package/site/mobile/AppHome.vue +154 -0
- package/site/mobile/main.ts +99 -0
- package/site/mobile/route-sync.spec.ts +34 -0
- package/site/mobile/route-sync.ts +10 -0
- package/site/mobile.html +70 -0
- package/site/module.d.ts +5 -0
- package/site/pc/App.vue +44 -0
- package/site/pc/Layout.vue +641 -0
- package/site/pc/components/AppAd.vue +117 -0
- package/site/pc/components/AppHeader.vue +459 -0
- package/site/pc/components/AppMobile.spec.ts +204 -0
- package/site/pc/components/AppMobile.vue +201 -0
- package/site/pc/components/AppOutline.spec.ts +89 -0
- package/site/pc/components/AppOutline.vue +161 -0
- package/site/pc/components/AppSidebar.vue +144 -0
- package/site/pc/components/code-example/CodeExample.spec.ts +36 -0
- package/site/pc/components/code-example/CodeExample.vue +164 -0
- package/site/pc/components/code-example/codeExample.less +88 -0
- package/site/pc/components/code-example/index.ts +10 -0
- package/site/pc/components/demo-preview/DemoPreview.vue +92 -0
- package/site/pc/components/demo-preview/index.ts +8 -0
- package/site/pc/components/mobile-preview-url.ts +17 -0
- package/site/pc/components/preview-section.spec.ts +24 -0
- package/site/pc/components/preview-section.ts +23 -0
- package/site/pc/main.ts +108 -0
- package/site/pc/pages/index/index.vue +421 -0
- package/site/pc/pages/index/locale/en-US.ts +1 -0
- package/site/pc/pages/index/locale/zh-CN.ts +1 -0
- package/site/pc/responsive-layout.spec.ts +40 -0
- package/site/pc/route-state.spec.ts +34 -0
- package/site/pc/route-state.ts +25 -0
- package/site/pc/scroll-hash.spec.ts +49 -0
- package/site/pc/scroll-hash.ts +25 -0
- package/site/route-recovery.spec.ts +51 -0
- package/site/route-recovery.ts +38 -0
- package/site/tsconfig.json +16 -0
- package/site/types.ts +6 -0
- package/site/utils.ts +45 -0
- package/template/create/[ComponentName].tsx.ejs +16 -0
- package/template/create/[ComponentName].vue.ejs +21 -0
- package/template/create/[componentName].d.ts.ejs +13 -0
- package/template/create/__tests__/index.spec.js.ejs +10 -0
- package/template/create/docs/en-US.md +0 -0
- package/template/create/docs/zh-CN.md +0 -0
- package/template/create/example/index.vue.ejs +17 -0
- package/template/create/example/locale/_index.ts +17 -0
- package/template/create/example/locale/en-US.ts +3 -0
- package/template/create/example/locale/index.ts +24 -0
- package/template/create/example/locale/zh-CN.ts +3 -0
- package/template/create/index.ts.ejs +12 -0
- package/template/create/props.ts +1 -0
- package/template/create/style/[componentName].less.ejs +5 -0
- package/template/create/style/index.less.ejs +1 -0
- package/template/create/style/index.ts.ejs +1 -0
- package/template/generators/base/.browserslistrc +2 -0
- package/template/generators/base/.prettierignore +14 -0
- package/template/generators/base/README.md +90 -0
- package/template/generators/base/_gitignore +19 -0
- package/template/generators/base/eslint.config.js +15 -0
- package/template/generators/base/package.json +97 -0
- package/template/generators/base/prettier.config.js +3 -0
- package/template/generators/base/public/logo.svg +30 -0
- package/template/generators/base/shims/shims-md.d.ts +4 -0
- package/template/generators/base/shims/shims-vue.d.ts +6 -0
- package/template/generators/base/tsconfig.declaration.json +21 -0
- package/template/generators/base/tsconfig.json +28 -0
- package/template/generators/base/ui-build.config.mjs +16 -0
- package/template/generators/config/default/base/docs/home.zh-CN.md +3 -0
- package/template/generators/config/default/base/maple.config.mjs +49 -0
- package/template/generators/config/default/sfc/src/button/Button.vue +34 -0
- package/template/generators/config/default/sfc/src/button/__tests__/index.spec.js +8 -0
- package/template/generators/config/default/sfc/src/button/docs/zh-CN.md +39 -0
- package/template/generators/config/default/sfc/src/button/example/BasicUse.vue +7 -0
- package/template/generators/config/default/sfc/src/button/example/ModifyColor.vue +7 -0
- package/template/generators/config/default/sfc/src/button/example/index.vue +12 -0
- package/template/generators/config/default/sfc/src/button/index.ts +8 -0
- package/template/generators/config/default/sfc/src/button/style/button.less +14 -0
- package/template/generators/config/default/sfc/src/button/style/index.less +1 -0
- package/template/generators/config/default/sfc/src/button/style/index.ts +1 -0
- package/template/generators/config/default/sfc/src/utils/components.ts +20 -0
- package/template/generators/config/default/tsx/src/button/Button.tsx +30 -0
- package/template/generators/config/default/tsx/src/button/__tests__/index.spec.js +8 -0
- package/template/generators/config/default/tsx/src/button/docs/zh-CN.md +39 -0
- package/template/generators/config/default/tsx/src/button/example/BasicUse.vue +7 -0
- package/template/generators/config/default/tsx/src/button/example/ModifyColor.vue +7 -0
- package/template/generators/config/default/tsx/src/button/example/index.vue +12 -0
- package/template/generators/config/default/tsx/src/button/index.ts +8 -0
- package/template/generators/config/default/tsx/src/button/style/button.less +14 -0
- package/template/generators/config/default/tsx/src/button/style/index.less +1 -0
- package/template/generators/config/default/tsx/src/button/style/index.ts +1 -0
- package/template/generators/config/default/tsx/src/utils/components.ts +20 -0
- package/template/generators/config/i18n/base/docs/home.en-US.md +3 -0
- package/template/generators/config/i18n/base/docs/home.zh-CN.md +3 -0
- package/template/generators/config/i18n/base/maple.config.mjs +51 -0
- package/template/generators/config/i18n/sfc/src/button/Button.vue +38 -0
- package/template/generators/config/i18n/sfc/src/button/__tests__/index.spec.js +8 -0
- package/template/generators/config/i18n/sfc/src/button/docs/en-US.md +39 -0
- package/template/generators/config/i18n/sfc/src/button/docs/zh-CN.md +39 -0
- package/template/generators/config/i18n/sfc/src/button/example/BasicUse.vue +11 -0
- package/template/generators/config/i18n/sfc/src/button/example/ModifyColor.vue +11 -0
- package/template/generators/config/i18n/sfc/src/button/example/index.vue +15 -0
- package/template/generators/config/i18n/sfc/src/button/example/locale/en-US.ts +5 -0
- package/template/generators/config/i18n/sfc/src/button/example/locale/index.ts +23 -0
- package/template/generators/config/i18n/sfc/src/button/example/locale/zh-CN.ts +5 -0
- package/template/generators/config/i18n/sfc/src/button/index.ts +8 -0
- package/template/generators/config/i18n/sfc/src/button/style/button.less +14 -0
- package/template/generators/config/i18n/sfc/src/button/style/index.less +1 -0
- package/template/generators/config/i18n/sfc/src/button/style/index.ts +1 -0
- package/template/generators/config/i18n/sfc/src/locale/__tests__/index.spec.js +52 -0
- package/template/generators/config/i18n/sfc/src/locale/docs/en-US.md +26 -0
- package/template/generators/config/i18n/sfc/src/locale/docs/zh-CN.md +25 -0
- package/template/generators/config/i18n/sfc/src/locale/en-US.d.ts +5 -0
- package/template/generators/config/i18n/sfc/src/locale/en-US.ts +7 -0
- package/template/generators/config/i18n/sfc/src/locale/index.ts +82 -0
- package/template/generators/config/i18n/sfc/src/locale/zh-CN.d.ts +5 -0
- package/template/generators/config/i18n/sfc/src/locale/zh-CN.ts +7 -0
- package/template/generators/config/i18n/sfc/src/utils/components.ts +20 -0
- package/template/generators/config/i18n/tsx/src/button/Button.tsx +35 -0
- package/template/generators/config/i18n/tsx/src/button/__tests__/index.spec.js +8 -0
- package/template/generators/config/i18n/tsx/src/button/docs/en-US.md +39 -0
- package/template/generators/config/i18n/tsx/src/button/docs/zh-CN.md +39 -0
- package/template/generators/config/i18n/tsx/src/button/example/BasicUse.vue +11 -0
- package/template/generators/config/i18n/tsx/src/button/example/ModifyColor.vue +11 -0
- package/template/generators/config/i18n/tsx/src/button/example/index.vue +15 -0
- package/template/generators/config/i18n/tsx/src/button/example/locale/en-US.ts +5 -0
- package/template/generators/config/i18n/tsx/src/button/example/locale/index.ts +23 -0
- package/template/generators/config/i18n/tsx/src/button/example/locale/zh-CN.ts +5 -0
- package/template/generators/config/i18n/tsx/src/button/index.ts +8 -0
- package/template/generators/config/i18n/tsx/src/button/style/button.less +14 -0
- package/template/generators/config/i18n/tsx/src/button/style/index.less +1 -0
- package/template/generators/config/i18n/tsx/src/button/style/index.ts +1 -0
- package/template/generators/config/i18n/tsx/src/locale/__tests__/index.spec.js +52 -0
- package/template/generators/config/i18n/tsx/src/locale/docs/en-US.md +26 -0
- package/template/generators/config/i18n/tsx/src/locale/docs/zh-CN.md +25 -0
- package/template/generators/config/i18n/tsx/src/locale/en-US.d.ts +5 -0
- package/template/generators/config/i18n/tsx/src/locale/en-US.ts +7 -0
- package/template/generators/config/i18n/tsx/src/locale/index.ts +82 -0
- package/template/generators/config/i18n/tsx/src/locale/zh-CN.d.ts +5 -0
- package/template/generators/config/i18n/tsx/src/locale/zh-CN.ts +7 -0
- package/template/generators/config/i18n/tsx/src/utils/components.ts +20 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { AppType, watchLang } from '@maple-design/cli-vue/client'
|
|
3
|
+
import VaButton from '..'
|
|
4
|
+
import { t, use } from './locale'
|
|
5
|
+
|
|
6
|
+
watchLang(use)
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<template>
|
|
10
|
+
<app-type>{{ t('basicUse') }}</app-type>
|
|
11
|
+
<va-button>{{ t('start') }}</va-button>
|
|
12
|
+
|
|
13
|
+
<app-type>{{ t('modifyColor') }}</app-type>
|
|
14
|
+
<va-button color="#03A9F4">{{ t('start') }}</va-button>
|
|
15
|
+
</template>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// lib
|
|
2
|
+
import { add as _add, use as _use, useLocale } from '../../../locale'
|
|
3
|
+
import _enCN from '../../../locale/en-US'
|
|
4
|
+
import _zhCN from '../../../locale/zh-CN'
|
|
5
|
+
import enUS from './en-US'
|
|
6
|
+
// mobile example doc
|
|
7
|
+
import zhCN from './zh-CN'
|
|
8
|
+
|
|
9
|
+
const { add, use: exampleUse, t, merge } = useLocale()
|
|
10
|
+
|
|
11
|
+
const use = (lang: string) => {
|
|
12
|
+
_use(lang)
|
|
13
|
+
exampleUse(lang)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { add, t, merge, use }
|
|
17
|
+
|
|
18
|
+
// lib
|
|
19
|
+
_add('zh-CN', _zhCN)
|
|
20
|
+
_add('en-US', _enCN)
|
|
21
|
+
// mobile example doc
|
|
22
|
+
add('zh-CN', zhCN)
|
|
23
|
+
add('en-US', enUS)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import './button';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './index.less'
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { expect, test, vi } from 'vitest'
|
|
2
|
+
import enUS from '../en-US'
|
|
3
|
+
import { useLocale } from '../index'
|
|
4
|
+
|
|
5
|
+
function mockConsole(method, fn = () => {}) {
|
|
6
|
+
const originMethod = console[method]
|
|
7
|
+
|
|
8
|
+
console[method] = fn
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
mockRestore() {
|
|
12
|
+
console[method] = originMethod
|
|
13
|
+
},
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
test('test add lang', () => {
|
|
18
|
+
const { add, use, pack, packs } = useLocale()
|
|
19
|
+
|
|
20
|
+
const LANG = 'custom'
|
|
21
|
+
const PACK = {
|
|
22
|
+
button: 'Custom Text',
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
add(LANG, PACK)
|
|
26
|
+
use(LANG)
|
|
27
|
+
|
|
28
|
+
expect(pack.value.lang).toBe(LANG)
|
|
29
|
+
expect(packs[LANG]).toBe(PACK)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('test merge lang', () => {
|
|
33
|
+
const fn = vi.fn()
|
|
34
|
+
const { mockRestore } = mockConsole('warn', fn)
|
|
35
|
+
const { add, use, merge, pack } = useLocale()
|
|
36
|
+
|
|
37
|
+
const LANG = 'en-US'
|
|
38
|
+
const PACK = {
|
|
39
|
+
button: 'Custom Text',
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
add(LANG, enUS)
|
|
43
|
+
use('zh_HK')
|
|
44
|
+
use(LANG)
|
|
45
|
+
merge('zh_HK', PACK)
|
|
46
|
+
merge(LANG, PACK)
|
|
47
|
+
|
|
48
|
+
expect(pack.value.button).toBe('Custom Text')
|
|
49
|
+
expect(fn).toHaveBeenCalledTimes(2)
|
|
50
|
+
|
|
51
|
+
mockRestore()
|
|
52
|
+
})
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Locale
|
|
2
|
+
|
|
3
|
+
### Intro
|
|
4
|
+
Component library uses Chinese as the default language, support multi-language switch,
|
|
5
|
+
built-in support for `Chinese`, `English`.
|
|
6
|
+
|
|
7
|
+
### Multi-language switch
|
|
8
|
+
The `Locale` component is introduced to realize multi-language switching, and `Locale.add` is used for language extension.
|
|
9
|
+
|
|
10
|
+
```js
|
|
11
|
+
Locale.add('en-US', enUS)
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Use `Locale.use` to switch languages.
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
Locale.use('en-US')
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Use `Locale.merge` to merge languages.
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
Locale.merge('en-US', {
|
|
24
|
+
button: 'Hello'
|
|
25
|
+
})
|
|
26
|
+
```
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# 国际化
|
|
2
|
+
|
|
3
|
+
### 介绍
|
|
4
|
+
组件库使用中文作为默认语言,支持多语言切换,内置支持 `中文`,`英文`。
|
|
5
|
+
|
|
6
|
+
### 多语言切换
|
|
7
|
+
引入 `Locale` 组件实现多语言切换,使用 `Locale.add` 进行语言扩展。
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
Locale.add('en-US', enUS)
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
使用 `Locale.use` 进行切换语言
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
Locale.use('en-US')
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
使用 `Locale.merge` 进行语言合并
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
Locale.merge('en-US', {
|
|
23
|
+
button: 'Hello'
|
|
24
|
+
})
|
|
25
|
+
```
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { ref } from 'vue'
|
|
2
|
+
import type { Ref } from 'vue'
|
|
3
|
+
import zhCN from './zh-CN'
|
|
4
|
+
|
|
5
|
+
export type Message = {
|
|
6
|
+
// Button component
|
|
7
|
+
button: string
|
|
8
|
+
|
|
9
|
+
// internal
|
|
10
|
+
lang?: string
|
|
11
|
+
[key: PropertyKey]: any
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type ValueOf<T> = T[keyof T]
|
|
15
|
+
|
|
16
|
+
const { hasOwnProperty } = Object.prototype
|
|
17
|
+
|
|
18
|
+
const hasOwn = <T extends object>(val: T, key: PropertyKey): key is keyof T => hasOwnProperty.call(val, key)
|
|
19
|
+
|
|
20
|
+
function useLocale<T = Message>() {
|
|
21
|
+
const messages: Record<string, Partial<T>> = {}
|
|
22
|
+
const currentMessage: Ref<Partial<T>> = ref({})
|
|
23
|
+
|
|
24
|
+
const add = (lang: string, message: Partial<T> & { lang?: string }) => {
|
|
25
|
+
message.lang = lang
|
|
26
|
+
messages[lang] = message
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const use = (lang: string) => {
|
|
30
|
+
if (!messages[lang]) {
|
|
31
|
+
console.warn(`The ${lang} does not exist. You can mount a language message using the add method`)
|
|
32
|
+
return {}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
currentMessage.value = messages[lang]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const merge = (lang: string, message: Partial<T>) => {
|
|
39
|
+
if (!messages[lang]) {
|
|
40
|
+
console.warn(`The ${lang} does not exist. You can mount a language message using the add method`)
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
messages[lang] = { ...messages[lang], ...message }
|
|
45
|
+
|
|
46
|
+
use(lang)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const t = (id: string): ValueOf<T> | undefined => {
|
|
50
|
+
if (hasOwn(currentMessage.value, id)) {
|
|
51
|
+
return currentMessage.value[id]
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
messages,
|
|
57
|
+
currentMessage,
|
|
58
|
+
add,
|
|
59
|
+
use,
|
|
60
|
+
merge,
|
|
61
|
+
t,
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const { messages, currentMessage, add, use, merge, t } = useLocale()
|
|
66
|
+
|
|
67
|
+
add('zh-CN', zhCN)
|
|
68
|
+
use('zh-CN')
|
|
69
|
+
|
|
70
|
+
export { messages, currentMessage, add, use, merge, t, useLocale }
|
|
71
|
+
|
|
72
|
+
export const _LocaleComponent = { messages, currentMessage, add, use, merge, t, useLocale }
|
|
73
|
+
|
|
74
|
+
export default {
|
|
75
|
+
messages,
|
|
76
|
+
currentMessage,
|
|
77
|
+
add,
|
|
78
|
+
use,
|
|
79
|
+
merge,
|
|
80
|
+
t,
|
|
81
|
+
useLocale,
|
|
82
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { App, Component, Plugin } from 'vue'
|
|
2
|
+
import { createNamespaceFn } from '@maple-design/shared-vue'
|
|
3
|
+
|
|
4
|
+
export type ComponentWithInstall<T> = T & Plugin
|
|
5
|
+
|
|
6
|
+
export function withInstall<T = Component>(component: Component, target?: T): ComponentWithInstall<T> {
|
|
7
|
+
const componentWithInstall = target ?? component
|
|
8
|
+
|
|
9
|
+
;(componentWithInstall as ComponentWithInstall<T>).install = function (app: App) {
|
|
10
|
+
const { name } = component
|
|
11
|
+
|
|
12
|
+
if (name) {
|
|
13
|
+
app.component(name, component)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return componentWithInstall as ComponentWithInstall<T>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const createNamespace = createNamespaceFn('va')
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { defineComponent, PropType } from 'vue'
|
|
2
|
+
import { createNamespace } from '../utils/components'
|
|
3
|
+
import './style'
|
|
4
|
+
// i18n for component's internal
|
|
5
|
+
import { t } from '../locale'
|
|
6
|
+
|
|
7
|
+
const { name, n, classes } = createNamespace('button')
|
|
8
|
+
|
|
9
|
+
export default defineComponent({
|
|
10
|
+
name,
|
|
11
|
+
props: {
|
|
12
|
+
color: {
|
|
13
|
+
type: String,
|
|
14
|
+
},
|
|
15
|
+
onClick: {
|
|
16
|
+
type: Function as PropType<(e: Event) => void>,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
setup(props, { slots }) {
|
|
20
|
+
const handleClick = (e: Event) => {
|
|
21
|
+
props.onClick?.(e)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return () => {
|
|
25
|
+
const { color } = props
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<button class={n()} style={{ background: color }} onClick={handleClick}>
|
|
29
|
+
{t('button')}
|
|
30
|
+
{slots.default?.()}
|
|
31
|
+
</button>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
})
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Button
|
|
2
|
+
|
|
3
|
+
### Basic Use
|
|
4
|
+
```html
|
|
5
|
+
<va-button>start</va-button>
|
|
6
|
+
```
|
|
7
|
+
|
|
8
|
+
```vue
|
|
9
|
+
import BasicUse from '../example/BasicUse'
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
### Theme Color Button
|
|
13
|
+
```html
|
|
14
|
+
<va-button color="#009688">start</va-button>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```vue
|
|
18
|
+
import ModifyColor from '../example/ModifyColor'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## API
|
|
22
|
+
|
|
23
|
+
### Button Props
|
|
24
|
+
|
|
25
|
+
| Prop | Description | Type | Default |
|
|
26
|
+
| --- | --- | --- | --- |
|
|
27
|
+
| `color` | Button background color | _string_ | `default` |
|
|
28
|
+
|
|
29
|
+
### Button Events
|
|
30
|
+
|
|
31
|
+
| Event | Description | Arguments |
|
|
32
|
+
| --- | --- | --- |
|
|
33
|
+
| `click` | Triggered when the button is clicked | `event: Event` |
|
|
34
|
+
|
|
35
|
+
### Button Slots
|
|
36
|
+
|
|
37
|
+
| Slot | Description | Arguments |
|
|
38
|
+
|-----------| --- | --- |
|
|
39
|
+
| `default` | Button content | `-` |
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# 按钮
|
|
2
|
+
|
|
3
|
+
### 基本使用
|
|
4
|
+
```html
|
|
5
|
+
<va-button>按钮起步</va-button>
|
|
6
|
+
```
|
|
7
|
+
|
|
8
|
+
```vue
|
|
9
|
+
import BasicUse from '../example/BasicUse'
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
### 主题色按钮
|
|
13
|
+
```html
|
|
14
|
+
<va-button color="#009688">按钮起步</va-button>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```vue
|
|
18
|
+
import ModifyColor from '../example/ModifyColor'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## API
|
|
22
|
+
|
|
23
|
+
### Button Props
|
|
24
|
+
|
|
25
|
+
| 参数 | 说明 | 类型 | 默认值 |
|
|
26
|
+
| --- | --- | --- | --- |
|
|
27
|
+
| `color` | 按钮颜色 | _string_ | `default` |
|
|
28
|
+
|
|
29
|
+
### Button Events
|
|
30
|
+
|
|
31
|
+
| 事件名 | 说明 | 参数 |
|
|
32
|
+
| --- | --- | --- |
|
|
33
|
+
| `click` | 点击按钮时触发 | `event: Event` |
|
|
34
|
+
|
|
35
|
+
### Button Slots
|
|
36
|
+
|
|
37
|
+
| 插槽名 | 说明 | 参数 |
|
|
38
|
+
| --- | --- | --- |
|
|
39
|
+
| `default` | 按钮内容 | `-` |
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { watchLang } from '@maple-design/cli-vue/client'
|
|
3
|
+
import VaButton from '..'
|
|
4
|
+
import { t, use } from './locale'
|
|
5
|
+
|
|
6
|
+
watchLang(use, 'pc')
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<template>
|
|
10
|
+
<va-button color="#03A9F4">{{ t('start') }}</va-button>
|
|
11
|
+
</template>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { AppType, watchLang } from '@maple-design/cli-vue/client'
|
|
3
|
+
import VaButton from '..'
|
|
4
|
+
import { t, use } from './locale'
|
|
5
|
+
|
|
6
|
+
watchLang(use)
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<template>
|
|
10
|
+
<app-type>{{ t('basicUse') }}</app-type>
|
|
11
|
+
<va-button>{{ t('start') }}</va-button>
|
|
12
|
+
|
|
13
|
+
<app-type>{{ t('modifyColor') }}</app-type>
|
|
14
|
+
<va-button color="#03A9F4">{{ t('start') }}</va-button>
|
|
15
|
+
</template>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// lib
|
|
2
|
+
import { add as _add, use as _use, useLocale } from '../../../locale'
|
|
3
|
+
import _enCN from '../../../locale/en-US'
|
|
4
|
+
import _zhCN from '../../../locale/zh-CN'
|
|
5
|
+
import enUS from './en-US'
|
|
6
|
+
// mobile example doc
|
|
7
|
+
import zhCN from './zh-CN'
|
|
8
|
+
|
|
9
|
+
const { add, use: exampleUse, t, merge } = useLocale()
|
|
10
|
+
|
|
11
|
+
const use = (lang: string) => {
|
|
12
|
+
_use(lang)
|
|
13
|
+
exampleUse(lang)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { add, t, merge, use }
|
|
17
|
+
|
|
18
|
+
// lib
|
|
19
|
+
_add('zh-CN', _zhCN)
|
|
20
|
+
_add('en-US', _enCN)
|
|
21
|
+
// mobile example doc
|
|
22
|
+
add('zh-CN', zhCN)
|
|
23
|
+
add('en-US', enUS)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import './button';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './index.less'
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { expect, test, vi } from 'vitest'
|
|
2
|
+
import enUS from '../en-US'
|
|
3
|
+
import { useLocale } from '../index'
|
|
4
|
+
|
|
5
|
+
function mockConsole(method, fn = () => {}) {
|
|
6
|
+
const originMethod = console[method]
|
|
7
|
+
|
|
8
|
+
console[method] = fn
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
mockRestore() {
|
|
12
|
+
console[method] = originMethod
|
|
13
|
+
},
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
test('test add lang', () => {
|
|
18
|
+
const { add, use, pack, packs } = useLocale()
|
|
19
|
+
|
|
20
|
+
const LANG = 'custom'
|
|
21
|
+
const PACK = {
|
|
22
|
+
button: 'Custom Text',
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
add(LANG, PACK)
|
|
26
|
+
use(LANG)
|
|
27
|
+
|
|
28
|
+
expect(pack.value.lang).toBe(LANG)
|
|
29
|
+
expect(packs[LANG]).toBe(PACK)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('test merge lang', () => {
|
|
33
|
+
const fn = vi.fn()
|
|
34
|
+
const { mockRestore } = mockConsole('warn', fn)
|
|
35
|
+
const { add, use, merge, pack } = useLocale()
|
|
36
|
+
|
|
37
|
+
const LANG = 'en-US'
|
|
38
|
+
const PACK = {
|
|
39
|
+
button: 'Custom Text',
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
add(LANG, enUS)
|
|
43
|
+
use('zh_HK')
|
|
44
|
+
use(LANG)
|
|
45
|
+
merge('zh_HK', PACK)
|
|
46
|
+
merge(LANG, PACK)
|
|
47
|
+
|
|
48
|
+
expect(pack.value.button).toBe('Custom Text')
|
|
49
|
+
expect(fn).toHaveBeenCalledTimes(2)
|
|
50
|
+
|
|
51
|
+
mockRestore()
|
|
52
|
+
})
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Locale
|
|
2
|
+
|
|
3
|
+
### Intro
|
|
4
|
+
Component library uses Chinese as the default language, support multi-language switch,
|
|
5
|
+
built-in support for `Chinese`, `English`.
|
|
6
|
+
|
|
7
|
+
### Multi-language switch
|
|
8
|
+
The `Locale` component is introduced to realize multi-language switching, and `Locale.add` is used for language extension.
|
|
9
|
+
|
|
10
|
+
```js
|
|
11
|
+
Locale.add('en-US', enUS)
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Use `Locale.use` to switch languages.
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
Locale.use('en-US')
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Use `Locale.merge` to merge languages.
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
Locale.merge('en-US', {
|
|
24
|
+
button: 'Hello'
|
|
25
|
+
})
|
|
26
|
+
```
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# 国际化
|
|
2
|
+
|
|
3
|
+
### 介绍
|
|
4
|
+
组件库使用中文作为默认语言,支持多语言切换,内置支持 `中文`,`英文`。
|
|
5
|
+
|
|
6
|
+
### 多语言切换
|
|
7
|
+
引入 `Locale` 组件实现多语言切换,使用 `Locale.add` 进行语言扩展。
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
Locale.add('en-US', enUS)
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
使用 `Locale.use` 进行切换语言
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
Locale.use('en-US')
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
使用 `Locale.merge` 进行语言合并
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
Locale.merge('en-US', {
|
|
23
|
+
button: 'Hello'
|
|
24
|
+
})
|
|
25
|
+
```
|