@gx-design-vue/context 0.0.3 β†’ 0.0.5-alpha.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 gx12358
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,10 +1,76 @@
1
- # context
1
+ <div align="center"><a name="readme-top"></a>
2
2
 
3
- ```shell
3
+ <img height="180" src="https://gx12358.cn/resource/img/favicon.ico">
4
+
5
+ <h1>Context</h1>
6
+
7
+ </div>
8
+
9
+ ## ✨ Features
10
+
11
+ - 🌈 Enterprise-class UI designed for web applications.
12
+ - πŸ“¦ A set of high-quality Vue3 components out of the box.
13
+ - πŸ›‘ Written in TypeScript with predictable static types.
14
+ - βš™οΈ Whole package of design resources and development tools.
15
+ - 🌍 Internationalization support for dozens of languages.
16
+ - 🎨 Powerful theme customization based on CSS-in-JS.
17
+
18
+ ## πŸ–₯ Environment Support
19
+
20
+ - Modern browsers
21
+ - Server-side Rendering
22
+ - [Electron](https://www.electronjs.org/)
23
+
24
+ | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png" alt="Edge" width="24px" height="24px" />](https://godban.github.io/browsers-support-badges/)<br>Edge | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png" alt="Firefox" width="24px" height="24px" />](https://godban.github.io/browsers-support-badges/)<br>Firefox | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" width="24px" height="24px" />](https://godban.github.io/browsers-support-badges/)<br>Chrome | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png" alt="Safari" width="24px" height="24px" />](https://godban.github.io/browsers-support-badges/)<br>Safari | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/electron/electron_48x48.png" alt="Electron" width="24px" height="24px" />](https://godban.github.io/browsers-support-badges/)<br>Electron |
25
+ | --- | --- | --- | --- | --- |
26
+ | Edge | last 2 versions | last 2 versions | last 2 versions | last 2 versions |
27
+
28
+ ## πŸ“¦ Install
29
+
30
+ ```bash
31
+ npm install @gx-design-vue/context
32
+ ```
33
+
34
+ ```bash
35
+ yarn add @gx-design-vue/context
36
+ ```
37
+
38
+ ```bash
4
39
  pnpm add @gx-design-vue/context
5
40
  ```
6
41
 
7
- ```ts
8
- // 可全局引ε…₯,也可δ»₯单独引ε…₯
9
- import { Gcontext } from '@gx-design-vue/context'
42
+ ```bash
43
+ bun add @gx-design-vue/context
10
44
  ```
