@antdv-vue/pro-provider 0.0.0-stage → 2.0.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/CHANGELOG.md +68 -0
- package/README.md +136 -2
- package/dist/ConfigProviderContainer.d.ts +10 -0
- package/dist/ConfigProviderContainer.js +207 -0
- package/dist/ProConfigProvider.d.ts +12 -0
- package/dist/ProConfigProvider.js +115 -0
- package/dist/context.d.ts +2810 -0
- package/dist/context.js +37 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +7 -0
- package/dist/intl.d.ts +220 -0
- package/dist/intl.js +188 -0
- package/dist/locale/ar_EG.d.ts +6 -0
- package/dist/locale/ar_EG.js +99 -0
- package/dist/locale/ca_ES.d.ts +6 -0
- package/dist/locale/ca_ES.js +99 -0
- package/dist/locale/cs_CZ.d.ts +6 -0
- package/dist/locale/cs_CZ.js +99 -0
- package/dist/locale/de_DE.d.ts +6 -0
- package/dist/locale/de_DE.js +99 -0
- package/dist/locale/en_GB.d.ts +6 -0
- package/dist/locale/en_GB.js +99 -0
- package/dist/locale/en_US.d.ts +6 -0
- package/dist/locale/en_US.js +99 -0
- package/dist/locale/es_ES.d.ts +6 -0
- package/dist/locale/es_ES.js +99 -0
- package/dist/locale/fa_IR.d.ts +6 -0
- package/dist/locale/fa_IR.js +99 -0
- package/dist/locale/fr_FR.d.ts +6 -0
- package/dist/locale/fr_FR.js +99 -0
- package/dist/locale/he_IL.d.ts +6 -0
- package/dist/locale/he_IL.js +99 -0
- package/dist/locale/hr_HR.d.ts +6 -0
- package/dist/locale/hr_HR.js +99 -0
- package/dist/locale/id_ID.d.ts +6 -0
- package/dist/locale/id_ID.js +99 -0
- package/dist/locale/it_IT.d.ts +6 -0
- package/dist/locale/it_IT.js +99 -0
- package/dist/locale/ja_JP.d.ts +6 -0
- package/dist/locale/ja_JP.js +99 -0
- package/dist/locale/ko_KR.d.ts +6 -0
- package/dist/locale/ko_KR.js +99 -0
- package/dist/locale/mn_MN.d.ts +6 -0
- package/dist/locale/mn_MN.js +99 -0
- package/dist/locale/ms_MY.d.ts +6 -0
- package/dist/locale/ms_MY.js +99 -0
- package/dist/locale/nl_NL.d.ts +6 -0
- package/dist/locale/nl_NL.js +99 -0
- package/dist/locale/pl_PL.d.ts +6 -0
- package/dist/locale/pl_PL.js +99 -0
- package/dist/locale/pt_BR.d.ts +6 -0
- package/dist/locale/pt_BR.js +99 -0
- package/dist/locale/ro_RO.d.ts +6 -0
- package/dist/locale/ro_RO.js +99 -0
- package/dist/locale/ru_RU.d.ts +6 -0
- package/dist/locale/ru_RU.js +99 -0
- package/dist/locale/sk_SK.d.ts +6 -0
- package/dist/locale/sk_SK.js +99 -0
- package/dist/locale/sr_RS.d.ts +6 -0
- package/dist/locale/sr_RS.js +99 -0
- package/dist/locale/sv_SE.d.ts +6 -0
- package/dist/locale/sv_SE.js +99 -0
- package/dist/locale/th_TH.d.ts +6 -0
- package/dist/locale/th_TH.js +99 -0
- package/dist/locale/tr_TR.d.ts +6 -0
- package/dist/locale/tr_TR.js +99 -0
- package/dist/locale/uk_UA.d.ts +6 -0
- package/dist/locale/uk_UA.js +99 -0
- package/dist/locale/uz_UZ.d.ts +6 -0
- package/dist/locale/uz_UZ.js +99 -0
- package/dist/locale/vi_VN.d.ts +6 -0
- package/dist/locale/vi_VN.js +99 -0
- package/dist/locale/zh_CN.d.ts +112 -0
- package/dist/locale/zh_CN.js +106 -0
- package/dist/locale/zh_HK.d.ts +6 -0
- package/dist/locale/zh_HK.js +99 -0
- package/dist/locale/zh_TW.d.ts +6 -0
- package/dist/locale/zh_TW.js +99 -0
- package/dist/pro-provider.esm.js +4147 -0
- package/dist/typing/layoutToken.d.ts +625 -0
- package/dist/typing/layoutToken.js +72 -0
- package/dist/typing.d.ts +99 -0
- package/dist/typing.js +1 -0
- package/dist/useStyle/index.d.ts +162 -0
- package/dist/useStyle/index.js +254 -0
- package/dist/useStyle/token.d.ts +35 -0
- package/dist/useStyle/token.js +421 -0
- package/dist/utils/index.d.ts +13 -0
- package/dist/utils/index.js +21 -0
- package/dist/utils/merge.d.ts +20 -0
- package/dist/utils/merge.js +36 -0
- package/package.json +65 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# @antdv-vue/pro-provider
|
|
2
|
+
|
|
3
|
+
## 2.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- feat!: remove the UMD bundle target from package builds.
|
|
8
|
+
- docs: sync structured changelog pages for every package.
|
|
9
|
+
|
|
10
|
+
## 1.0.14
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- fix provider Algorithm bugs
|
|
15
|
+
|
|
16
|
+
## 1.0.13
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- fix layout filed form card bugs
|
|
21
|
+
|
|
22
|
+
## 1.0.12
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- Fix layout multi-tab prop forwarding, make SettingDrawer extra settings extensible, and align docs deployment build command.
|
|
27
|
+
|
|
28
|
+
## 1.0.11
|
|
29
|
+
|
|
30
|
+
### Patch Changes
|
|
31
|
+
|
|
32
|
+
- Refine layout multi-tab rendering and setting drawer dark theme behavior.
|
|
33
|
+
|
|
34
|
+
## 1.0.10
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- fix provider styles and locale exports
|
|
39
|
+
|
|
40
|
+
## 1.0.9
|
|
41
|
+
|
|
42
|
+
### Patch Changes
|
|
43
|
+
|
|
44
|
+
- fix bugs
|
|
45
|
+
|
|
46
|
+
## 1.0.8
|
|
47
|
+
|
|
48
|
+
### Patch Changes
|
|
49
|
+
|
|
50
|
+
- create listy card mode
|
|
51
|
+
|
|
52
|
+
## 1.0.7
|
|
53
|
+
|
|
54
|
+
### Patch Changes
|
|
55
|
+
|
|
56
|
+
- change version
|
|
57
|
+
|
|
58
|
+
## 1.0.6
|
|
59
|
+
|
|
60
|
+
### Patch Changes
|
|
61
|
+
|
|
62
|
+
- fix layout bugs and listy
|
|
63
|
+
|
|
64
|
+
## 1.0.5
|
|
65
|
+
|
|
66
|
+
### Patch Changes
|
|
67
|
+
|
|
68
|
+
- fix ProForm bugs
|
package/README.md
CHANGED
|
@@ -1,3 +1,137 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @antdv-vue/pro-provider
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Global configuration provider, internationalization (i18n), and theme context for Pro Components.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @antdv-vue/pro-provider
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @antdv-vue/pro-provider
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Peer Dependencies
|
|
14
|
+
|
|
15
|
+
- `vue` >= 3.5.30
|
|
16
|
+
- `antdv-next` >= 1.3.6
|
|
17
|
+
|
|
18
|
+
## What's Included
|
|
19
|
+
|
|
20
|
+
### Components
|
|
21
|
+
|
|
22
|
+
| Component | Description |
|
|
23
|
+
|-----------|-------------|
|
|
24
|
+
| `ProConfigProvider` | Global configuration provider for Pro Components |
|
|
25
|
+
|
|
26
|
+
### Exports
|
|
27
|
+
|
|
28
|
+
| Export | Description |
|
|
29
|
+
|--------|-------------|
|
|
30
|
+
| `ProConfigProvider` | Global config provider wrapper component |
|
|
31
|
+
| `useIntl` | Composable to access current internationalization instance |
|
|
32
|
+
| `intlMap` | Built-in i18n language map |
|
|
33
|
+
| Context utilities | Shared context providers and consumers |
|
|
34
|
+
| `useStyle` | CSS-in-JS style composition utilities |
|
|
35
|
+
| Layout token types | Type definitions for layout design tokens |
|
|
36
|
+
|
|
37
|
+
### ProConfigProvider Props
|
|
38
|
+
|
|
39
|
+
| Prop | Type | Default | Description |
|
|
40
|
+
|------|------|---------|-------------|
|
|
41
|
+
| `dark` | `boolean` | `false` | Enable dark theme |
|
|
42
|
+
| `compact` | `boolean` | `false` | Enable compact mode |
|
|
43
|
+
| `needDeps` | `boolean` | — | Whether dependencies are needed |
|
|
44
|
+
| `token` | `DeepPartial<ProAliasToken>` | — | Custom design tokens |
|
|
45
|
+
| `prefixCls` | `string` | — | CSS class prefix |
|
|
46
|
+
| `valueTypeMap` | `Record<string, ProRenderFieldPropsType>` | — | Custom value type renderers |
|
|
47
|
+
| `hashed` | `boolean` | — | Enable CSS-in-JS hash |
|
|
48
|
+
| `intl` | `IntlType` | — | Custom internationalization instance |
|
|
49
|
+
|
|
50
|
+
### Core Types
|
|
51
|
+
|
|
52
|
+
| Type | Description |
|
|
53
|
+
|------|-------------|
|
|
54
|
+
| `ProSchemaValueEnumType` | Value enum configuration (text, status, color, disabled) |
|
|
55
|
+
| `ProSchemaValueEnumMap` | Map-based value enum |
|
|
56
|
+
| `ProSchemaValueEnumObj` | Object-based value enum |
|
|
57
|
+
| `ProFieldFCMode` | Field render mode: `'read' \| 'edit' \| 'update'` |
|
|
58
|
+
| `BaseProFieldFC` | Base field component type |
|
|
59
|
+
| `ProFieldFCRenderProps` | Field render props |
|
|
60
|
+
| `ProRenderFieldPropsType` | Custom field renderer type |
|
|
61
|
+
| `ParamsType` | General params type |
|
|
62
|
+
|
|
63
|
+
## Usage
|
|
64
|
+
|
|
65
|
+
```vue
|
|
66
|
+
<script setup lang="ts">
|
|
67
|
+
import { ProConfigProvider } from '@antdv-vue/pro-provider'
|
|
68
|
+
</script>
|
|
69
|
+
|
|
70
|
+
<template>
|
|
71
|
+
<ProConfigProvider :dark="false" :compact="false">
|
|
72
|
+
<YourApp />
|
|
73
|
+
</ProConfigProvider>
|
|
74
|
+
</template>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Theme Integration
|
|
78
|
+
|
|
79
|
+
Use `ConfigProvider.theme` for antdv-next component tokens and `ProConfigProvider.token` for Pro component tokens.
|
|
80
|
+
|
|
81
|
+
```vue
|
|
82
|
+
<script setup lang="ts">
|
|
83
|
+
import { ref } from 'vue'
|
|
84
|
+
|
|
85
|
+
const dark = ref(false)
|
|
86
|
+
const compact = ref(false)
|
|
87
|
+
</script>
|
|
88
|
+
|
|
89
|
+
<template>
|
|
90
|
+
<a-config-provider :theme="{ token: { colorPrimary: '#1677ff' } }">
|
|
91
|
+
<ProConfigProvider
|
|
92
|
+
:dark="dark"
|
|
93
|
+
:compact="compact"
|
|
94
|
+
:token="{
|
|
95
|
+
layout: {
|
|
96
|
+
header: {
|
|
97
|
+
colorBgHeader: '#001529',
|
|
98
|
+
colorHeaderTitle: '#fff',
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
}"
|
|
102
|
+
>
|
|
103
|
+
<YourApp />
|
|
104
|
+
</ProConfigProvider>
|
|
105
|
+
</a-config-provider>
|
|
106
|
+
</template>
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
- `dark` and `compact` merge antdv-next algorithms into the current theme algorithm.
|
|
110
|
+
- Nested providers are scoped to their own subtree. Child provider tokens do not update unrelated global Pro components.
|
|
111
|
+
- Pro theme variables are emitted as CSS variables with the `css-var-pro` key, so dynamic theme changes update variable styles instead of reinserting component style text.
|
|
112
|
+
- Generated styles reuse `ConfigProvider.csp.nonce` when CSP is configured.
|
|
113
|
+
|
|
114
|
+
### Style Hook for Pro Components
|
|
115
|
+
|
|
116
|
+
`useStyle` is the shared CSS-in-JS helper for Pro packages. Component style hooks generated by `useStyle` return both the hash class and the CSS variable scope class:
|
|
117
|
+
|
|
118
|
+
```tsx
|
|
119
|
+
const [hashId, cssVarCls] = useStyle(prefixCls)
|
|
120
|
+
|
|
121
|
+
return () => (
|
|
122
|
+
<div class={[prefixCls.value, hashId.value, cssVarCls.value]}>
|
|
123
|
+
{slots.default?.()}
|
|
124
|
+
</div>
|
|
125
|
+
)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
When authoring a Pro component:
|
|
129
|
+
|
|
130
|
+
- attach both `hashId` and `cssVarCls` to the component root;
|
|
131
|
+
- keep component styles expressed with token values instead of hard-coded theme colors;
|
|
132
|
+
- pass `injectStyle: false` only when a component intentionally wants to skip runtime style injection;
|
|
133
|
+
- reset/common styles are registered before component styles so component selectors with overlapping prefixes keep priority.
|
|
134
|
+
|
|
135
|
+
## License
|
|
136
|
+
|
|
137
|
+
[MIT](../../LICENSE)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ProConfigProviderProps } from "./typing.js";
|
|
2
|
+
import * as _$vue from "vue";
|
|
3
|
+
import { CustomSlotsType, VueNode } from "@v-c/util/dist/type";
|
|
4
|
+
|
|
5
|
+
//#region src/ConfigProviderContainer.d.ts
|
|
6
|
+
declare const ConfigProviderContainer: _$vue.DefineSetupFnComponent<ProConfigProviderProps, {}, CustomSlotsType<{
|
|
7
|
+
default?: () => VueNode;
|
|
8
|
+
}>, ProConfigProviderProps & {}, _$vue.PublicProps>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { ConfigProviderContainer as default };
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { findIntlKeyByAntdLocaleKey, intlMap, zhCNIntl } from "./intl.js";
|
|
2
|
+
import { useProCacheTokenProvider, useProConfig, useProConfigProvider } from "./context.js";
|
|
3
|
+
import { getLayoutDesignToken, proLayoutUnitless } from "./typing/layoutToken.js";
|
|
4
|
+
import { isNeedOpenHash } from "./utils/index.js";
|
|
5
|
+
import { shallowMergeOneLevel } from "./utils/merge.js";
|
|
6
|
+
import { computed, createVNode, defineComponent, mergeProps, watch } from "vue";
|
|
7
|
+
import { useCacheToken } from "@antdv-next/cssinjs";
|
|
8
|
+
import { ConfigProvider, theme } from "antdv-next";
|
|
9
|
+
import { useConfig } from "antdv-next/config-provider/context";
|
|
10
|
+
import { ignore } from "antdv-next/dist/theme/useToken";
|
|
11
|
+
import dayjs from "dayjs";
|
|
12
|
+
import "dayjs/locale/zh-cn";
|
|
13
|
+
//#region src/ConfigProviderContainer.tsx
|
|
14
|
+
const preserve = {
|
|
15
|
+
screenXS: true,
|
|
16
|
+
screenXSMin: true,
|
|
17
|
+
screenXSMax: true,
|
|
18
|
+
screenSM: true,
|
|
19
|
+
screenSMMin: true,
|
|
20
|
+
screenSMMax: true,
|
|
21
|
+
screenMD: true,
|
|
22
|
+
screenMDMin: true,
|
|
23
|
+
screenMDMax: true,
|
|
24
|
+
screenLG: true,
|
|
25
|
+
screenLGMin: true,
|
|
26
|
+
screenLGMax: true,
|
|
27
|
+
screenXL: true,
|
|
28
|
+
screenXLMin: true,
|
|
29
|
+
screenXLMax: true,
|
|
30
|
+
screenXXL: true,
|
|
31
|
+
screenXXLMin: true,
|
|
32
|
+
screenXXLMax: true,
|
|
33
|
+
screenXXXL: true,
|
|
34
|
+
screenXXXLMin: true
|
|
35
|
+
};
|
|
36
|
+
function flattenToken(token, prefix = "") {
|
|
37
|
+
const result = {};
|
|
38
|
+
for (const [key, value] of Object.entries(token)) {
|
|
39
|
+
const currentKey = prefix ? `${prefix}${key.charAt(0).toUpperCase()}${key.slice(1)}` : key;
|
|
40
|
+
if (value && typeof value === "object" && !Array.isArray(value)) Object.assign(result, flattenToken(value, currentKey));
|
|
41
|
+
else result[currentKey] = value;
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 解析最终使用的 intl 实例。优先级从高到低:
|
|
47
|
+
* 1. 组件 props 显式传入的 `intl`
|
|
48
|
+
* 2. 父级 Provider 里非 `default` 的 intl(即用户已显式配置过)
|
|
49
|
+
* 3. 根据 antd 的 locale 推断(zh_CN → zh-CN → zhCNIntl)
|
|
50
|
+
* 4. 兜底 zh-CN
|
|
51
|
+
*/
|
|
52
|
+
function resolveIntl(propsIntl, parentIntl, antdLocaleName) {
|
|
53
|
+
if (propsIntl) return propsIntl;
|
|
54
|
+
if (parentIntl && parentIntl.locale !== "default") return parentIntl;
|
|
55
|
+
if (antdLocaleName) {
|
|
56
|
+
const key = findIntlKeyByAntdLocaleKey(antdLocaleName);
|
|
57
|
+
const found = key ? intlMap[key] : void 0;
|
|
58
|
+
if (found) return found;
|
|
59
|
+
}
|
|
60
|
+
return zhCNIntl;
|
|
61
|
+
}
|
|
62
|
+
const ConfigProviderContainer = /* @__PURE__ */ defineComponent((props, { slots, attrs }) => {
|
|
63
|
+
const config = useConfig();
|
|
64
|
+
const proProvide = useProConfig();
|
|
65
|
+
const tokenContext = theme.useToken?.();
|
|
66
|
+
const mergedProps = computed(() => ({
|
|
67
|
+
...attrs,
|
|
68
|
+
...props
|
|
69
|
+
}));
|
|
70
|
+
/**
|
|
71
|
+
* pro 的 类
|
|
72
|
+
* @example ref('.ant-pro')
|
|
73
|
+
*/
|
|
74
|
+
const proComponentsCls = computed(() => mergedProps.value.prefixCls ? `.${mergedProps.value.prefixCls}` : `.${config.value.getPrefixCls()}-pro`);
|
|
75
|
+
const antCls = computed(() => `.${config.value.getPrefixCls()}`);
|
|
76
|
+
const salt = computed(() => `${proComponentsCls.value}`);
|
|
77
|
+
const proLayoutTokenMerge = computed(() => getLayoutDesignToken(mergedProps.value.token || {}, tokenContext.token.value));
|
|
78
|
+
const proProvideValue = computed(() => {
|
|
79
|
+
return {
|
|
80
|
+
...proProvide.value,
|
|
81
|
+
dark: mergedProps.value.dark ?? proProvide.value.dark,
|
|
82
|
+
compact: mergedProps.value.compact ?? proProvide.value.compact,
|
|
83
|
+
token: shallowMergeOneLevel(proProvide.value.token, tokenContext.token.value, {
|
|
84
|
+
proComponentsCls: proComponentsCls.value,
|
|
85
|
+
antCls: antCls.value,
|
|
86
|
+
themeId: tokenContext.theme.value.id,
|
|
87
|
+
layout: proLayoutTokenMerge.value
|
|
88
|
+
}),
|
|
89
|
+
intl: resolveIntl(mergedProps.value.intl, proProvide.value.intl, config.value.locale?.locale)
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
const finalToken = computed(() => ({
|
|
93
|
+
...proProvideValue.value?.token || {},
|
|
94
|
+
proComponentsCls: proComponentsCls.value
|
|
95
|
+
}));
|
|
96
|
+
const cacheToken = useCacheToken(tokenContext.theme, computed(() => {
|
|
97
|
+
const { layout, ...restFinalToken } = finalToken.value || {};
|
|
98
|
+
const prolayoutToken = flattenToken({ layout }, "pro");
|
|
99
|
+
return [tokenContext.token.value, {
|
|
100
|
+
...restFinalToken,
|
|
101
|
+
...prolayoutToken
|
|
102
|
+
}];
|
|
103
|
+
}), computed(() => {
|
|
104
|
+
const { layout, ...restFinalToken } = finalToken.value || {};
|
|
105
|
+
const prolayoutToken = flattenToken({ layout }, "pro");
|
|
106
|
+
return {
|
|
107
|
+
salt: salt.value,
|
|
108
|
+
override: {
|
|
109
|
+
...restFinalToken,
|
|
110
|
+
...prolayoutToken
|
|
111
|
+
},
|
|
112
|
+
cssVar: {
|
|
113
|
+
key: "css-var-pro",
|
|
114
|
+
unitless: proLayoutUnitless,
|
|
115
|
+
ignore,
|
|
116
|
+
preserve,
|
|
117
|
+
prefix: "ant"
|
|
118
|
+
},
|
|
119
|
+
nonce: config.value.csp?.nonce
|
|
120
|
+
};
|
|
121
|
+
}));
|
|
122
|
+
const hashed = computed(() => {
|
|
123
|
+
if (mergedProps.value.hashed === false) return false;
|
|
124
|
+
if (proProvide.value.hashed === false) return false;
|
|
125
|
+
return true;
|
|
126
|
+
});
|
|
127
|
+
const hashId = computed(() => {
|
|
128
|
+
if (mergedProps.value.hashed === false) return "";
|
|
129
|
+
if (proProvide.value.hashed === false) return "";
|
|
130
|
+
if (isNeedOpenHash() === false) return "";
|
|
131
|
+
else return cacheToken.value[1];
|
|
132
|
+
});
|
|
133
|
+
watch(() => config.value.locale?.locale, () => {
|
|
134
|
+
dayjs.locale(config.value.locale?.locale || "zh-cn");
|
|
135
|
+
}, { immediate: true });
|
|
136
|
+
const themeConfig = computed(() => {
|
|
137
|
+
const { locale, getPrefixCls, ...restConfig } = config.value;
|
|
138
|
+
return {
|
|
139
|
+
...restConfig.theme,
|
|
140
|
+
hashId: hashId.value,
|
|
141
|
+
hashed: hashed.value && isNeedOpenHash()
|
|
142
|
+
};
|
|
143
|
+
});
|
|
144
|
+
const proConfigConsumerValue = computed(() => {
|
|
145
|
+
return {
|
|
146
|
+
...proProvideValue.value,
|
|
147
|
+
valueTypeMap: mergedProps.value.valueTypeMap || proProvide.value.valueTypeMap,
|
|
148
|
+
token: finalToken.value,
|
|
149
|
+
theme: tokenContext.theme.value,
|
|
150
|
+
hashed: hashed.value,
|
|
151
|
+
hashId: hashId.value,
|
|
152
|
+
prefixCls: mergedProps.value.prefixCls
|
|
153
|
+
};
|
|
154
|
+
});
|
|
155
|
+
useProCacheTokenProvider({
|
|
156
|
+
realToken: computed(() => cacheToken.value[2]),
|
|
157
|
+
token: computed(() => cacheToken.value[0])
|
|
158
|
+
});
|
|
159
|
+
useProConfigProvider(proConfigConsumerValue);
|
|
160
|
+
return () => {
|
|
161
|
+
const { locale, getPrefixCls, ...restConfig } = config.value;
|
|
162
|
+
return createVNode(ConfigProvider, mergeProps(restConfig, { "theme": themeConfig.value }), { default: () => [slots.default?.()] });
|
|
163
|
+
};
|
|
164
|
+
}, {
|
|
165
|
+
props: {
|
|
166
|
+
dark: {
|
|
167
|
+
type: Boolean,
|
|
168
|
+
required: false,
|
|
169
|
+
default: void 0
|
|
170
|
+
},
|
|
171
|
+
compact: {
|
|
172
|
+
type: Boolean,
|
|
173
|
+
required: false,
|
|
174
|
+
default: void 0
|
|
175
|
+
},
|
|
176
|
+
needDeps: {
|
|
177
|
+
type: Boolean,
|
|
178
|
+
required: false,
|
|
179
|
+
default: void 0
|
|
180
|
+
},
|
|
181
|
+
token: {
|
|
182
|
+
type: Object,
|
|
183
|
+
required: false
|
|
184
|
+
},
|
|
185
|
+
prefixCls: {
|
|
186
|
+
type: String,
|
|
187
|
+
required: false
|
|
188
|
+
},
|
|
189
|
+
valueTypeMap: {
|
|
190
|
+
type: Object,
|
|
191
|
+
required: false
|
|
192
|
+
},
|
|
193
|
+
hashed: {
|
|
194
|
+
type: Boolean,
|
|
195
|
+
required: false,
|
|
196
|
+
default: void 0
|
|
197
|
+
},
|
|
198
|
+
intl: {
|
|
199
|
+
type: Object,
|
|
200
|
+
required: false
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
name: "ConfigProviderContainer",
|
|
204
|
+
inheritAttrs: false
|
|
205
|
+
});
|
|
206
|
+
//#endregion
|
|
207
|
+
export { ConfigProviderContainer as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ProConfigProviderProps } from "./typing.js";
|
|
2
|
+
import * as _$vue from "vue";
|
|
3
|
+
import { Plugin } from "vue";
|
|
4
|
+
import { CustomSlotsType, VueNode } from "@v-c/util/dist/type";
|
|
5
|
+
|
|
6
|
+
//#region src/ProConfigProvider.d.ts
|
|
7
|
+
declare const _ProConfigProvider: _$vue.DefineSetupFnComponent<ProConfigProviderProps, {}, CustomSlotsType<{
|
|
8
|
+
default?: () => VueNode;
|
|
9
|
+
}>, ProConfigProviderProps & {}, _$vue.PublicProps>;
|
|
10
|
+
declare const ProConfigProvider: typeof _ProConfigProvider & Plugin;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { ProConfigProvider as default };
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { useProConfig } from "./context.js";
|
|
2
|
+
import ConfigProviderContainer from "./ConfigProviderContainer.js";
|
|
3
|
+
import { Fragment, computed, createVNode, defineComponent, mergeProps } from "vue";
|
|
4
|
+
import { ConfigProvider, theme } from "antdv-next";
|
|
5
|
+
import { useConfig } from "antdv-next/config-provider/context";
|
|
6
|
+
import zh_CN from "antdv-next/locale/zh_CN";
|
|
7
|
+
//#region src/ProConfigProvider.tsx
|
|
8
|
+
function omitUndefined(obj) {
|
|
9
|
+
const newObj = {};
|
|
10
|
+
Object.keys(obj || {}).forEach((key) => {
|
|
11
|
+
if (obj?.[key] !== void 0) newObj[key] = obj[key];
|
|
12
|
+
});
|
|
13
|
+
if (Object.keys(newObj || {}).length < 1) return;
|
|
14
|
+
return newObj;
|
|
15
|
+
}
|
|
16
|
+
function uniqueAlgorithm(algorithms) {
|
|
17
|
+
return Array.from(new Set(algorithms));
|
|
18
|
+
}
|
|
19
|
+
const ProConfigProvider = /* @__PURE__ */ defineComponent((props, { slots, attrs }) => {
|
|
20
|
+
const config = useConfig();
|
|
21
|
+
const proProvide = useProConfig();
|
|
22
|
+
const mergedProps = computed(() => ({
|
|
23
|
+
...attrs,
|
|
24
|
+
...props
|
|
25
|
+
}));
|
|
26
|
+
const mergeAlgorithm = () => {
|
|
27
|
+
const algorithm = config.value.theme?.algorithm;
|
|
28
|
+
const isDark = mergedProps.value.dark ?? proProvide.value.dark;
|
|
29
|
+
const isCompact = mergedProps.value.compact ?? proProvide.value.compact;
|
|
30
|
+
if (algorithm) {
|
|
31
|
+
if (!Array.isArray(algorithm)) {
|
|
32
|
+
if (isDark && !isCompact) return uniqueAlgorithm([algorithm, theme.darkAlgorithm]).filter(Boolean);
|
|
33
|
+
else if (!isDark && isCompact) return uniqueAlgorithm([algorithm, theme.compactAlgorithm]).filter(Boolean);
|
|
34
|
+
else if (isDark && isCompact) return uniqueAlgorithm([
|
|
35
|
+
algorithm,
|
|
36
|
+
theme.darkAlgorithm,
|
|
37
|
+
theme.compactAlgorithm
|
|
38
|
+
]).filter(Boolean);
|
|
39
|
+
} else if (isDark && !isCompact) return uniqueAlgorithm([...algorithm || [], theme.darkAlgorithm]).filter(Boolean);
|
|
40
|
+
else if (!isDark && isCompact) return uniqueAlgorithm([...algorithm || [], theme.compactAlgorithm]).filter(Boolean);
|
|
41
|
+
else if (isDark && isCompact) return uniqueAlgorithm([
|
|
42
|
+
...algorithm || [],
|
|
43
|
+
theme.darkAlgorithm,
|
|
44
|
+
theme.compactAlgorithm
|
|
45
|
+
]).filter(Boolean);
|
|
46
|
+
} else if (isDark && !isCompact) return [theme.darkAlgorithm];
|
|
47
|
+
else if (!isDark && isCompact) return [theme.compactAlgorithm];
|
|
48
|
+
else if (isDark && isCompact) return [theme.darkAlgorithm, theme.compactAlgorithm];
|
|
49
|
+
return algorithm;
|
|
50
|
+
};
|
|
51
|
+
const isNullProvide = computed(() => mergedProps.value.needDeps && proProvide.value.hashId !== void 0 && Object.keys(Object.fromEntries(Object.entries(mergedProps.value).filter(([, v]) => v !== void 0))).sort().join("-") === "needDeps");
|
|
52
|
+
const configProviderProps = computed(() => {
|
|
53
|
+
const { locale, theme, ...rest } = config.value;
|
|
54
|
+
return {
|
|
55
|
+
...rest,
|
|
56
|
+
locale: locale || zh_CN,
|
|
57
|
+
theme: omitUndefined({
|
|
58
|
+
...theme,
|
|
59
|
+
algorithm: mergeAlgorithm()
|
|
60
|
+
})
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
return () => {
|
|
64
|
+
const { token } = mergedProps.value;
|
|
65
|
+
if (isNullProvide.value) return createVNode(Fragment, null, [slots.default?.()]);
|
|
66
|
+
return createVNode(ConfigProvider, configProviderProps.value, { default: () => [createVNode(ConfigProviderContainer, mergeProps(mergedProps.value, { "token": token }), slots)] });
|
|
67
|
+
};
|
|
68
|
+
}, {
|
|
69
|
+
props: {
|
|
70
|
+
dark: {
|
|
71
|
+
type: Boolean,
|
|
72
|
+
required: false,
|
|
73
|
+
default: void 0
|
|
74
|
+
},
|
|
75
|
+
compact: {
|
|
76
|
+
type: Boolean,
|
|
77
|
+
required: false,
|
|
78
|
+
default: void 0
|
|
79
|
+
},
|
|
80
|
+
needDeps: {
|
|
81
|
+
type: Boolean,
|
|
82
|
+
required: false,
|
|
83
|
+
default: void 0
|
|
84
|
+
},
|
|
85
|
+
token: {
|
|
86
|
+
type: Object,
|
|
87
|
+
required: false
|
|
88
|
+
},
|
|
89
|
+
prefixCls: {
|
|
90
|
+
type: String,
|
|
91
|
+
required: false
|
|
92
|
+
},
|
|
93
|
+
valueTypeMap: {
|
|
94
|
+
type: Object,
|
|
95
|
+
required: false
|
|
96
|
+
},
|
|
97
|
+
hashed: {
|
|
98
|
+
type: Boolean,
|
|
99
|
+
required: false,
|
|
100
|
+
default: void 0
|
|
101
|
+
},
|
|
102
|
+
intl: {
|
|
103
|
+
type: Object,
|
|
104
|
+
required: false
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
name: "ProConfigProvider",
|
|
108
|
+
inheritAttrs: false
|
|
109
|
+
});
|
|
110
|
+
ProConfigProvider.install = (app) => {
|
|
111
|
+
app.component(ProConfigProvider.name, ProConfigProvider);
|
|
112
|
+
return app;
|
|
113
|
+
};
|
|
114
|
+
//#endregion
|
|
115
|
+
export { ProConfigProvider as default };
|