45
+
46
+ ## Acknowledgements
47
+
48
+ Antdv Next is inspired by and built upon the following open-source projects.
49
+
50
+ - [Ant Design](https://ant.design/)
51
+ - [Vue.js](https://vuejs.org/)
52
+ - [Vite](https://vitejs.dev/)
53
+
54
+ ## Maintainer
55
+
56
+ [@gx12358](https://github.com/gx12358/vue3-antd-admin)
57
+
58
+ ## Contributors
59
+
60
+ <a href="https://github.com/gx12358/vue3-antd-admin/graphs/contributors">
61
+ <img alt="Contributors" src="https://contrib.rocks/image?repo=gx12358/vue3-antd-admin" />
62
+ </a>
63
+
64
+ ## Special Thanks
65
+
66
+ Thanks to the [vbenjs/vue-vben-admin](https://github.com/gx12358/vue3-antd-admin) project for providing inspiration and reference implementation.
67
+
68
+ ## License
69
+
70
+ [MIT Β© gx12358-2021](./LICENSE)
71
+
72
+ ## `Star`
73
+
74
+ Thank you very much for the stars from kind-hearted people, thank you for your support :heart:
75
+
76
+ [![Stargazers repo roster for @gx12358/vue3-antd-admin](https://bytecrank.com/nastyox/reporoster/php/stargazersSVG.php?user=gx12358&repo=vue3-antd-admin)](https://github.com/gx12358/vue3-antd-admin/stargazers)
@@ -0,0 +1,45 @@
1
+ import * as vue0 from "vue";
2
+ import { PropType, SlotsType } from "vue";
3
+
4
+ //#region src/context/ContextProvider.d.ts
5
+ interface ContextProviderProps {
6
+ contextKey: string;
7
+ value: any;
8
+ }
9
+ interface ContextProviderSlots {
10
+ default?: () => any;
11
+ }
12
+ declare const contextProps: {
13
+ contextKey: {
14
+ type: PropType<ContextProviderProps["contextKey"]>;
15
+ required: boolean;
16
+ };
17
+ value: {
18
+ type: PropType<ContextProviderProps["value"]>;
19
+ required: boolean;
20
+ };
21
+ };
22
+ declare const ContextProvider: vue0.DefineComponent<vue0.ExtractPropTypes<{
23
+ contextKey: {
24
+ type: PropType<ContextProviderProps["contextKey"]>;
25
+ required: boolean;
26
+ };
27
+ value: {
28
+ type: PropType<ContextProviderProps["value"]>;
29
+ required: boolean;
30
+ };
31
+ }>, () => any, {}, {}, {}, vue0.ComponentOptionsMixin, vue0.ComponentOptionsMixin, {}, string, vue0.PublicProps, Readonly<vue0.ExtractPropTypes<{
32
+ contextKey: {
33
+ type: PropType<ContextProviderProps["contextKey"]>;
34
+ required: boolean;
35
+ };
36
+ value: {
37
+ type: PropType<ContextProviderProps["value"]>;
38
+ required: boolean;
39
+ };
40
+ }>> & Readonly<{}>, {}, SlotsType<ContextProviderSlots>, {}, {}, string, vue0.ComponentProvideOptions, true, {}, any>;
41
+ declare function useContextProvider<T = any>(contextInjectKey: string, defaultValue?: T): T & {
42
+ contextId: string;
43
+ };
44
+ //#endregion
45
+ export { ContextProvider, ContextProviderSlots, contextProps, useContextProvider };
@@ -0,0 +1,39 @@
1
+ import { defineComponent, inject, provide, toRefs } from "vue";
2
+ import { getRandomNumber, isObject } from "@gx-design-vue/pro-utils";
3
+
4
+ //#region src/context/ContextProvider.tsx
5
+ let contextId = null;
6
+ function updateContextKey(key) {
7
+ if (contextId) return contextId;
8
+ contextId = Symbol(key);
9
+ return contextId;
10
+ }
11
+ const contextProps = {
12
+ contextKey: {
13
+ type: String,
14
+ required: true
15
+ },
16
+ value: {
17
+ type: Object,
18
+ required: true
19
+ }
20
+ };
21
+ const ContextProvider = /* @__PURE__ */ defineComponent({
22
+ name: "ContextProvider",
23
+ props: contextProps,
24
+ slots: Object,
25
+ setup: (props, { slots }) => {
26
+ if (props.contextKey && props.value && isObject(props.value)) provide(updateContextKey(props.contextKey), {
27
+ ...toRefs(props.value),
28
+ contextId: `${props.contextKey}-${getRandomNumber().uuid(10)}`
29
+ });
30
+ else console.warn("[ContextProvider]: contextKey is required");
31
+ return () => slots.default?.();
32
+ }
33
+ });
34
+ function useContextProvider(contextInjectKey, defaultValue) {
35
+ if (typeof contextId === "symbol") return inject(updateContextKey(contextInjectKey), defaultValue || {});
36
+ }
37
+
38
+ //#endregion
39
+ export { ContextProvider, contextProps, useContextProvider };
@@ -0,0 +1,10 @@
1
+ import { InjectionKey } from "vue";
2
+
3
+ //#region src/context/index.d.ts
4
+ declare function useContext<T>(key: string, defaultValue?: T): {
5
+ provideContext: (value: T) => void;
6
+ useInjectContext: (injectDefaultValue?: T) => T;
7
+ contextInjectKey: InjectionKey<T>;
8
+ };
9
+ //#endregion
10
+ export { useContext };
@@ -0,0 +1,20 @@
1
+ import { inject, provide } from "vue";
2
+
3
+ //#region src/context/index.ts
4
+ function useContext(key, defaultValue) {
5
+ const contextInjectKey = Symbol(key);
6
+ const provideContext = (value) => {
7
+ provide(contextInjectKey, value);
8
+ };
9
+ const useInjectContext = (injectDefaultValue) => {
10
+ return inject(contextInjectKey, injectDefaultValue || defaultValue || {});
11
+ };
12
+ return {
13
+ provideContext,
14
+ useInjectContext,
15
+ contextInjectKey
16
+ };
17
+ }
18
+
19
+ //#endregion
20
+ export { useContext };